fix(api): improve schema accuracy (#50626)

This commit is contained in:
Oliver Eyton-Williams
2023-06-07 14:08:37 +02:00
committed by GitHub
parent 754ae54387
commit 962f45475c
5 changed files with 34 additions and 14 deletions
+14 -9
View File
@@ -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[]
}
// -----------------------------------
+15
View File
@@ -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);
});
});
+1 -3
View File
@@ -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();
+1
View File
@@ -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');
});
+3 -2
View File
@@ -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);