feat: add records deletion before seeding

This commit is contained in:
2026-09-27 16:49:06 +03:30
parent fbce16ef60
commit 17b47ffd91
5 changed files with 30 additions and 11 deletions
+19
View File
@@ -47,12 +47,31 @@ async function prepareTests() {
}
}
export async function clearDatabase() {
await dataSource.query(`
DO $$
DECLARE
r RECORD;
BEGIN
FOR r IN (
SELECT tablename
FROM pg_tables
WHERE schemaname = 'public'
)
LOOP
EXECUTE 'TRUNCATE TABLE "' || r.tablename || '" RESTART IDENTITY CASCADE';
END LOOP;
END $$;
`);
}
async function seed() {
try {
await dataSource.initialize();
console.log('Database connection initialized.');
await clearDatabase();
await seedSuperuser();
await prepareTests();
@@ -2,8 +2,8 @@ POST {{baseUrl}}/auth/verify-otp
Content-Type: application/json
{
"phone": "09121212123",
"otp": "26989"
"phone": "09333026363",
"otp": "55333"
}
{{
@@ -1,4 +1,4 @@
GET {{baseUrl}}/submissions/6183e332-d28d-45ba-90a7-942f9d15100f/history
GET {{baseUrl}}/submissions/1/history
Authorization: Bearer {{$global.accessToken}}
GET {{baseUrl}}/submissions
@@ -1,17 +1,17 @@
POST {{baseUrl}}/submissions/start
Content-Type: application/json
# Authorization: Bearer {{$global.accessToken}}
Authorization: Bearer {{$global.accessToken}}
{
"testId": 3
"testId": 1
}
POST {{baseUrl}}/submissions/6183e332-d28d-45ba-90a7-942f9d15100f/answer
POST {{baseUrl}}/submissions/2/answer
Content-Type: application/json
# Authorization: Bearer {{$global.accessToken}}
Authorization: Bearer {{$global.accessToken}}
{
"choiceId": 57
// "numericValue": 10
// "choiceIds": [45]
"choiceId": 33
// "numericValue": 1
// "choiceIds": []
}
@@ -1,3 +1,3 @@
GET {{baseUrl}}/tests
GET {{baseUrl}}/tests/4
GET {{baseUrl}}/tests/1