-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathflexible-rollout.test.ts
71 lines (60 loc) · 2.54 KB
/
flexible-rollout.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
71
/* eslint-disable import/no-extraneous-dependencies */
import test from 'ava';
import * as sinon from 'sinon';
import FlexibleRolloutStrategy from '../../strategy/flexible-rollout-strategy';
test('should have correct name', (t) => {
const strategy = new FlexibleRolloutStrategy();
t.deepEqual(strategy.name, 'flexibleRollout');
});
test('should NOT be enabled for userId=61 and rollout=9', (t) => {
const strategy = new FlexibleRolloutStrategy();
const params = { rollout: 9, stickiness: 'default', groupId: 'Demo' };
const context = { userId: '61', application: 'web' };
t.false(strategy.isEnabled(params, context));
});
test('should be enabled for userId=61 and rollout=10', (t) => {
const strategy = new FlexibleRolloutStrategy();
const params = { rollout: '10', stickiness: 'default', groupId: 'Demo' };
const context = { userId: '61', application: 'web' };
t.true(strategy.isEnabled(params, context));
});
test('should be disabled when stickiness=userId and userId not on context', (t) => {
const strategy = new FlexibleRolloutStrategy();
const params = { rollout: '100', stickiness: 'userId', groupId: 'Demo' };
const context = {};
t.false(strategy.isEnabled(params, context));
});
test('should fallback to random if stickiness=default and empty context', (t) => {
const randomGenerator = sinon.fake.returns('42'); // eslint-disable-line import/namespace
const strategy = new FlexibleRolloutStrategy(randomGenerator);
const params = { rollout: '100', stickiness: 'default', groupId: 'Demo' };
const context = {};
t.true(strategy.isEnabled(params, context));
t.true(randomGenerator.called);
});
test('should NOT be enabled for rollout=10% when userId is 123', (t) => {
const strategy = new FlexibleRolloutStrategy();
const params = { rollout: 10, stickiness: 'default', groupId: 'toggleName' };
const context = { environment: 'dev', userId: '123' };
t.false(strategy.isEnabled(params, context));
});
test('should be disabled when stickiness=customerId and customerId not found on context', (t) => {
const strategy = new FlexibleRolloutStrategy();
const params = {
rollout: '100',
stickiness: 'customerId',
groupId: 'Demo',
};
const context = {};
t.false(strategy.isEnabled(params, context));
});
test('should be enabled when stickiness=customerId and customerId=61', (t) => {
const strategy = new FlexibleRolloutStrategy();
const params = {
rollout: '100',
stickiness: 'customerId',
groupId: 'Demo',
};
const context = { customerId: 61 };
t.true(strategy.isEnabled(params, context));
});