chore(api): add exam-env test script (#60445)

This commit is contained in:
Shaun Hamilton
2025-05-27 06:23:51 +02:00
committed by GitHub
parent 0b1db2b9c6
commit a90e2757ac
3 changed files with 43 additions and 5 deletions
+1 -1
View File
@@ -42,5 +42,5 @@ During development and testing, the api exposes the endpoint GET auth/dev-callba
## Generating Exams
```bash
pnpm run generate-exams <ENV_EXAM_ID> <NUMBER_OF_EXAMS_TO_GENERATE>
pnpm run exam-env:generate <ENV_EXAM_ID> <NUMBER_OF_EXAMS_TO_GENERATE>
```
+5 -4
View File
@@ -76,10 +76,11 @@
"test-with-logging": "FCC_ENABLE_TEST_LOGGING=true pnpm run test",
"prisma": "dotenv -e ../.env prisma",
"postinstall": "prisma generate",
"generate-exams": "tsx tools/exam-environment/generate/index.ts",
"deprecate-exam": "tsx tools/exam-environment/generate/deprecate.ts",
"insert-exam": "tsx tools/exam-environment/generate/insert.ts",
"seed:env-exam": "tsx tools/exam-environment/seed/index.ts"
"exam-env:generate": "tsx tools/exam-environment/generate/index.ts",
"exam-env:generate:deprecate": "tsx tools/exam-environment/generate/deprecate.ts",
"exam-env:generate:insert": "tsx tools/exam-environment/generate/insert.ts",
"exam-env:seed": "tsx tools/exam-environment/seed/index.ts",
"exam-env:test": "tsx tools/exam-environment/test/index.ts"
},
"version": "0.0.1"
}
+37
View File
@@ -0,0 +1,37 @@
//! Check the records on the database matches the Prisma schema
//!
//! This script should be run, before any deployments with Exam schema changes.
//! WARNING: This script queries every single record in the `Env<>` collections.
import { PrismaClient } from '@prisma/client';
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library';
import { MONGOHQ_URL } from '../../../src/utils/env';
const prisma = new PrismaClient({
datasources: {
db: {
url: MONGOHQ_URL
}
}
});
async function main() {
await prisma.$connect();
try {
const envExam = await prisma.envExam.findMany();
const envGeneratedExam = await prisma.envGeneratedExam.findMany();
const envExamAttempt = await prisma.envExamAttempt.findMany();
console.log('Number of exams:', envExam.length);
console.log('Number of generated exams:', envGeneratedExam.length);
console.log('Number of exam attempts:', envExamAttempt.length);
// NOTE: This is not strictly true. E.g. If a `Boolean` becomes an `Int`, Prisma converts it instead of throwing.
console.log('\nSUCCESS! The database schema matches the Prisma schema.');
} catch (error) {
if (error instanceof PrismaClientKnownRequestError) {
console.log(error.message);
console.info('\nCHECK DATABASE SCHEMA!');
}
}
}
void main();