Simplify and fix Change.apply tests for replace
This commit is contained in:
parent
a80cedd870
commit
888d34ab7c
|
@ -132,36 +132,38 @@ test('apply - replace', function (t) {
|
||||||
vals: ['new', 'two']
|
vals: ['new', 'two']
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
var empty = new Change({
|
||||||
|
operation: 'replace',
|
||||||
|
modification: {
|
||||||
|
type: 'cn',
|
||||||
|
vals: []
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// plain
|
// plain
|
||||||
res = Change.apply(single, { cn: ['old'] });
|
res = Change.apply(single, { cn: ['old'] });
|
||||||
t.ok(res.cn);
|
t.deepEqual(res.cn, ['new']);
|
||||||
t.equal(res.cn.length, 1);
|
|
||||||
t.equal(res.cn[0], 'new');
|
|
||||||
|
|
||||||
// multiple
|
// multiple
|
||||||
res = Change.apply(single, { cn: ['old', 'also'] });
|
res = Change.apply(single, { cn: ['old', 'also'] });
|
||||||
t.ok(res.cn);
|
t.deepEqual(res.cn, ['new']);
|
||||||
t.equal(res.cn.length, 1);
|
|
||||||
t.equal(res.cn[0], 'new');
|
// empty
|
||||||
|
res = Change.apply(empty, { cn: ['existing'] });
|
||||||
|
t.equal(res.cn, undefined);
|
||||||
|
t.ok(Object.keys(res).indexOf('cn') === -1);
|
||||||
|
|
||||||
//absent
|
//absent
|
||||||
res = Change.apply(single, { dn: ['otherjunk'] });
|
res = Change.apply(single, { dn: ['otherjunk'] });
|
||||||
t.ok(res.cn);
|
t.deepEqual(res.cn, ['new']);
|
||||||
t.equal(res.cn.length, 1);
|
|
||||||
t.equal(res.cn[0], 'new');
|
|
||||||
|
|
||||||
// scalar formatting "success"
|
// scalar formatting "success"
|
||||||
res = Change.apply(single, { cn: 'old' }, true);
|
res = Change.apply(single, { cn: 'old' }, true);
|
||||||
t.ok(res.cn);
|
|
||||||
t.equal(res.cn, 'new');
|
t.equal(res.cn, 'new');
|
||||||
|
|
||||||
// scalar formatting "failure"
|
// scalar formatting "failure"
|
||||||
res = Change.apply(twin, { cn: 'old' }, true);
|
res = Change.apply(twin, { cn: 'old' }, true);
|
||||||
t.ok(res.cn);
|
t.deepEqual(res.cn, ['new', 'two']);
|
||||||
t.equal(res.cn.length, 2);
|
|
||||||
t.equal(res.cn[0], 'new');
|
|
||||||
t.equal(res.cn[1], 'two');
|
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue