Skip to content

Commit 568840b

Browse files
feat(api): exam date use + split prisma files (freeCodeCamp#62344)
Co-authored-by: Oliver Eyton-Williams <[email protected]>
1 parent 3dc1e8b commit 568840b

16 files changed

+1034
-524
lines changed

api/__mocks__/exam-environment-exam.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ export const oid = () => new ObjectId().toString();
1616

1717
export const examId = oid();
1818

19-
export const config: ExamEnvironmentConfig = {
19+
export const config = {
2020
totalTimeInMS: 2 * 60 * 60 * 1000,
21+
totalTimeInS: 2 * 60 * 60,
2122
tags: [],
2223
name: 'Test Exam',
2324
note: 'Some exam note...',
@@ -45,8 +46,9 @@ export const config: ExamEnvironmentConfig = {
4546
numberOfIncorrectAnswers: 1
4647
}
4748
],
48-
retakeTimeInMS: 24 * 60 * 60 * 1000
49-
};
49+
retakeTimeInMS: 24 * 60 * 60 * 1000,
50+
retakeTimeInS: 24 * 60 * 60
51+
} satisfies ExamEnvironmentConfig;
5052

5153
export const questionSets: ExamEnvironmentQuestionSet[] = [
5254
{
@@ -247,7 +249,7 @@ export const generatedExam: ExamEnvironmentGeneratedExam = {
247249
]
248250
}
249251
],
250-
version: 1
252+
version: 2
251253
};
252254

253255
export const examAttempt: ExamEnvironmentExamAttempt = {
@@ -261,7 +263,8 @@ export const examAttempt: ExamEnvironmentExamAttempt = {
261263
{
262264
id: generatedExam.questionSets[0]!.questions[0]!.id,
263265
answers: [generatedExam.questionSets[0]!.questions[0]!.answers[0]!],
264-
submissionTimeInMS: Date.now()
266+
submissionTimeInMS: Date.now(),
267+
submissionTime: new Date()
265268
}
266269
]
267270
},
@@ -271,7 +274,8 @@ export const examAttempt: ExamEnvironmentExamAttempt = {
271274
{
272275
id: generatedExam.questionSets[1]!.questions[0]!.id,
273276
answers: [generatedExam.questionSets[1]!.questions[0]!.answers[1]!],
274-
submissionTimeInMS: Date.now()
277+
submissionTimeInMS: Date.now(),
278+
submissionTime: new Date()
275279
}
276280
]
277281
},
@@ -281,22 +285,25 @@ export const examAttempt: ExamEnvironmentExamAttempt = {
281285
{
282286
id: generatedExam.questionSets[2]!.questions[0]!.id,
283287
answers: [generatedExam.questionSets[2]!.questions[0]!.answers[1]!],
284-
submissionTimeInMS: Date.now()
288+
submissionTimeInMS: Date.now(),
289+
submissionTime: new Date()
285290
},
286291
{
287292
id: generatedExam.questionSets[2]!.questions[1]!.id,
288293
answers: [generatedExam.questionSets[2]!.questions[1]!.answers[0]!],
289-
submissionTimeInMS: Date.now()
294+
submissionTimeInMS: Date.now(),
295+
submissionTime: new Date()
290296
}
291297
]
292298
}
293299
],
294300
startTimeInMS: Date.now(),
301+
startTime: new Date(),
295302
userId: defaultUserId,
296-
version: 1
303+
version: 2
297304
};
298305

299-
export const examAttemptSansSubmissionTimeInMS: Static<
306+
export const examAttemptSansSubmissionTime: Static<
300307
typeof examEnvironmentPostExamAttempt.body
301308
>['attempt'] = {
302309
examId,
@@ -335,20 +342,21 @@ export const examAttemptSansSubmissionTimeInMS: Static<
335342
]
336343
};
337344

