-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathsync-testcases.js
More file actions
executable file
·106 lines (94 loc) · 3.08 KB
/
sync-testcases.js
File metadata and controls
executable file
·106 lines (94 loc) · 3.08 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
94
95
96
97
98
99
100
101
102
103
104
105
106
'use strict';
/*
* Module Dependencies.
*/
const Contentstack = require('../../dist/node/contentstack.js');
const init = require('../config.js');
let Stack;
let sync_token = '';
let pagination_token = '';
describe('ContentStack SDK Sync Tests', () => {
// Initialize the Contentstack Stack Instance
beforeAll(() => {
return new Promise((resolve) => {
// Initialize Stack with proper configuration
Stack = Contentstack.Stack(init.stack);
Stack.setHost(init.host);
setTimeout(resolve, 1000);
});
});
describe('default .Init()', () => {
test('should initialize sync with correct total count', async () => {
const data = await Stack.sync({ init: true });
expect(data.total_count).toBeDefined();
});
});
describe('default .startdate()', () => {
test('should filter entries by start date', async () => {
const data = await Stack.sync({
init: 'true',
start_from: '2018-10-22T00:00:00.000Z'
});
expect(data.total_count).toBeDefined();
});
});
describe('default .locale()', () => {
test('should filter entries by locale', async () => {
const data = await Stack.sync({
init: 'true',
locale: 'en-us'
});
expect(data.total_count).toBeDefined();
});
});
describe('default .localeDate()', () => {
test('should filter entries by locale and date', async () => {
const data = await Stack.sync({
init: 'true',
locale: 'en-us',
start_from: '2018-10-22T00:00:00.000Z'
});
expect(data.total_count).toBeDefined();
});
});
describe('default .pagination_token()', () => {
test('should handle pagination correctly', async () => {
// This works only when it contains more than 100 records else sync token will be generated
const initialData = await Stack.sync({ init: 'true' });
pagination_token = initialData.pagination_token;
expect(pagination_token).toBeUndefined();
try {
await Stack.sync({ pagination_token });
} catch (error) {
expect(error.message).toBe('Invalid parameter value for key "pagination_token": must be a string, number, object, boolean, or RegExp.');
}
});
});
describe('default .contentTypeUid()', () => {
test('should filter entries by content type', async () => {
const data = await Stack.sync({
init: 'true',
content_type_uid: 'source'
});
expect(data.total_count).toBeDefined();
});
});
describe('default .type()', () => {
test('should filter entries by type', async () => {
const data = await Stack.sync({
init: 'true',
type: 'asset_published'
});
expect(data.total_count).toBeDefined();
});
});
describe('default .sync_token()', () => {
test('should handle sync token correctly', async () => {
// First get a valid sync token
const initialData = await Stack.sync({ init: 'true' });
sync_token = initialData.sync_token;
const result = await Stack.sync({ sync_token });
expect(result.total_count).toBeDefined();
});
});
});