-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap-sync.test.ts
50 lines (39 loc) · 1.61 KB
/
map-sync.test.ts
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
import { GraphSynchronizer, IGraphSyncOptions } from '@ablestack/rdo';
import { Logger } from '@ablestack/rdo/infrastructure/logger';
const logger = Logger.make('map-sync.test.ts');
// --------------------------------------------------------------
// CONFIG
// --------------------------------------------------------------
const config: IGraphSyncOptions = {
targetedNodeOptions: [{ sourceNodeMatcher: { nodePath: 'collectionOfBar' }, makeRdo: (sourceNode: Bar) => new BarRDO() }],
};
// --------------------------------------------------------------
// TEST
// --------------------------------------------------------------
test('Collection usage demo', () => {
const fooRDO = new FooDomainGraphWithCollection();
const graphSynchronizer = new GraphSynchronizer(config);
// EXECUTE
graphSynchronizer.smartSync({ rootRdo: fooRDO, rootSourceNode: fooSourceJSONWithCollection });
// RESULTS VERIFICATION
expect(fooRDO.collectionOfBar.size).toEqual(fooSourceJSONWithCollection.collectionOfBar.length);
expect(fooRDO.collectionOfBar.values().next().value.id).toEqual(fooSourceJSONWithCollection.collectionOfBar[0].id);
});
// --------------------------------------------------------------
// MODELS & DATA
// --------------------------------------------------------------
//
// Source Data Models
type Bar = { id: string; name: string };
//
// Source Data
const fooSourceJSONWithCollection = { collectionOfBar: [{ id: 'bar-1', name: 'Bar 1' }] };
//
// RDO Graphs
class FooDomainGraphWithCollection {
public collectionOfBar = new Map<string, BarRDO>();
}
class BarRDO {
public id: string = '';
public name: string = '';
}