Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 94ee77a

Browse files
committed
Added foreign key migration
1 parent d1db9f4 commit 94ee77a

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* eslint-disable camelcase */
2+
3+
exports.shorthands = undefined
4+
5+
exports.up = pgm => {
6+
pgm.addConstraint('solves', 'uuid_fkey', {
7+
foreignKeys: {
8+
columns: 'userid',
9+
references: 'users("id")',
10+
onDelete: 'cascade',
11+
onUpdate: 'cascade'
12+
}
13+
})
14+
}
15+
16+
exports.down = pgm => {
17+
pgm.dropConstraint('solves', 'uuid_fkey')
18+
}

server/api/users/delete.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ module.exports = {
1010
id: uuid
1111
})
1212

13-
await database.solves.removeSolvesByUserId({
14-
id: uuid
15-
})
16-
1713
return responses.goodUserDelete
1814
}
1915
}

test/integration/submit.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const db = require('../../server/database')
77
const challenges = require('../../server/challenges')
88
const { responseList } = require('../../server/responses')
99
const auth = require('../../server/auth')
10+
const util = require('../util')
1011

1112
const chall = challenges.getAllChallenges()[0]
1213

@@ -19,6 +20,11 @@ test('fails with unauthorized', async t => {
1920
})
2021

2122
const uuid = uuidv4()
23+
const testUser = {
24+
...util.generateTestUser(),
25+
id: uuid,
26+
perms: 0
27+
}
2228

2329
test('fails with badBody', async t => {
2430
const badChallenge = uuidv4()
@@ -44,6 +50,8 @@ test.serial('fails with badFlag', async t => {
4450
})
4551

4652
test.serial('succeeds with goodFlag', async t => {
53+
await db.auth.makeUser(testUser)
54+
4755
const authToken = await auth.token.getToken(auth.token.tokenKinds.auth, uuid)
4856
const resp = await request(app)
4957
.post(process.env.API_ENDPOINT + '/challs/' + encodeURIComponent(chall.id) + '/submit')
@@ -67,4 +75,7 @@ test.serial('fails with badAlreadySolvedChallenge', async t => {
6775

6876
test.after.always('remove solves from test user', async t => {
6977
await db.solves.removeSolvesByUserId({ userid: uuid })
78+
await db.auth.removeUserById({
79+
id: testUser.id
80+
})
7081
})

0 commit comments

Comments
 (0)