diff --git a/api/src/routes/user.test.ts b/api/src/routes/user.test.ts index f53ca91004c..8cc38028ac2 100644 --- a/api/src/routes/user.test.ts +++ b/api/src/routes/user.test.ts @@ -109,11 +109,8 @@ const minimalUserData: Prisma.userCreateInput = { const computedProperties = { calendar: {}, completedChallengeCount: 0, - completedChallenges: [], // we don't need to provide an empty array, prisma will create it isEmailVerified: minimalUserData.emailVerified, points: 1, - portfolio: [], - yearsTopContributor: [], // This is the default value if profileUI is missing. If individual properties // are missing from the db, they will be omitted from the response. profileUI: { @@ -541,8 +538,17 @@ describe('userRoutes', () => { const publicUser = { ..._.omit(minimalUserData, ['externalId', 'unsubscribeId']), ...computedProperties, - id: testUser?.id, - joinDate: new ObjectId(testUser?.id).getTimestamp().toISOString() + id: testUser.id, + joinDate: new ObjectId(testUser.id).getTimestamp().toISOString(), + // the following properties are defaults provided if the field is + // missing in the user document. + completedChallenges: [], + // TODO: add completedExams when /generate-exam is implemented + // completedExams: [], + partiallyCompletedChallenges: [], + portfolio: [], + savedChallenges: [], + yearsTopContributor: [] }; const response = await superRequest('/user/get-session-user', { diff --git a/api/src/routes/user.ts b/api/src/routes/user.ts index fad90c9c1b5..735622aed6c 100644 --- a/api/src/routes/user.ts +++ b/api/src/routes/user.ts @@ -1,5 +1,4 @@ import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'; -import { isEmpty } from 'lodash'; import { ObjectId } from 'mongodb'; import { customAlphabet } from 'nanoid'; @@ -325,8 +324,6 @@ export const userGetRoutes: FastifyPluginCallbackTypebox = ( progressTimestamps, twitter, profileUI, - savedChallenges, - partiallyCompletedChallenges, ...publicUser } = user; @@ -340,19 +337,11 @@ export const userGetRoutes: FastifyPluginCallbackTypebox = ( calendar: getCalendar( progressTimestamps as ProgressTimestamp[] | null ), - partiallyCompletedChallenges: isEmpty( - partiallyCompletedChallenges - ) - ? undefined - : partiallyCompletedChallenges, // This assertion is necessary until the database is normalized. points: getPoints( progressTimestamps as ProgressTimestamp[] | null ), profileUI: normalizeProfileUI(profileUI), - savedChallenges: isEmpty(savedChallenges) - ? undefined - : savedChallenges, // TODO(Post-MVP) remove this and just use emailVerified isEmailVerified: user.emailVerified, joinDate: new ObjectId(user.id).getTimestamp().toISOString(),