-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathverifyApiToken.test.ts
More file actions
47 lines (39 loc) · 1.27 KB
/
verifyApiToken.test.ts
File metadata and controls
47 lines (39 loc) · 1.27 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
import assert from 'node:assert/strict';
import { afterEach, beforeEach, suite, test } from 'node:test';
import { Client } from './Client.js';
import { Container } from './Container.js';
import { getImageVersionFromDockerfile } from './getImageVersionFromDockerfile.js';
suite('verifyApiToken', { timeout: 30_000 }, () => {
let container: Container;
beforeEach(async () => {
const imageVersion = getImageVersionFromDockerfile();
container = new Container().withImageTag(imageVersion);
await container.start();
});
afterEach(async () => {
await container.stop();
});
test('does not throw an error if the token is valid.', async (): Promise<void> => {
const client = container.getClient();
// Should not throw.
await client.verifyApiToken();
});
test('throws an error if the token is invalid.', async (): Promise<void> => {
const url = container.getBaseUrl();
const invalidApiToken = `${container.getApiToken()}-invalid`;
const client = new Client(url, invalidApiToken);
await assert.rejects(
async () => {
await client.verifyApiToken();
},
error => {
assert.ok(error instanceof Error);
assert.equal(
error.message,
"Failed to verify API token, got HTTP status code '401', expected '200'.",
);
return true;
},
);
});
});