-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig-type-matcher-sync.test.ts
52 lines (39 loc) · 1.85 KB
/
config-type-matcher-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
import { GraphSynchronizer, IGraphSyncOptions } from '@ablestack/rdo';
import { Logger } from '@ablestack/rdo/infrastructure/logger';
import { LibraryRDO, BookRDO } 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('flat-object-sync.test.ts');
// --------------------------------------------------------------
// CONFIG
// --------------------------------------------------------------
const config: IGraphSyncOptions = {
targetedNodeOptions: [{ sourceNodeMatcher: { nodeContent: (node) => node && node.__type === 'Book' }, makeRdo: (book: Book) => new BookRDO() }],
globalNodeOptions: { commonRdoFieldnamePostfix: '$' },
};
// --------------------------------------------------------------
// TEST
// --------------------------------------------------------------
test('Synchronize using sourceNodeMatcher config', () => {
const libraryRDO = new LibraryRDO();
const graphSynchronizer = new GraphSynchronizer(config);
// POSTURE VERIFICATION
expect(libraryRDO.authors.size).toBeFalsy();
// EXECUTE
graphSynchronizer.smartSync({ rootRdo: libraryRDO, rootSourceNode: librarySourceJSON });
// RESULTS VERIFICATION
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);
});
// --------------------------------------------------------------
// 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