OverviewFilesCommitsIssuesDocsReleasesPeers

pear-git-v3 / test / profile-render.test.js

40 lines · javascript ref:
/**
 * Profile SSR: both the OWN view (/profile → renderProfile) and the PUBLIC
 * view (/profile/:pubkey → renderUserProfile) render the activity sections
 * ("Repos pushed", "Recent issues"). Regression guard for the gap where the
 * activity was added only to the public renderer.
 */

import test from 'brittle'
import { renderProfile, renderUserProfile } from '../lib/web/pages/profile.js'

const pk = 'aa'.repeat(32)

function mockSvc () {
  return {
    identity: { publicKey: pk, publicKeyHex: pk, createdAt: 0 },
    identityRegistry: {
      getUserByIdentity: async () => ({ userId: 'u1', name: 'Me', globalPermissions: ['write'], profilePicture: null }),
      getUserWithIdentities: async () => ({ user: { userId: 'u1', name: 'Me', globalPermissions: ['write'] }, identities: [] }),
      getIdentity: async () => ({ userId: 'u1' })
    },
    sessions: {},
    http: {}
  }
}

test('own /profile renders activity sections + account cards', async (t) => {
  const html = await renderProfile(mockSvc(), { identity: { publicKey: pk }, prefix: '/git' })
  t.ok(html.includes('Repos pushed'), 'own view has Repos pushed')
  t.ok(html.includes('Recent issues'), 'own view has Recent issues')
  t.ok(html.includes('Edit profile'), 'own view keeps account cards')
})

test('public /profile/:pubkey renders activity; hides identities from anon', async (t) => {
  // Anonymous viewer (no ctx.identity) → identities section must be gated.
  const html = await renderUserProfile(mockSvc(), { prefix: '/git' }, pk)
  t.ok(html.includes('Repos pushed'), 'public view has Repos pushed')
  t.ok(html.includes('Recent issues'), 'public view has Recent issues')
  t.absent(html.includes('<h2>Identities ('), 'identities hidden from anonymous viewer')
})