-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsplit.test.js
More file actions
75 lines (68 loc) · 2.9 KB
/
split.test.js
File metadata and controls
75 lines (68 loc) · 2.9 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
const request = require('supertest');
const app = require('../../app');
const { expectError, expectErrorContaining } = require('../../utils/testWrapper');
describe('split', () => {
// Testing authorization
test('should be 401 if auth is not passed', async () => {
const response = await request(app)
.get('/manager/split?split-name=split');
expectError(response, 401, 'Unauthorized');
});
test('should be 401 if auth does not match', async () => {
const response = await request(app)
.get('/manager/split?split-name=split')
.set('Authorization', 'invalid');
expectError(response, 401, 'Unauthorized');
});
test('should be 400 if split-name is not passed', async () => {
const expected = [
'you passed a null or undefined split-name, split-name must be a non-empty string.'
];
const response = await request(app)
.get('/manager/split')
.set('Authorization', 'test');
expectErrorContaining(response, 400, expected);
});
test('should be 400 if split-name is empty', async () => {
const expected = [
'you passed an empty split-name, split-name must be a non-empty string.'
];
const response = await request(app)
.get('/manager/split?split-name=')
.set('Authorization', 'test');
expectErrorContaining(response, 400, expected);
});
test('should be 400 if split-name is empty trimmed', async () => {
const expected = [
'you passed an empty split-name, split-name must be a non-empty string.'
];
const response = await request(app)
.get('/manager/split?split-name= ')
.set('Authorization', 'test');
expectErrorContaining(response, 400, expected);
});
test('should be 404 if split is not found', async () => {
const response = await request(app)
.get('/manager/split?split-name=not-found')
.set('Authorization', 'test');
expect(response.statusCode).toBe(404);
expect(response.body).toHaveProperty('error', 'Feature flag "not-found" was not found.');
});
test('should be 200 and matches with passed split in YAML', async () => {
const response = await request(app)
.get('/manager/split?split-name=my-experiment')
.set('Authorization', 'test');
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('name', 'my-experiment');
expect(response.body).toHaveProperty('trafficType', 'localhost');
expect(response.body).toHaveProperty('killed', false);
expect(response.body).toHaveProperty('changeNumber', 0);
expect(response.body).toHaveProperty('treatments');
expect(response.body.treatments).toEqual(expect.arrayContaining(['on', 'off']));
expect(response.body).toHaveProperty('configs');
expect(response.body.configs).toEqual({
on: '{"desc" : "this applies only to ON treatment"}',
off: '{"desc" : "this applies only to OFF and only for only_test. The rest will receive ON"}',
});
});
});