1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/lib/client-metrics/projection.test.js

35 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-11-13 18:14:29 +01:00
'use strict';
2018-12-17 09:24:49 +01:00
const test = require('ava');
2016-11-13 18:14:29 +01:00
const Projection = require('./projection');
test('should return set empty if missing', t => {
const projection = new Projection();
projection.substract('name-1', { yes: 1, no: 2 });
t.deepEqual(projection.getProjection()['name-1'], { yes: 0, no: 0 });
});
test('should add and substract', t => {
const projection = new Projection();
t.truthy(projection.store);
projection.add('name-1', { yes: 1, no: 2 });
t.deepEqual(projection.getProjection()['name-1'], { yes: 1, no: 2 });
projection.add('name-1', { yes: 1, no: 2 });
t.deepEqual(projection.getProjection()['name-1'], { yes: 2, no: 4 });
projection.substract('name-1', { yes: 1, no: 2 });
t.deepEqual(projection.getProjection()['name-1'], { yes: 1, no: 2 });
projection.substract('name-1', { yes: 1, no: 2 });
t.deepEqual(projection.getProjection()['name-1'], { yes: 0, no: 0 });
projection.substract('name-2', { yes: 23213, no: 23213 });
projection.add('name-2', { yes: 3, no: 2 });
t.deepEqual(projection.getProjection()['name-2'], { yes: 3, no: 2 });
});