338-
export const exam: ExamEnvironmentExam = {
345+
export const exam = {
339346
id: examId,
340347
config,
341348
questionSets,
342349
prerequisites: ['67112fe1c994faa2c26d0b1d'],
343350
deprecated: false,
344-
version: 1
345-
};
351+
version: 2
352+
} satisfies ExamEnvironmentExam;
346353

347354
export const examEnvironmentChallenge: ExamEnvironmentChallenge = {
348355
id: oid(),
349356
examId,
350357
// Id of the certified full stack developer exam challenge page
351-
challengeId: '645147516c245de4d11eb7ba'
358+
challengeId: '645147516c245de4d11eb7ba',
359+
version: 1
352360
};
353361

354362
export async function seedEnvExam() {

api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"@fastify/swagger-ui": "5.2.0",
1414
"@fastify/type-provider-typebox": "5.1.0",
1515
"@growthbook/growthbook": "1.3.1",
16-
"@prisma/client": "5.5.2",
16+
"@prisma/client": "6.16.2",
1717
"@sentry/node": "9.1.0",
1818
"@sinclair/typebox": "^0.34.33",
1919
"@types/pino": "^7.0.5",
@@ -51,7 +51,7 @@
5151
"dotenv-cli": "7.3.0",
5252
"jsdom": "^26.1.0",
5353
"msw": "^2.7.0",
54-
"prisma": "5.5.2",
54+
"prisma": "6.16.2",
5555
"supertest": "6.3.3",
5656
"tsx": "4.19.1",
5757
"vitest": "^3.2.4"

api/prisma.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { PrismaConfig } from 'prisma';
2+
3+
export default {
4+
schema: 'prisma'
5+
} satisfies PrismaConfig;

api/prisma/exam-creator.prisma

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/// A copy of `ExamEnvironmentExam` used as a staging collection for updates to the curriculum.
2+
///
3+
/// This collection schema must be kept in sync with `ExamEnvironmentExam`.
4+
model ExamCreatorExam {
5+
/// Globally unique exam id
6+
id String @id @default(auto()) @map("_id") @db.ObjectId
7+
/// All questions for a given exam
8+
questionSets ExamEnvironmentQuestionSet[]
9+
/// Configuration for exam metadata
10+
config ExamEnvironmentConfig
11+
/// ObjectIds for required challenges/blocks to take the exam
12+
prerequisites String[] @db.ObjectId
13+
/// If `deprecated`, the exam should no longer be considered for users
14+
deprecated Boolean
15+
/// Version of the record
16+
/// The default must be incremented by 1, if anything in the schema changes
17+
version Int @default(2)
18+
19+
}
20+
21+
/// Exam Creator application collection to store authZ users.
22+
///
23+
/// Currently, this is manually created in order to grant access to the application.
24+
model ExamCreatorUser {
25+
id String @id @default(auto()) @map("_id") @db.ObjectId
26+
email String
27+
/// Unique id from GitHub for an account.
28+
///
29+
/// Currently, this is unused. Consider removing.
30+
github_id Int?
31+
name String
32+
picture String?
33+
/// TODO: After migration, remove optionality
34+
settings ExamCreatorUserSettings?
35+
version Int @default(1)
36+
37+
38+
ExamCreatorSession ExamCreatorSession[]
39+
}
40+
41+
type ExamCreatorUserSettings {
42+
databaseEnvironment ExamCreatorDatabaseEnvironment
43+
}
44+
45+
enum ExamCreatorDatabaseEnvironment {
46+
Production
47+
Staging
48+
}
49+
50+
/// Exam Creator application collection to store auth sessions.
51+
model ExamCreatorSession {
52+
id String @id @default(auto()) @map("_id") @db.ObjectId
53+
user_id String @db.ObjectId
54+
session_id String
55+
/// Expiration date for record.
56+
expires_at DateTime
57+
58+
version Int @default(1)
59+
60+
61+
ExamCreatorUser ExamCreatorUser @relation(fields: [user_id], references: [id])
62+
}

0 commit comments

Comments
 (0)