-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplex-graph-sync.test.ts
75 lines (57 loc) · 3.18 KB
/
complex-graph-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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { GraphSynchronizer, IGraphSyncOptions } from '@ablestack/rdo';
import { Logger } from '@ablestack/rdo/infrastructure/logger';
import { BookRDO, LibraryRDO } from './supporting-files/library-rdo-models';
import { librarySourceJSON } from './supporting-files/library-source-data';
import { Book } from './supporting-files/library-source-models';
const logger = Logger.make('map-sync.test.ts');
// --------------------------------------------------------------
// CONFIG
// --------------------------------------------------------------
const config: IGraphSyncOptions = {
targetedNodeOptions: [{ sourceNodeMatcher: { nodePath: 'authors/books' }, makeRdo: (book: Book) => new BookRDO() }],
globalNodeOptions: { commonRdoFieldnamePostfix: '$' },
};
// --------------------------------------------------------------
// TEST
// --------------------------------------------------------------
test('Synchronize updates complex graph as expected', () => {
const libraryRDO = new LibraryRDO();
const graphSynchronizer = new GraphSynchronizer(config);
// POSTURE VERIFICATION
expect(libraryRDO.name).toBeFalsy();
expect(libraryRDO.city$).toBeFalsy();
expect(libraryRDO.authors.size).toBeFalsy();
// EXECUTE
graphSynchronizer.smartSync({ rootRdo: libraryRDO, rootSourceNode: librarySourceJSON });
// console.log(`librarySourceJSON.authors`, JSON.stringify(librarySourceJSON.authors[0].books, null, 2));
// console.log(` ------------------------------------------- `);
// console.log(`libraryRDO.authors.array$`, JSON.stringify(libraryRDO.authors.array$[0].books, null, 2));
// RESULTS VERIFICATION
expect(libraryRDO.name).not.toBeFalsy();
expect(libraryRDO.city$).not.toBeFalsy();
expect(libraryRDO.authors.size).not.toBeFalsy();
expect(libraryRDO.name).toEqual(librarySourceJSON.name);
expect(libraryRDO.city$).toEqual(librarySourceJSON.city);
expect(libraryRDO.authors.size).toEqual(librarySourceJSON.authors.length);
expect(libraryRDO.authors.array$[0].id).toEqual(librarySourceJSON.authors[0].id);
expect(libraryRDO.authors.array$[0].name$).toEqual(librarySourceJSON.authors[0].name);
expect(libraryRDO.authors.array$[0].age$).toEqual(librarySourceJSON.authors[0].age);
expect(libraryRDO.authors.array$[0].books.length).toEqual(librarySourceJSON.authors[0].books.length);
expect(libraryRDO.authors.array$[0].books[0].id).toEqual(librarySourceJSON.authors[0].books[0].id);
expect(libraryRDO.authors.array$[0].books[0].title$).toEqual(librarySourceJSON.authors[0].books[0].title);
expect(libraryRDO.authors.array$[0].books[0].publisher).toBeDefined();
expect(libraryRDO.authors.array$[0].books[0].publisher.id).toEqual(librarySourceJSON.authors[0].books[0].publisher.id);
expect(libraryRDO.authors.array$[0].books[0].publisher.name$).toEqual(librarySourceJSON.authors[0].books[0].publisher.name);
});
// --------------------------------------------------------------
// MODELS & DATA
// --------------------------------------------------------------
//
// Source Data Models
// Imported from ./supporting-files/library-source-models
//
// Source Data
// Imported from ./supporting-files/library-source-data
//
// RDO Graphs
// Imported from ./supporting-files/library-rdo-models.ts