From 88b175bf96e485df2412e39cfba423830fa5ee8e Mon Sep 17 00:00:00 2001 From: Alex Meng Date: Wed, 3 Jun 2026 17:38:30 -0700 Subject: [PATCH 1/3] Fix profile lab affiliation loading --- app/profile/profile-data.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/profile/profile-data.ts b/app/profile/profile-data.ts index 82ca0dd..5f7cf40 100644 --- a/app/profile/profile-data.ts +++ b/app/profile/profile-data.ts @@ -1,6 +1,7 @@ import { connectToDatabase } from "@/lib/mongoose"; import UserLab from "@/models/UserLab"; import { User } from "@/models/User"; +import "@/models/Lab"; export type Affiliation = { id: string; @@ -79,7 +80,8 @@ export async function loadProfileAffiliations(userEmail?: string) { role: roleLabels[row.role] ?? row.role, joined: formatJoined(row.joinedAt), })); - } catch { - return sampleAffiliations; + } catch (error) { + console.error("[profile] Failed to load lab affiliations:", error); + return [] as Affiliation[]; } } From b787f2f740f47311d3b9134be89aab669bfedcc8 Mon Sep 17 00:00:00 2001 From: Alex Meng Date: Wed, 3 Jun 2026 17:41:44 -0700 Subject: [PATCH 2/3] Test profile lab affiliation loading --- app/profile/__tests__/profile-data.test.ts | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 app/profile/__tests__/profile-data.test.ts diff --git a/app/profile/__tests__/profile-data.test.ts b/app/profile/__tests__/profile-data.test.ts new file mode 100644 index 0000000..614c8e0 --- /dev/null +++ b/app/profile/__tests__/profile-data.test.ts @@ -0,0 +1,48 @@ +import { connectToDatabase } from "@/lib/mongoose"; +import LabModel from "@/models/Lab"; +import UserLab from "@/models/UserLab"; +import { User } from "@/models/User"; +import { loadProfileAffiliations } from "@/app/profile/profile-data"; + +describe("profile affiliation data", () => { + test("loads the signed-in user's real lab affiliations instead of sample data", async () => { + await connectToDatabase(); + + const user = await User.create({ + email: "profile-test@ucsd.edu", + name: { + first: "Profile", + last: "Tester", + }, + role: "RESEARCHER", + }); + const lab = await LabModel.create({ + name: "Real Profile Testing Lab", + department: "Cognitive Science", + }); + + await UserLab.create({ + user: user._id, + lab: lab._id, + role: "RESEARCHER", + joinedAt: new Date("2026-03-15T12:00:00.000Z"), + }); + + const affiliations = await loadProfileAffiliations("profile-test@ucsd.edu"); + + expect(affiliations).toEqual([ + expect.objectContaining({ + labName: "Real Profile Testing Lab", + role: "Researcher", + joined: "March 2026", + }), + ]); + expect(affiliations).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({ + labName: "Xu Computational Neuroscience Lab", + }), + ]) + ); + }); +}); From e2dcf60fe41612f706549770d948e38ca09fc30a Mon Sep 17 00:00:00 2001 From: Alex Meng Date: Wed, 3 Jun 2026 17:46:15 -0700 Subject: [PATCH 3/3] Revert "Test profile lab affiliation loading" This reverts commit b787f2f740f47311d3b9134be89aab669bfedcc8. --- app/profile/__tests__/profile-data.test.ts | 48 ---------------------- 1 file changed, 48 deletions(-) delete mode 100644 app/profile/__tests__/profile-data.test.ts diff --git a/app/profile/__tests__/profile-data.test.ts b/app/profile/__tests__/profile-data.test.ts deleted file mode 100644 index 614c8e0..0000000 --- a/app/profile/__tests__/profile-data.test.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { connectToDatabase } from "@/lib/mongoose"; -import LabModel from "@/models/Lab"; -import UserLab from "@/models/UserLab"; -import { User } from "@/models/User"; -import { loadProfileAffiliations } from "@/app/profile/profile-data"; - -describe("profile affiliation data", () => { - test("loads the signed-in user's real lab affiliations instead of sample data", async () => { - await connectToDatabase(); - - const user = await User.create({ - email: "profile-test@ucsd.edu", - name: { - first: "Profile", - last: "Tester", - }, - role: "RESEARCHER", - }); - const lab = await LabModel.create({ - name: "Real Profile Testing Lab", - department: "Cognitive Science", - }); - - await UserLab.create({ - user: user._id, - lab: lab._id, - role: "RESEARCHER", - joinedAt: new Date("2026-03-15T12:00:00.000Z"), - }); - - const affiliations = await loadProfileAffiliations("profile-test@ucsd.edu"); - - expect(affiliations).toEqual([ - expect.objectContaining({ - labName: "Real Profile Testing Lab", - role: "Researcher", - joined: "March 2026", - }), - ]); - expect(affiliations).not.toEqual( - expect.arrayContaining([ - expect.objectContaining({ - labName: "Xu Computational Neuroscience Lab", - }), - ]) - ); - }); -});