Storage Service: Fetch updates on any group record merge
This commit is contained in:
parent
a527b88867
commit
85cf445924
6 changed files with 153 additions and 97 deletions
|
@ -3,55 +3,71 @@
|
|||
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { areArraysMatchingSets } from '../../util/areArraysMatchingSets';
|
||||
import { diffArraysAsSets } from '../../util/diffArraysAsSets';
|
||||
|
||||
describe('areArraysMatchingSets', () => {
|
||||
function assertMatch<T>({
|
||||
added,
|
||||
removed,
|
||||
}: {
|
||||
added: Array<T>;
|
||||
removed: Array<T>;
|
||||
}) {
|
||||
return added.length === 0 && removed.length === 0;
|
||||
}
|
||||
|
||||
describe('diffArraysAsSets', () => {
|
||||
it('returns true if arrays are both empty', () => {
|
||||
const left: Array<string> = [];
|
||||
const right: Array<string> = [];
|
||||
|
||||
assert.isTrue(areArraysMatchingSets(left, right));
|
||||
assertMatch(diffArraysAsSets(left, right));
|
||||
});
|
||||
|
||||
it('returns true if arrays are equal', () => {
|
||||
const left = [1, 2, 3];
|
||||
const right = [1, 2, 3];
|
||||
|
||||
assert.isTrue(areArraysMatchingSets(left, right));
|
||||
assertMatch(diffArraysAsSets(left, right));
|
||||
});
|
||||
|
||||
it('returns true if arrays are equal but out of order', () => {
|
||||
const left = [1, 2, 3];
|
||||
const right = [3, 1, 2];
|
||||
|
||||
assert.isTrue(areArraysMatchingSets(left, right));
|
||||
assertMatch(diffArraysAsSets(left, right));
|
||||
});
|
||||
|
||||
it('returns true if arrays are equal but one has duplicates', () => {
|
||||
const left = [1, 2, 3, 1];
|
||||
const right = [1, 2, 3];
|
||||
|
||||
assert.isTrue(areArraysMatchingSets(left, right));
|
||||
assertMatch(diffArraysAsSets(left, right));
|
||||
});
|
||||
|
||||
it('returns false if first array has missing elements', () => {
|
||||
const left = [1, 2];
|
||||
const right = [1, 2, 3];
|
||||
|
||||
assert.isFalse(areArraysMatchingSets(left, right));
|
||||
const { added, removed } = diffArraysAsSets(left, right);
|
||||
assert.deepEqual(added, [3]);
|
||||
assert.deepEqual(removed, []);
|
||||
});
|
||||
|
||||
it('returns false if second array has missing elements', () => {
|
||||
const left = [1, 2, 3];
|
||||
const right = [1, 2];
|
||||
|
||||
assert.isFalse(areArraysMatchingSets(left, right));
|
||||
const { added, removed } = diffArraysAsSets(left, right);
|
||||
assert.deepEqual(added, []);
|
||||
assert.deepEqual(removed, [3]);
|
||||
});
|
||||
|
||||
it('returns false if second array is empty', () => {
|
||||
const left = [1, 2, 3];
|
||||
const right: Array<number> = [];
|
||||
|
||||
assert.isFalse(areArraysMatchingSets(left, right));
|
||||
const { added, removed } = diffArraysAsSets(left, right);
|
||||
assert.deepEqual(added, []);
|
||||
assert.deepEqual(removed, [1, 2, 3]);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue