-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathzone.test.js
More file actions
68 lines (57 loc) · 2.06 KB
/
zone.test.js
File metadata and controls
68 lines (57 loc) · 2.06 KB
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
import assert from 'node:assert/strict'
import { describe, it, after, before } from 'node:test'
import Zone from './zone.js'
import testCase from './test/zone.json' with { type: 'json' }
before(async () => {
await Zone.destroy({ id: testCase.id })
await Zone.create(testCase)
})
after(async () => {
// await Zone.destroy({ id: testCase.id })
Zone.mysql.disconnect()
})
describe('zone', function () {
it('gets zone by id', async () => {
const g = await Zone.get({ id: testCase.id })
delete g[0].last_modified
assert.deepEqual(g[0], testCase)
})
it('gets zone by name', async () => {
const g = await Zone.get({ zone: testCase.zone })
delete g[0].last_modified
assert.deepEqual(g[0], testCase)
})
it('changes a zone', async () => {
assert.ok(await Zone.put({ id: testCase.id, mailaddr: 'toastmaster.example.com.' }))
const ns = await Zone.get({ id: testCase.id })
assert.deepEqual(ns[0].mailaddr, 'toastmaster.example.com.')
assert.ok(await Zone.put({ id: testCase.id, mailaddr: testCase.mailaddr }))
})
it('handles null minimum gracefully', async () => {
await Zone.mysql.execute('UPDATE nt_zone SET minimum = NULL WHERE nt_zone_id = ?', [testCase.id])
const z = await Zone.get({ id: testCase.id })
assert.equal(z[0].minimum, 3600)
await Zone.mysql.execute('UPDATE nt_zone SET minimum = ? WHERE nt_zone_id = ?', [
testCase.minimum,
testCase.id,
])
})
describe('deletes a zone', async () => {
it('can delete a zone', async () => {
assert.ok(await Zone.delete({ id: testCase.id }))
})
it('default get does not find deleted zone', async () => {
let z = await Zone.get({ id: testCase.id })
assert.equal(z.length, 0)
})
it('can get the deleted zone', async () => {
let z = await Zone.get({ id: testCase.id, deleted: 1 })
assert.equal(z[0]?.deleted, true)
})
it('can restore the zone', async () => {
await Zone.delete({ id: testCase.id, deleted: 0 })
let z = await Zone.get({ id: testCase.id })
assert.equal(z.length, 1)
})
})
})