diff --git a/api/prisma/schema.prisma b/api/prisma/schema.prisma index 0edce571356..62157b0f7fe 100644 --- a/api/prisma/schema.prisma +++ b/api/prisma/schema.prisma @@ -20,7 +20,7 @@ type File { type CompletedChallenge { challengeType Int? // Null | Undefined - completedDate Float + completedDate Float // TODO(Post-MVP): Change to DateTime files File[] githubLink String? // Undefined id String @@ -28,6 +28,11 @@ type CompletedChallenge { solution String? // Null | Undefined } +type PartiallyCompletedChallenge { + id String + completedDate Float +} + type Portfolio { description String id String @@ -68,13 +73,13 @@ type SavedChallenge { } model user { - id String @id @default(auto()) @map("_id") @db.ObjectId + id String @id @default(auto()) @map("_id") @db.ObjectId about String acceptedPrivacyTerms Boolean - badges Json? // Undefined | { coreTeam [][] } + // badges Json? // Undefined | { coreTeam [][] } removed, as new API never uses it. completedChallenges CompletedChallenge[] currentChallengeId String? - donationEmails String[] @default([]) // Undefined | String[] (only possible for built in Types like String) + donationEmails String[] // Undefined | String[] (only possible for built in Types like String) email String emailAuthLinkTTL DateTime? // Null | Undefined emailVerified Boolean @@ -110,25 +115,25 @@ model user { name String? // Null needsModeration Boolean? // Undefined newEmail String? // Null | Undefined - partiallyCompletedChallenges Json? // Undefined | PartiallyCompletedChallenge[] TODO: The db only has this as an empty array + partiallyCompletedChallenges PartiallyCompletedChallenge[] // Undefined | PartiallyCompletedChallenge[] password String? // Undefined picture String portfolio Portfolio[] profileUI ProfileUI? // Undefined progressTimestamps Json? // ProgressTimestamp[] | Null[] | Int64[] | Double[] - rand Float? // Undefined - savedChallenges Json? // Undefined | SavedChallenge[] + // rand Float? // Undefined removed, as new API never uses it. + savedChallenges SavedChallenge[] // Undefined | SavedChallenge[] sendQuincyEmail Boolean sound Boolean? // Undefined theme String? // Undefined timezone String? // Undefined twitter String? // Null | Undefined unsubscribeId String - username String // TODO(Post-MVP): make this unique + username String // TODO(Post-MVP): make this unique usernameDisplay String? // Undefined verificationToken String? // Undefined website String? // Undefined - yearsTopContributor String[] @default([]) // Undefined | String[] + yearsTopContributor String[] // Undefined | String[] } // ----------------------------------- diff --git a/api/src/routes/auth.test.ts b/api/src/routes/auth.test.ts new file mode 100644 index 00000000000..d8e5d59a57e --- /dev/null +++ b/api/src/routes/auth.test.ts @@ -0,0 +1,15 @@ +import { setupServer, superRequest } from '../../jest.utils'; + +describe('dev login', () => { + setupServer(); + it('should create an account if one does not exist', async () => { + await fastifyTestInstance.prisma.user.deleteMany({ + where: { email: 'foo@bar.com' } + }); + + const res = await superRequest('/auth/dev-callback', { method: 'GET' }); + + expect(res.body).toStrictEqual({ statusCode: 200 }); + expect(res.status).toBe(200); + }); +}); diff --git a/api/src/routes/auth.ts b/api/src/routes/auth.ts index 2036cbffebf..531d29be820 100644 --- a/api/src/routes/auth.ts +++ b/api/src/routes/auth.ts @@ -19,7 +19,6 @@ declare module 'fastify' { const defaultUser = { about: '', acceptedPrivacyTerms: false, - badges: {}, completedChallenges: [], currentChallengeId: '', emailVerified: false, @@ -63,8 +62,6 @@ const defaultUser = { showTimeLine: false }, progressTimestamps: [], - // TODO: check what this is used for in api-server and if we need it - rand: 0, sendQuincyEmail: false, theme: 'default', // TODO: generate a UUID like in api-server @@ -114,6 +111,7 @@ export const devLoginCallback: FastifyPluginCallback = ( const { id } = await findOrCreateUser(fastify, email); req.session.user = { id }; await req.session.save(); + return { statusCode: 200 }; }); done(); diff --git a/api/src/routes/settings.test.ts b/api/src/routes/settings.test.ts index e1d14f0bd8d..4a5601bd057 100644 --- a/api/src/routes/settings.test.ts +++ b/api/src/routes/settings.test.ts @@ -90,6 +90,7 @@ describe('settingRoutes', () => { const res = await request(fastifyTestInstance.server).get( '/auth/dev-callback' ); + expect(res.status).toBe(200); setCookies = res.get('Set-Cookie'); }); diff --git a/api/src/routes/user.test.ts b/api/src/routes/user.test.ts index 27acf07889b..7d72b50fc6a 100644 --- a/api/src/routes/user.test.ts +++ b/api/src/routes/user.test.ts @@ -43,6 +43,7 @@ describe('userRoutes', () => { beforeEach(async () => { const res = await superRequest('/auth/dev-callback', { method: 'GET' }); + expect(res.status).toBe(200); setCookies = res.get('Set-Cookie'); }); @@ -57,8 +58,8 @@ describe('userRoutes', () => { where: { email: 'foo@bar.com' } }); - expect(response.status).toBe(200); expect(response.body).toStrictEqual({}); + expect(response.status).toBe(200); expect(userCount).toBe(0); }); }); @@ -79,8 +80,8 @@ describe('userRoutes', () => { where: { email: 'foo@bar.com' } }); - expect(response.status).toBe(200); expect(response.body).toStrictEqual({}); + expect(response.status).toBe(200); expect(user?.progressTimestamps).toHaveLength(1); expect(user).toMatchObject(baseProgressData);