mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(api): improve schema accuracy (#50626)
This commit is contained in:
committed by
GitHub
parent
754ae54387
commit
962f45475c
@@ -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[]
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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();
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user