-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathddd.test.js
66 lines (59 loc) · 1.69 KB
/
ddd.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
const assert = require('node:assert');
const { describe, it } = require('node:test');
const { Entity } = require('./ddd');
const { ValueObject } = require('./ddd');
describe('Entity', () => {
const Cat = Entity.fromKeys(['id', 'name', 'age', 'color']);
const cat = new Cat({
id: '123',
name: 'Sanya',
age: 3,
color: 'Orange tabbie',
});
it('Has correct properties', () => {
assert.strictEqual(cat.id, '123');
assert.strictEqual(cat.name, 'Sanya');
assert.strictEqual(cat.age, 3);
assert.strictEqual(cat.color, 'Orange tabbie');
});
it('Compares by id', () => {
assert.strictEqual(
new (Entity.fromKeys(['id', 'x']))({ id: '123', x: 3 }).isEqual(
new (Entity.fromKeys(['id', 'x']))({ id: '123', x: 5 }),
),
true,
);
assert.strictEqual(
new (Entity.fromKeys(['id', 'x']))({ id: '123', x: 3 }).isEqual(
new (Entity.fromKeys(['id', 'x']))({ id: '321', x: 3 }),
),
false,
);
});
});
describe('Entity', () => {
const Cat = ValueObject.fromKeys(['name', 'age', 'color']);
const cat = new Cat({ name: 'Sanya', age: 3, color: 'Orange tabbie' });
it('Has correct properties', () => {
assert.strictEqual(cat.name, 'Sanya');
assert.strictEqual(cat.age, 3);
assert.strictEqual(cat.color, 'Orange tabbie');
});
it('Compares by each property', () => {
assert.strictEqual(
new (ValueObject.fromKeys(['x', 'y', 'z']))({
x: 1,
y: [1, 2, 3],
z: { a: 1, b: [2] },
}).isEqual(
new (ValueObject.fromKeys(['x', 'y', 'z']))({
x: 1,
y: [1, 2, 3],
z: { a: 1, b: [2] },
}),
),
true,
);
});
});