2016-04-24 22:41:37 +02:00
|
|
|
'use strict';
|
2016-10-26 10:43:11 +02:00
|
|
|
|
2016-11-13 18:14:29 +01:00
|
|
|
const eventDiffer = require('./event-differ');
|
2021-04-29 10:21:29 +02:00
|
|
|
const { FEATURE_CREATED, FEATURE_UPDATED } = require('./types/events');
|
2015-01-26 16:54:50 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should not fail if events include an unknown event type', () => {
|
2016-11-13 15:41:35 +01:00
|
|
|
const events = [
|
2016-12-09 14:50:30 +01:00
|
|
|
{ type: FEATURE_CREATED, data: {} },
|
2016-11-13 15:41:35 +01:00
|
|
|
{ type: 'unknown-type', data: {} },
|
|
|
|
];
|
2015-01-26 16:54:50 +01:00
|
|
|
|
2021-01-19 10:42:45 +01:00
|
|
|
eventDiffer.addDiffs(events);
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(true).toBe(true);
|
2016-11-13 15:41:35 +01:00
|
|
|
});
|
2015-01-26 16:54:50 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('diffs a feature-update event', () => {
|
2016-11-13 15:41:35 +01:00
|
|
|
const feature = 'foo';
|
|
|
|
const desc = 'bar';
|
2015-01-26 16:54:50 +01:00
|
|
|
|
2016-11-13 15:41:35 +01:00
|
|
|
const events = [
|
|
|
|
{
|
2016-12-09 14:50:30 +01:00
|
|
|
type: FEATURE_UPDATED,
|
2017-06-28 10:17:14 +02:00
|
|
|
data: {
|
|
|
|
name: feature,
|
|
|
|
description: desc,
|
|
|
|
strategy: 'default',
|
|
|
|
enabled: true,
|
|
|
|
parameters: { value: 2 },
|
|
|
|
},
|
2016-11-13 15:41:35 +01:00
|
|
|
},
|
|
|
|
{
|
2016-12-09 14:50:30 +01:00
|
|
|
type: FEATURE_CREATED,
|
2017-06-28 10:17:14 +02:00
|
|
|
data: {
|
|
|
|
name: feature,
|
|
|
|
description: desc,
|
|
|
|
strategy: 'default',
|
|
|
|
enabled: false,
|
|
|
|
parameters: { value: 1 },
|
|
|
|
},
|
2016-11-13 15:41:35 +01:00
|
|
|
},
|
|
|
|
];
|
2015-01-26 16:54:50 +01:00
|
|
|
|
2016-11-13 15:41:35 +01:00
|
|
|
eventDiffer.addDiffs(events);
|
2015-01-26 16:54:50 +01:00
|
|
|
|
2020-04-14 22:29:11 +02:00
|
|
|
const { diffs } = events[0];
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(diffs[0].kind === 'E').toBe(true);
|
|
|
|
expect(diffs[0].path[0] === 'enabled').toBe(true);
|
|
|
|
expect(diffs[0].kind === 'E').toBe(true);
|
|
|
|
expect(diffs[0].lhs === false).toBe(true);
|
|
|
|
expect(diffs[0].rhs).toBe(true);
|
|
|
|
|
|
|
|
expect(diffs[1].kind === 'E').toBe(true);
|
|
|
|
expect(diffs[1].path[0] === 'parameters').toBe(true);
|
|
|
|
expect(diffs[1].path[1] === 'value').toBe(true);
|
|
|
|
expect(diffs[1].kind === 'E').toBe(true);
|
|
|
|
expect(diffs[1].lhs === 1).toBe(true);
|
|
|
|
|
|
|
|
expect(events[1].diffs === null).toBe(true);
|
2016-11-13 15:41:35 +01:00
|
|
|
});
|
2015-01-26 16:54:50 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('diffs only against features with the same name', () => {
|
2016-11-13 15:41:35 +01:00
|
|
|
const events = [
|
|
|
|
{
|
2016-12-09 14:50:30 +01:00
|
|
|
type: FEATURE_UPDATED,
|
2017-06-28 10:17:14 +02:00
|
|
|
data: {
|
|
|
|
name: 'bar',
|
|
|
|
description: 'desc',
|
|
|
|
strategy: 'default',
|
|
|
|
enabled: true,
|
|
|
|
parameters: {},
|
|
|
|
},
|
2016-11-13 15:41:35 +01:00
|
|
|
},
|
|
|
|
{
|
2016-12-09 14:50:30 +01:00
|
|
|
type: FEATURE_UPDATED,
|
2017-06-28 10:17:14 +02:00
|
|
|
data: {
|
|
|
|
name: 'foo',
|
|
|
|
description: 'desc',
|
|
|
|
strategy: 'default',
|
|
|
|
enabled: false,
|
|
|
|
parameters: {},
|
|
|
|
},
|
2016-11-13 15:41:35 +01:00
|
|
|
},
|
|
|
|
{
|
2016-12-09 14:50:30 +01:00
|
|
|
type: FEATURE_CREATED,
|
2017-06-28 10:17:14 +02:00
|
|
|
data: {
|
|
|
|
name: 'bar',
|
|
|
|
description: 'desc',
|
|
|
|
strategy: 'default',
|
|
|
|
enabled: false,
|
|
|
|
parameters: {},
|
|
|
|
},
|
2016-11-13 15:41:35 +01:00
|
|
|
},
|
|
|
|
{
|
2016-12-09 14:50:30 +01:00
|
|
|
type: FEATURE_CREATED,
|
2017-06-28 10:17:14 +02:00
|
|
|
data: {
|
|
|
|
name: 'foo',
|
|
|
|
description: 'desc',
|
|
|
|
strategy: 'default',
|
|
|
|
enabled: true,
|
|
|
|
parameters: {},
|
|
|
|
},
|
2016-11-13 15:41:35 +01:00
|
|
|
},
|
|
|
|
];
|
2015-01-26 16:54:50 +01:00
|
|
|
|
2016-11-13 15:41:35 +01:00
|
|
|
eventDiffer.addDiffs(events);
|
2015-01-26 16:54:50 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(events[0].diffs[0].rhs === true).toBe(true);
|
|
|
|
expect(events[1].diffs[0].rhs === false).toBe(true);
|
|
|
|
expect(events[2].diffs === null).toBe(true);
|
|
|
|
expect(events[3].diffs === null).toBe(true);
|
2016-11-13 15:41:35 +01:00
|
|
|
});
|
2015-01-26 16:54:50 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('sets an empty array of diffs if nothing was changed', () => {
|
2016-11-13 15:41:35 +01:00
|
|
|
const events = [
|
|
|
|
{
|
2016-12-09 14:50:30 +01:00
|
|
|
type: FEATURE_UPDATED,
|
2017-06-28 10:17:14 +02:00
|
|
|
data: {
|
|
|
|
name: 'foo',
|
|
|
|
description: 'desc',
|
|
|
|
strategy: 'default',
|
|
|
|
enabled: true,
|
|
|
|
parameters: {},
|
|
|
|
},
|
2016-11-13 15:41:35 +01:00
|
|
|
},
|
|
|
|
{
|
2016-12-09 14:50:30 +01:00
|
|
|
type: FEATURE_CREATED,
|
2017-06-28 10:17:14 +02:00
|
|
|
data: {
|
|
|
|
name: 'foo',
|
|
|
|
description: 'desc',
|
|
|
|
strategy: 'default',
|
|
|
|
enabled: true,
|
|
|
|
parameters: {},
|
|
|
|
},
|
2016-11-13 15:41:35 +01:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
eventDiffer.addDiffs(events);
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(events[0].diffs).toEqual([]);
|
2016-04-24 22:41:37 +02:00
|
|
|
});
|
2016-11-13 15:41:35 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('sets diffs to null if there was nothing to diff against', () => {
|
2016-11-13 15:41:35 +01:00
|
|
|
const events = [
|
|
|
|
{
|
2016-12-09 14:50:30 +01:00
|
|
|
type: FEATURE_UPDATED,
|
2017-06-28 10:17:14 +02:00
|
|
|
data: {
|
|
|
|
name: 'foo',
|
|
|
|
description: 'desc',
|
|
|
|
strategy: 'default',
|
|
|
|
enabled: true,
|
|
|
|
parameters: {},
|
|
|
|
},
|
2016-11-13 15:41:35 +01:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
eventDiffer.addDiffs(events);
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(events[0].diffs === null).toBe(true);
|
2016-11-13 15:41:35 +01:00
|
|
|
});
|