forked from meilisearch/meilisearch-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump.test.ts
70 lines (63 loc) · 1.96 KB
/
dump.test.ts
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
import { ErrorStatusCode } from '../src/types'
import {
clearAllIndexes,
config,
MeiliSearch,
BAD_HOST,
getClient,
} from './utils/meilisearch-test-utils'
beforeEach(async () => {
await clearAllIndexes(config)
})
describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
'Test on dump',
({ permission }) => {
test(`${permission} key: create a new dump`, async () => {
const client = await getClient(permission)
const { taskUid } = await client.createDump()
await client.waitForTask(taskUid)
})
}
)
describe.each([{ permission: 'Search' }])(
'Test on dump with search api key should not have access',
({ permission }) => {
test(`${permission} key: try to create dump with search key and be denied`, async () => {
const client = await getClient(permission)
await expect(client.createDump()).rejects.toHaveProperty(
'code',
ErrorStatusCode.INVALID_API_KEY
)
})
}
)
describe.each([{ permission: 'No' }])(
'Test on dump without api key should not have access',
({ permission }) => {
test(`${permission} key: try to create dump with no key and be denied`, async () => {
const client = await getClient(permission)
await expect(client.createDump()).rejects.toHaveProperty(
'code',
ErrorStatusCode.MISSING_AUTHORIZATION_HEADER
)
})
}
)
describe.each([
{ host: BAD_HOST, trailing: false },
{ host: `${BAD_HOST}/api`, trailing: false },
{ host: `${BAD_HOST}/trailing/`, trailing: true },
])('Tests on url construction', ({ host, trailing }) => {
test(`Test createDump route`, async () => {
const route = `dumps`
const client = new MeiliSearch({ host })
const strippedHost = trailing ? host.slice(0, -1) : host
await expect(client.createDump()).rejects.toHaveProperty(
'message',
`request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace(
'http://',
''
)}`
)
})
})