-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-fixtures.js
68 lines (61 loc) · 2.09 KB
/
test-fixtures.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict'
import path from 'node:path'
import Group from './lib/group.js'
import User from './lib/user.js'
import Session from './lib/session.js'
import Permission from './lib/permission.js'
import Nameserver from './lib/nameserver.js'
import Zone from './lib/zone.js'
// import ZoneRecord from './lib/zone_record.js'
import groupCase from './lib/test/group.json' with { type: 'json' }
import userCase from './lib/test/user.json' with { type: 'json' }
import zoneCase from './lib/test/zone.json' with { type: 'json' }
// import zrCase from './lib/test/zone_record.json' with { type: 'json' }
import groupCaseR from './routes/test/group.json' with { type: 'json' }
import userCaseR from './routes/test/user.json' with { type: 'json' }
import nsCaseR from './routes/test/nameserver.json' with { type: 'json' }
switch (process.argv[2]) {
case 'setup':
setup()
break
case 'teardown':
teardown()
break
default:
console.log(
`\nusage:\tnode ${path.basename(process.argv[1])} [ setup | teardown ]\n`,
)
}
async function setup() {
await Group.create(groupCase)
await Group.create(groupCaseR)
await User.create(userCase)
await User.create(userCaseR)
// await createTestSession()
await User.mysql.disconnect()
await Group.mysql.disconnect()
process.exit(0)
}
// async function createTestSession() {
// await Session.create({
// nt_user_id: userCase.nt_user_id,
// nt_user_session: '3.0.0',
// last_access: parseInt(Date.now(), 10),
// })
// }
async function teardown() {
// await ZoneRecord.destroy({ id: zrCase.id })
await Zone.destroy({ id: zoneCase.id })
await Nameserver.destroy({ id: nsCaseR.id })
await Nameserver.destroy({ id: nsCaseR.id - 1 })
await Permission.destroy({ id: userCase.id })
await Permission.destroy({ id: userCase.id - 1 })
await Session.delete({ nt_user_id: userCase.id })
await User.destroy({ id: userCase.id })
await User.destroy({ id: userCaseR.id })
await Group.destroy({ id: groupCase.id })
await Group.destroy({ id: groupCaseR.id })
await User.mysql.disconnect()
await Group.mysql.disconnect()
process.exit(0)
}