diff --git a/backend/src/processors/query/timelineFeed.processor.ts b/backend/src/processors/query/timelineFeed.processor.ts index 581f434..294cf5f 100644 --- a/backend/src/processors/query/timelineFeed.processor.ts +++ b/backend/src/processors/query/timelineFeed.processor.ts @@ -9,6 +9,7 @@ import type { JourneyGoal } from "../../types/journey/Journey.types.js"; export interface RelevantJourney { username: string; + displayName?: string | null; summary: string; expertiseAreas: string[]; imageUrl?: string | null; @@ -77,6 +78,7 @@ export function buildTimelineFeed( return { username: journey.username, + displayName: journey.displayName?.trim() || null, summary: journey.summary, expertiseAreas: journey.expertiseAreas, imageUrl: journey.imageUrl, diff --git a/backend/src/services/journeyRetrieval.service.ts b/backend/src/services/journeyRetrieval.service.ts index 3b91392..938bfc8 100644 --- a/backend/src/services/journeyRetrieval.service.ts +++ b/backend/src/services/journeyRetrieval.service.ts @@ -2,6 +2,7 @@ import { closeSession, getSession } from "./neo4j.service.js"; export interface RetrievedJourney { username: string; + displayName?: string | null; summary: string; expertiseAreas: string[]; imageUrl: string | null; @@ -27,6 +28,7 @@ export async function retrieveJourneys( RETURN u.username AS username, + u.displayName AS displayName, u.summary AS summary, u.expertiseAreas AS expertiseAreas, u.imageUrl AS imageUrl, @@ -40,6 +42,7 @@ export async function retrieveJourneys( return result.records.map((record) => ({ username: record.get("username") as string, + displayName: (record.get("displayName") as string | null) ?? null, summary: (record.get("summary") as string) ?? "", diff --git a/backend/tests/displayName.test.ts b/backend/tests/displayName.test.ts new file mode 100644 index 0000000..221458a --- /dev/null +++ b/backend/tests/displayName.test.ts @@ -0,0 +1,14 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { buildTimelineFeed } from '../src/processors/query/timelineFeed.processor.js'; +function feed(displayName?: string | null) { + return buildTimelineFeed({journeys:[{username:'test1',displayName,summary:'Example',expertiseAreas:[],imageUrl:null,reputationScore:0,experienceIds:['e1']}], experiences:[{id:'e1', title:'Project',goalIds:[],transitions:[],skills:[]}],goals:[]} as any)[0]!; +} +test('display name does not change stable journey username', () => { + const result=feed(' Rohinth '); + assert.equal(result.displayName,'Rohinth'); + assert.equal(result.username,'test1'); +}); +test('legacy and empty display names remain absent', () => { + for (const name of [undefined,null,'',' ']) assert.equal(feed(name).displayName,null); +}); diff --git a/frontend/app/results.tsx b/frontend/app/results.tsx index c7d912f..1d9fbae 100644 --- a/frontend/app/results.tsx +++ b/frontend/app/results.tsx @@ -311,9 +311,9 @@ export default function ResultsPage() { - {user.username.charAt(0).toUpperCase()} + {(user.displayName?.trim() || user.username).charAt(0).toUpperCase()} - @{user.username} + {user.displayName?.trim() || `@${user.username}`} {(user.reputationScore !== undefined && user.reputationScore > 0) && (