-
-
Notifications
You must be signed in to change notification settings - Fork 768
/
Copy pathapi-token-schema.test.ts
62 lines (56 loc) · 1.81 KB
/
api-token-schema.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
import { ALL } from '../types/models/api-token';
import { createApiToken } from './api-token-schema';
test('should reject token with projects and project', async () => {
expect.assertions(1);
try {
await createApiToken.validateAsync({
username: 'test',
type: 'admin',
project: 'default',
projects: ['default'],
});
} catch (error) {
expect(error.details[0].message).toEqual(
'"project" must not exist simultaneously with [projects]',
);
}
});
test('should not have default project set if projects is present', async () => {
const token = await createApiToken.validateAsync({
username: 'test',
type: 'admin',
projects: ['default'],
});
expect(token.project).not.toBeDefined();
});
test('should have project set to default if projects is missing', async () => {
const token = await createApiToken.validateAsync({
username: 'test',
type: 'admin',
});
expect(token.project).toBe(ALL);
});
test('should not have projects set if project is present', async () => {
const token = await createApiToken.validateAsync({
username: 'test',
type: 'admin',
project: 'default',
});
expect(token.projects).not.toBeDefined();
});
test('should allow for embedded proxy (frontend) key', async () => {
const token = await createApiToken.validateAsync({
username: 'test',
type: 'frontend',
project: 'default',
});
expect(token.error).toBeUndefined();
});
test('should set environment to default for frontend key', async () => {
const token = await createApiToken.validateAsync({
username: 'test',
type: 'frontend',
project: 'default',
});
expect(token.environment).toEqual('default');
});