-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_translation.ts
More file actions
87 lines (71 loc) · 2.37 KB
/
test_translation.ts
File metadata and controls
87 lines (71 loc) · 2.37 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
import assert from 'node:assert/strict'
import { after, beforeEach, describe, it } from 'node:test'
import { BaseApiClient } from './base.ts'
import { TRANSLATION_MAP_SCHEMA } from '../../common/translation.ts'
import { assertTrue } from '../assertion.ts'
describe('/api/translation', function () {
let client: BaseApiClient
beforeEach(async function () {
if (client) {
await client.reset()
} else {
client = await BaseApiClient.initialize()
}
})
after(async function () {
await client?.finalize()
})
it('serves a correct core English translation', async function () {
const response = await client.get('/api/translation/core?lang=en')
const payload = await response.json()
assertTrue(
TRANSLATION_MAP_SCHEMA.matches(payload),
)
})
it('errors out with 404 at the root', async function () {
const response = await client.get('/api/translation')
assert.equal(response.status(), 404)
assert.deepEqual(
await response.json(),
{ errorKind: 'http', code: 404 },
)
})
it('errors out with 404 for an invalid map', async function () {
const response = await client.get('/api/translation/invalid?lang=en')
assert.equal(response.status(), 404)
assert.deepEqual(
await response.json(),
{ errorKind: 'http', code: 404 },
)
})
it('displays a raw error if requested', async function () {
const response = await client.get('/api/translation/core', { rawErrorResponse: true })
assert.equal(response.status(), 400)
assert.deepEqual(
await response.json(),
{
errorKind: 'http', code: 400,
details: {
bundleId: 'api',
key: 'error.details.language_string.missing',
},
},
)
})
it('errors out with 400 for a valid map with an invalid language', async function () {
const response = await client.get('/api/translation/core?lang=invalid')
assert.equal(response.status(), 400)
assert.deepEqual(
await response.json(),
{ errorKind: 'http', code: 400, details: 'Unexpected language `invalid`.' },
)
})
it('errors out with 403 on server translations', async function () {
const response = await client.get('/api/translation/server?lang=en')
assert.equal(response.status(), 403)
assert.deepEqual(
await response.json(),
{ errorKind: 'http', code: 403 },
)
})
})