-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_files.ts
More file actions
90 lines (72 loc) · 2.41 KB
/
test_files.ts
File metadata and controls
90 lines (72 loc) · 2.41 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import assert from 'node:assert/strict'
import { after, beforeEach, describe, it } from 'node:test'
import { BaseApiClient } from './base.ts'
import { DIRECTORY_SCHEMA } from '../../common/services.ts'
import { assertTrue } from '../assertion.ts'
describe('/api/files', function () {
let client: BaseApiClient
beforeEach(async function () {
if (client) {
await client.reset()
} else {
client = await BaseApiClient.initialize()
}
})
after(async function () {
await client?.finalize()
})
it('matches the directory schema at the root', async function () {
const response = await client.get('/api/files')
const payload = await response.json()
assertTrue(
DIRECTORY_SCHEMA.matches(payload),
)
})
it('matches the directory schema on an existing directory', async function () {
const response = await client.get('/api/files/sub')
const payload = await response.json()
assertTrue(
DIRECTORY_SCHEMA.matches(payload),
)
})
it('errors out with 404 on an invalid directory', async function () {
const response = await client.get('/api/files/invalid')
assert.equal(response.status(), 404)
assert.deepEqual(
await response.json(),
{ errorKind: 'http', code: 404 },
)
})
it('errors out with 403 on an existing hidden directory', async function () {
const response = await client.get('/api/files/.valid')
assert.equal(response.status(), 403)
assert.deepEqual(
await response.json(),
{ errorKind: 'http', code: 403 },
)
})
it('errors out with 403 on a hidden subdirectory of a visible directory', async function () {
const response = await client.get('/api/files/.valid/sub')
assert.equal(response.status(), 403)
assert.deepEqual(
await response.json(),
{ errorKind: 'http', code: 403 },
)
})
it('errors out with 403 on a visible subdirectory of a hidden directory', async function () {
const response = await client.get('/api/files/.valid/sub')
assert.equal(response.status(), 403)
assert.deepEqual(
await response.json(),
{ errorKind: 'http', code: 403 },
)
})
it('errors out with 403 on a non-existing hidden directory', async function () {
const response = await client.get('/api/files/.invalid')
assert.equal(response.status(), 403)
assert.deepEqual(
await response.json(),
{ errorKind: 'http', code: 403 },
)
})
})