|
1 | | -'use strict'; |
| 1 | +"use strict"; |
2 | 2 | /* |
3 | 3 | * Module Dependencies. |
4 | 4 | */ |
5 | | -const sync_testcase = require('tape'); |
6 | | -const Contentstack = require('../../dist/node/contentstack.js'); |
7 | | -const init = require('../sync_config.js'); |
| 5 | +const Contentstack = require("../../dist/node/contentstack.js"); |
| 6 | +const init = require("../sync_config.js"); |
8 | 7 |
|
9 | 8 | let Stack; |
10 | 9 | let sync_token = ""; |
11 | | -var total_count = 123; |
12 | 10 | var pagination_token = ""; |
13 | 11 |
|
14 | | - |
15 | | -/* |
16 | | - * Initalise the Contentstack Instance |
17 | | - * */ |
18 | | -sync_testcase('Initalise the Contentstack Stack Instance', function(TC) { |
19 | | - setTimeout(function() { |
20 | | - Stack = Contentstack.Stack(init.stack); |
21 | | - Stack.setHost(init.host); |
22 | | - TC.end(); |
23 | | - }, 1000); |
24 | | -}); |
25 | | - |
26 | | -sync_testcase('default .Init()', function(assert) { |
27 | | - Stack |
28 | | - .sync({"init" : true}) |
29 | | - .then(function success(data) { |
30 | | - assert.equal(data.total_count, total_count, "Present Data and Totalcount is equal"); |
31 | | - assert.end(); |
32 | | - }); |
33 | | -}); |
34 | | - |
35 | | -sync_testcase('default .startdate()', function(assert) { |
36 | | - var date_entry_count = 7 |
37 | | - Stack |
38 | | - .sync({"init": true, "start_from": "2018-10-22"}) |
39 | | - .then(function success(data) { |
40 | | - assert.equal(data.total_count, date_entry_count, "Present data and filtered data count on date bases is equal"); |
41 | | - assert.end(); |
42 | | - }); |
43 | | -}); |
44 | | - |
45 | | - |
46 | | -sync_testcase('default .locale()', function(assert) { |
47 | | - var locale_entry_count = 123; |
48 | | - Stack |
49 | | - .sync({"init": "true", "locale": "en-us"}) |
50 | | - .then(function success(data) { |
51 | | - assert.equal(data.total_count, locale_entry_count, "Present data and filtered data count on locale bases is equal"); |
52 | | - assert.end(); |
53 | | - }); |
54 | | -}); |
55 | | - |
56 | | -sync_testcase('default .localeDate()', function(assert) { |
57 | | - var locale_date_entry_count = 7; |
58 | | - Stack |
59 | | - .sync({"init": true, "locale": "en-us", "start_from": "2018-10-22"}) |
60 | | - .then(function success(data) { |
61 | | - assert.equal(data.total_count, locale_date_entry_count, "Present data and filtered data count on date and locale bases is equal"); |
62 | | - assert.end(); |
63 | | - }); |
64 | | -}); |
65 | | - |
66 | | - |
67 | | -sync_testcase('default .pagination_token()', function(assert) { |
68 | | - |
69 | | - Stack |
70 | | - .sync({"pagination_token" : pagination_token}) |
71 | | - .then(function success(result) { |
72 | | - let pagination_count = result.items.length |
73 | | - assert.equal(pagination_count, 23, "pagination_token testcase executed successfully"); |
74 | | - assert.end(); |
75 | | - }); |
76 | | -}); |
77 | | - |
78 | | - |
79 | | -sync_testcase('default .contentTypeUid()', function(assert) { |
80 | | - Stack |
81 | | - .sync({"init": true, "content_type_uid": "session"}) |
82 | | - .then(function success(data) { |
83 | | - assert.equal(data.total_count, 31, "Present data and filtered data total count on contentType bases is equal"); |
84 | | - assert.end(); |
85 | | - }); |
86 | | -}); |
87 | | - |
88 | | -sync_testcase('default .type()', function(assert) { |
89 | | - var items_count = 8; |
90 | | - Stack |
91 | | - .sync({"init": true, "type": "asset_published"}) |
92 | | - .then(function success(data) { |
93 | | - assert.equal(data.total_count, items_count, "Present data and filtered data total count on type bases is equal"); |
94 | | - assert.end(); |
95 | | - }); |
96 | | -}); |
97 | | - |
98 | | -sync_testcase('default .sync_token()', function(assert) { |
99 | | - var sync_expected_count = 7 |
100 | | - |
101 | | - Stack |
102 | | - .sync({"sync_token" : sync_token}) |
103 | | - .then(function success(result) { |
104 | | - assert.equal(result.total_count, sync_expected_count, "Synced Data and Sync_total_count is equal"); |
105 | | - assert.end(); |
106 | | - }); |
| 12 | +describe("ContentStack SDK Sync Tests", () => { |
| 13 | + // Initialize the Contentstack Stack Instance |
| 14 | + beforeAll(() => { |
| 15 | + return new Promise((resolve) => { |
| 16 | + // Initialize Stack with proper configuration |
| 17 | + Stack = Contentstack.Stack({ |
| 18 | + api_key: init.stack.api_key, |
| 19 | + delivery_token: init.stack.access_token, |
| 20 | + environment: init.stack.environment, |
| 21 | + fetchOptions: init.stack.fetchOptions |
| 22 | + }); |
| 23 | + Stack.setHost(init.host); |
| 24 | + setTimeout(resolve, 1000); |
| 25 | + }); |
| 26 | + }); |
| 27 | + |
| 28 | + describe("default .Init()", () => { |
| 29 | + test("should initialize sync with correct total count", async () => { |
| 30 | + const data = await Stack.sync({ init: true }); |
| 31 | + expect(data.total_count).toBeDefined(); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + describe("default .startdate()", () => { |
| 36 | + test("should filter entries by start date", async () => { |
| 37 | + const data = await Stack.sync({ |
| 38 | + init: "true", |
| 39 | + start_from: "2018-10-22T00:00:00.000Z" |
| 40 | + }); |
| 41 | + expect(data.total_count).toBeDefined(); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + describe("default .locale()", () => { |
| 46 | + test("should filter entries by locale", async () => { |
| 47 | + const data = await Stack.sync({ |
| 48 | + init: "true", |
| 49 | + locale: "en-us" |
| 50 | + }); |
| 51 | + expect(data.total_count).toBeDefined(); |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + describe("default .localeDate()", () => { |
| 56 | + test("should filter entries by locale and date", async () => { |
| 57 | + const data = await Stack.sync({ |
| 58 | + init: "true", |
| 59 | + locale: "en-us", |
| 60 | + start_from: "2018-10-22T00:00:00.000Z" |
| 61 | + }); |
| 62 | + expect(data.total_count).toBeDefined(); |
| 63 | + }); |
| 64 | + }); |
| 65 | + |
| 66 | + describe("default .pagination_token()", () => { |
| 67 | + test("should handle pagination correctly", async () => { |
| 68 | + // First get a valid pagination token |
| 69 | + const initialData = await Stack.sync({ init: "true" }); |
| 70 | + pagination_token = initialData.pagination_token; |
| 71 | + |
| 72 | + const result = await Stack.sync({ pagination_token }); |
| 73 | + expect(result.items.length).toBeDefined(); |
| 74 | + }); |
| 75 | + }); |
| 76 | + |
| 77 | + describe("default .contentTypeUid()", () => { |
| 78 | + test("should filter entries by content type", async () => { |
| 79 | + const data = await Stack.sync({ |
| 80 | + init: "true", |
| 81 | + content_type_uid: "source" |
| 82 | + }); |
| 83 | + expect(data.total_count).toBeDefined(); |
| 84 | + }); |
| 85 | + }); |
| 86 | + |
| 87 | + describe("default .type()", () => { |
| 88 | + test("should filter entries by type", async () => { |
| 89 | + const data = await Stack.sync({ |
| 90 | + init: "true", |
| 91 | + type: "asset_published" |
| 92 | + }); |
| 93 | + expect(data.total_count).toBeDefined(); |
| 94 | + }); |
| 95 | + }); |
| 96 | + |
| 97 | + describe("default .sync_token()", () => { |
| 98 | + test("should handle sync token correctly", async () => { |
| 99 | + // First get a valid sync token |
| 100 | + const initialData = await Stack.sync({ init: "true" }); |
| 101 | + sync_token = initialData.sync_token; |
| 102 | + |
| 103 | + const result = await Stack.sync({ sync_token }); |
| 104 | + expect(result.total_count).toBeDefined(); |
| 105 | + }); |
| 106 | + }); |
107 | 107 | }); |
108 | 108 |
|
0 commit comments