|
| 1 | +import { SplitFactory as SplitFactorySS } from '../../factory/node'; |
| 2 | +import { SplitFactory as SplitFactoryCS } from '../../factory/browser'; |
| 3 | + |
| 4 | +// Tests should finish without dangling timers or requests |
| 5 | +export default function (settings, fetchMock, t) { |
| 6 | + |
| 7 | + t.test('Server-side', async (assert) => { |
| 8 | + let splitio; |
| 9 | + |
| 10 | + for (let i = 0; i < 100; i++) { |
| 11 | + splitio = SplitFactorySS({ |
| 12 | + core: { |
| 13 | + authorizationKey: 'fake-token-' + i, |
| 14 | + }, |
| 15 | + urls: { |
| 16 | + sdk: 'https://not-called/api', |
| 17 | + events: 'https://not-called/api', |
| 18 | + auth: 'https://not-called/api', |
| 19 | + } |
| 20 | + }, (modules) => { |
| 21 | + modules.lazyInit = true; |
| 22 | + }); |
| 23 | + |
| 24 | + const manager = splitio.manager(); |
| 25 | + assert.deepEqual(manager.names(), [], 'We should not have done any request yet'); |
| 26 | + |
| 27 | + const client = splitio.client(); |
| 28 | + assert.equal(client.getTreatment('user-1', 'split_test'), 'control', 'We should get control'); |
| 29 | + assert.equal(client.track('user-1', 'user', 'my_event'), true, 'We should track the event'); |
| 30 | + } |
| 31 | + |
| 32 | + fetchMock.getOnce('https://not-called/api/splitChanges?s=1.1&since=-1', { status: 200, body: { splits: [], since: -1, till: 1457552620999 } }); |
| 33 | + fetchMock.getOnce('https://not-called/api/splitChanges?s=1.1&since=1457552620999', { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } }); |
| 34 | + fetchMock.postOnce('https://not-called/api/testImpressions/bulk', 200); |
| 35 | + fetchMock.postOnce('https://not-called/api/events/bulk', 200); |
| 36 | + |
| 37 | + splitio.init(); |
| 38 | + await splitio.client().ready(); |
| 39 | + assert.true(splitio.client().__getStatus().isReady, 'Split SDK is ready'); |
| 40 | + await splitio.destroy(); |
| 41 | + |
| 42 | + assert.end(); |
| 43 | + }); |
| 44 | + |
| 45 | + t.test('Client-side', async (assert) => { |
| 46 | + let splitio; |
| 47 | + |
| 48 | + for (let i = 0; i < 100; i++) { |
| 49 | + splitio = SplitFactoryCS({ |
| 50 | + core: { |
| 51 | + authorizationKey: 'fake-token-' + i, |
| 52 | + key: 'user-' + i, |
| 53 | + }, |
| 54 | + urls: { |
| 55 | + sdk: 'https://not-called/api', |
| 56 | + events: 'https://not-called/api', |
| 57 | + auth: 'https://not-called/api', |
| 58 | + } |
| 59 | + }, (modules) => { |
| 60 | + modules.lazyInit = true; |
| 61 | + }); |
| 62 | + |
| 63 | + const manager = splitio.manager(); |
| 64 | + assert.deepEqual(manager.names(), [], 'We should not have done any request yet'); |
| 65 | + |
| 66 | + const client = splitio.client(); |
| 67 | + assert.equal(client.getTreatment('split_test'), 'control', 'We should get control'); |
| 68 | + assert.equal(client.track('user', 'my_event'), true, 'We should track the event'); |
| 69 | + |
| 70 | + const otherClient = splitio.client('other-user'); |
| 71 | + assert.equal(otherClient.getTreatment('split_test'), 'control', 'We should get control'); |
| 72 | + assert.equal(otherClient.track('user', 'my_event'), true, 'We should track the event'); |
| 73 | + } |
| 74 | + |
| 75 | + fetchMock.getOnce('https://not-called/api/splitChanges?s=1.2&since=-1', { status: 200, body: { splits: [], since: -1, till: 1457552620999 } }); |
| 76 | + fetchMock.getOnce('https://not-called/api/splitChanges?s=1.2&since=1457552620999', { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } }); |
| 77 | + fetchMock.getOnce('https://not-called/api/memberships/user-99', { status: 200, body: {} }); |
| 78 | + fetchMock.getOnce('https://not-called/api/memberships/other-user', { status: 200, body: {} }); |
| 79 | + fetchMock.postOnce('https://not-called/api/testImpressions/bulk', 200); |
| 80 | + fetchMock.postOnce('https://not-called/api/events/bulk', 200); |
| 81 | + |
| 82 | + splitio.init(); |
| 83 | + await splitio.client().ready(); |
| 84 | + assert.true(splitio.client().__getStatus().isReady, 'Split SDK is ready'); |
| 85 | + await splitio.destroy(); |
| 86 | + |
| 87 | + assert.end(); |
| 88 | + }); |
| 89 | +} |
0 commit comments