-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathsync.service.spec.ts
More file actions
93 lines (82 loc) · 4.32 KB
/
Copy pathsync.service.spec.ts
File metadata and controls
93 lines (82 loc) · 4.32 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { ContentItem, Hub, Job } from 'dc-management-sdk-js';
import { ContentItemSyncService } from './sync.service';
const createMockHub = (id: string) => {
return { ...new Hub({ id }), ...{ related: { jobs: { createDeepSyncJob: jest.fn(), get: jest.fn() } } } };
};
describe('sync.service', () => {
beforeEach(() => {
jest.clearAllMocks();
});
describe('ContentItemSyncService', () => {
describe('sync', () => {
it('should add a content item sync job to the queue and process the queue item (with sync options enabled)', async () => {
const JOB_ID = '68e5289f0aba3024bde050f9';
const DEST_HUB_ID = '67d2a201642fa239dbe1523d';
const CONTENT_ITEM_ID = 'c5b659df-680e-4711-bfbe-84eaa10d76cc';
const contentItem = new ContentItem({ id: CONTENT_ITEM_ID, label: 'sync service test' });
const hub = createMockHub(CONTENT_ITEM_ID);
hub.related.jobs.createDeepSyncJob.mockResolvedValue(new Job({ jobId: JOB_ID }));
hub.related.jobs.get.mockResolvedValue(new Job({ id: JOB_ID, status: 'COMPLETED' }));
const syncService = new ContentItemSyncService();
syncService.sync(DEST_HUB_ID, hub as unknown as Hub, contentItem, () => {}, {
ignoreSchemaValidation: true,
forceSync: true
});
await syncService.onIdle();
expect(hub.related.jobs.createDeepSyncJob).toHaveBeenCalledWith({
label: `dc-cli content item: sync service test`,
forceSync: true,
ignoreSchemaValidation: true,
destinationHubId: DEST_HUB_ID,
input: { rootContentItemIds: [CONTENT_ITEM_ID] }
});
expect(hub.related.jobs.get).toHaveBeenNthCalledWith(1, JOB_ID);
expect(syncService.failedJobs.length).toEqual(0);
});
it('should add a content item sync job to the queue, process and wait for a completed job', async () => {
const JOB_ID = '68e5289f0aba3024bde050f9';
const DEST_HUB_ID = '67d2a201642fa239dbe1523d';
const CONTENT_ITEM_ID = 'c5b659df-680e-4711-bfbe-84eaa10d76cc';
const contentItem = new ContentItem({ id: CONTENT_ITEM_ID, label: 'sync service test' });
const hub = createMockHub(CONTENT_ITEM_ID);
hub.related.jobs.createDeepSyncJob.mockResolvedValue(new Job({ jobId: JOB_ID }));
hub.related.jobs.get
.mockResolvedValueOnce(new Job({ id: JOB_ID, status: 'IN_PROGRESS' }))
.mockResolvedValueOnce(new Job({ id: JOB_ID, status: 'COMPLETED' }));
const syncService = new ContentItemSyncService();
syncService.sync(DEST_HUB_ID, hub as unknown as Hub, contentItem, () => {}, {});
await syncService.onIdle();
expect(hub.related.jobs.createDeepSyncJob).toHaveBeenCalledWith({
label: `dc-cli content item: sync service test`,
forceSync: false,
ignoreSchemaValidation: true,
destinationHubId: DEST_HUB_ID,
input: { rootContentItemIds: [CONTENT_ITEM_ID] }
});
expect(hub.related.jobs.get).toHaveBeenNthCalledWith(2, JOB_ID);
expect(syncService.failedJobs.length).toEqual(0);
});
it('should add a content item sync job to the queue, process and store a failed job', async () => {
const JOB_ID = '68e5289f0aba3024bde050f9';
const DEST_HUB_ID = '67d2a201642fa239dbe1523d';
const CONTENT_ITEM_ID = 'c5b659df-680e-4711-bfbe-84eaa10d76cc';
const contentItem = new ContentItem({ id: CONTENT_ITEM_ID, label: 'sync service test' });
const hub = createMockHub(CONTENT_ITEM_ID);
hub.related.jobs.createDeepSyncJob.mockResolvedValue(new Job({ jobId: JOB_ID }));
hub.related.jobs.get.mockResolvedValueOnce(new Job({ id: JOB_ID, status: 'FAILED' }));
const syncService = new ContentItemSyncService();
syncService.sync(DEST_HUB_ID, hub as unknown as Hub, contentItem, () => {}, {});
await syncService.onIdle();
expect(hub.related.jobs.createDeepSyncJob).toHaveBeenCalledWith({
label: `dc-cli content item: sync service test`,
forceSync: false,
ignoreSchemaValidation: true,
destinationHubId: DEST_HUB_ID,
input: { rootContentItemIds: [CONTENT_ITEM_ID] }
});
expect(hub.related.jobs.get).toHaveBeenNthCalledWith(1, JOB_ID);
expect(syncService.failedJobs.length).toEqual(1);
});
});
});
});