diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c11ea9d..d1b89af9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Change log +### Version: 3.25.3 +#### Date: April-21-2025 +##### Fix: + - Handle the sanity tests when ENVs are not provided. + ### Version: 3.25.2 #### Date: April-02-2025 ##### Fix: diff --git a/README.md b/README.md index e014e402..3471eda5 100755 --- a/README.md +++ b/README.md @@ -19,11 +19,11 @@ For browsers, we recommend to download the library via npm or yarn to ensure 100 If you'd like to use a standalone built file you can use the following script tag or download it from [jsDelivr](https://www.jsdelivr.com/package/npm/contentstack), under the `dist` directory: ```html - + ``` You can also specify a specific version number. ```html - + ``` To initialize the SDK, you will need to specify the API Key, Delivery Token, and Environment Name of your stack. diff --git a/jest.js.config.js b/jest.js.config.js index 26212a05..6bfd5308 100644 --- a/jest.js.config.js +++ b/jest.js.config.js @@ -7,7 +7,6 @@ module.exports = { "/test/config.js", "/test/sync_config.js", "/test/.*/utils.js", - "/test/sync/", ], reporters: ["default", ["jest-html-reporters", { diff --git a/package-lock.json b/package-lock.json index b9fd17b6..a0a94e0c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,18 @@ { "name": "contentstack", - "version": "3.25.2", + "version": "3.25.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "contentstack", - "version": "3.25.2", + "version": "3.25.3", "license": "MIT", "dependencies": { - "@contentstack/utils": "^1.3.18", - "@fetch-mock/jest": "^0.2.12", + "@contentstack/utils": "^1.3.20", + "@fetch-mock/jest": "^0.2.15", "es6-promise": "^4.2.8", - "fetch-mock": "^12.4.0", + "fetch-mock": "^12.5.2", "localStorage": "1.0.4", "qs": "^6.14.0" }, @@ -69,9 +69,9 @@ } }, "node_modules/@asamuzakjp/css-color": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@asamuzakjp/css-color/-/css-color-3.1.1.tgz", - "integrity": "sha512-hpRD68SV2OMcZCsrbdkccTw5FXjNDLo5OuqSHyHZfwweGsDWZwDJ2+gONyNAbazZclobMirACLw0lk8WVxIqxA==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@asamuzakjp/css-color/-/css-color-3.1.2.tgz", + "integrity": "sha512-nwgc7jPn3LpZ4JWsoHtuwBsad1qSSLDDX634DdG0PBJofIuIEtSWk4KkRmuXyu178tjuHAbwiMNNzwqIyLYxZw==", "dev": true, "license": "MIT", "dependencies": { @@ -2521,9 +2521,9 @@ } }, "node_modules/@types/babel__generator": { - "version": "7.6.8", - "resolved": "https://registry.npmjs.org/@types/babel__generator/-/babel__generator-7.6.8.tgz", - "integrity": "sha512-ASsj+tpEDsEiFr1arWrlN6V3mdfjRMZt6LtK/Vp/kreFLnr5QH5+DhvD5nINYZXzwJvXeGq+05iUXcAzVrqWtw==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@types/babel__generator/-/babel__generator-7.27.0.tgz", + "integrity": "sha512-ufFd2Xi92OAVPYsy+P4n7/U7e68fex0+Ee8gSG9KX7eo084CWiQ4sdxktvdl0bOPupXtVJPY19zk6EwWqUQ8lg==", "license": "MIT", "dependencies": { "@babel/types": "^7.0.0" @@ -2762,12 +2762,12 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "22.13.17", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.17.tgz", - "integrity": "sha512-nAJuQXoyPj04uLgu+obZcSmsfOenUg6DxPKogeUy6yNCFwWaj5sBF8/G/pNo8EtBJjAfSVgfIlugR/BCOleO+g==", + "version": "22.14.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.14.1.tgz", + "integrity": "sha512-u0HuPQwe/dHrItgHHpmw3N2fYCR6x4ivMNbPHRkBVP4CvN+kiRrKHWk3i8tXiO/joPwXLMYvF9TTF0eqgHIuOw==", "license": "MIT", "dependencies": { - "undici-types": "~6.20.0" + "undici-types": "~6.21.0" } }, "node_modules/@types/qs": { @@ -3741,9 +3741,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001707", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001707.tgz", - "integrity": "sha512-3qtRjw/HQSMlDWf+X79N206fepf4SOOU6SQLMaq/0KkZLmSjPxAkBOQQ+FxbHKfHmYLZFfdWsO3KA90ceHPSnw==", + "version": "1.0.30001713", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001713.tgz", + "integrity": "sha512-wCIWIg+A4Xr7NfhTuHdX+/FKh3+Op3LBbSp2N5Pfx6T/LhdQy3GTyoTg48BReaW/MyMNZAkTadsBtai3ldWK0Q==", "funding": [ { "type": "opencollective", @@ -4536,9 +4536,9 @@ } }, "node_modules/dotenv": { - "version": "16.4.7", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", - "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", + "version": "16.5.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.5.0.tgz", + "integrity": "sha512-m/C+AwOAr9/W1UOIZUo232ejMNnJAJtYQjUbHoNTBNTJSvqzzDh7vnrei3o3r3m9blf6ZoDkvcw0VmozNRFJxg==", "dev": true, "license": "BSD-2-Clause", "engines": { @@ -4616,9 +4616,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.129", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.129.tgz", - "integrity": "sha512-JlXUemX4s0+9f8mLqib/bHH8gOHf5elKS6KeWG3sk3xozb/JTq/RLXIv8OKUWiK4Ah00Wm88EFj5PYkFr4RUPA==", + "version": "1.5.137", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.137.tgz", + "integrity": "sha512-/QSJaU2JyIuTbbABAo/crOs+SuAZLS+fVVS10PVrIT9hrRkmZl8Hb0xPSkKRUUWHQtYzXHpQUW3Dy5hwMzGZkA==", "license": "ISC" }, "node_modules/emittery": { @@ -7555,16 +7555,15 @@ } }, "node_modules/jsdom": { - "version": "26.0.0", - "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-26.0.0.tgz", - "integrity": "sha512-BZYDGVAIriBWTpIxYzrXjv3E/4u8+/pSG5bQdIYCbNCGOvsPkDQfTVLAIXAf9ETdCpduCVTkDe2NNZ8NIwUVzw==", + "version": "26.1.0", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-26.1.0.tgz", + "integrity": "sha512-Cvc9WUhxSMEo4McES3P7oK3QaXldCfNWp7pl2NNeiIFlCoLr3kfq9kb1fxftiwk1FLV7CvpvDfonxtzUDeSOPg==", "dev": true, "license": "MIT", "dependencies": { "cssstyle": "^4.2.1", "data-urls": "^5.0.0", - "decimal.js": "^10.4.3", - "form-data": "^4.0.1", + "decimal.js": "^10.5.0", "html-encoding-sniffer": "^4.0.0", "http-proxy-agent": "^7.0.2", "https-proxy-agent": "^7.0.6", @@ -7574,12 +7573,12 @@ "rrweb-cssom": "^0.8.0", "saxes": "^6.0.0", "symbol-tree": "^3.2.4", - "tough-cookie": "^5.0.0", + "tough-cookie": "^5.1.1", "w3c-xmlserializer": "^5.0.0", "webidl-conversions": "^7.0.0", "whatwg-encoding": "^3.1.1", "whatwg-mimetype": "^4.0.0", - "whatwg-url": "^14.1.0", + "whatwg-url": "^14.1.1", "ws": "^8.18.0", "xml-name-validator": "^5.0.0" }, @@ -8376,9 +8375,9 @@ } }, "node_modules/nodemailer": { - "version": "6.10.0", - "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.10.0.tgz", - "integrity": "sha512-SQ3wZCExjeSatLE/HBaXS5vqUOQk6GtBdIIKxiFdmm01mOQZX/POJkO3SUX1wDiYcwUOJwT23scFSC9fY2H8IA==", + "version": "6.10.1", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.10.1.tgz", + "integrity": "sha512-Z+iLaBGVaSjbIzQ4pX6XV41HrooLsQ10ZWPUehGmuantvzWoDVBnmsdUcOIDM1t+yPor5pDhVlDESgOMEGxhHA==", "dev": true, "license": "MIT-0", "engines": { @@ -10566,22 +10565,22 @@ } }, "node_modules/tldts": { - "version": "6.1.85", - "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.85.tgz", - "integrity": "sha512-gBdZ1RjCSevRPFix/hpaUWeak2/RNUZB4/8frF1r5uYMHjFptkiT0JXIebWvgI/0ZHXvxaUDDJshiA0j6GdL3w==", + "version": "6.1.86", + "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.86.tgz", + "integrity": "sha512-WMi/OQ2axVTf/ykqCQgXiIct+mSQDFdH2fkwhPwgEwvJ1kSzZRiinb0zF2Xb8u4+OqPChmyI6MEu4EezNJz+FQ==", "dev": true, "license": "MIT", "dependencies": { - "tldts-core": "^6.1.85" + "tldts-core": "^6.1.86" }, "bin": { "tldts": "bin/cli.js" } }, "node_modules/tldts-core": { - "version": "6.1.85", - "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.85.tgz", - "integrity": "sha512-DTjUVvxckL1fIoPSb3KE7ISNtkWSawZdpfxGxwiIrZoO6EbHVDXXUIlIuWympPaeS+BLGyggozX/HTMsRAdsoA==", + "version": "6.1.86", + "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.86.tgz", + "integrity": "sha512-Je6p7pkk+KMzMv2XXKmAE3McmolOQFdxkKw0R8EYNr7sELW46JqnNeTX8ybPiQgvg1ymCoF8LXs5fzFaZvJPTA==", "dev": true, "license": "MIT" }, @@ -10640,9 +10639,9 @@ } }, "node_modules/ts-jest": { - "version": "29.3.1", - "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.3.1.tgz", - "integrity": "sha512-FT2PIRtZABwl6+ZCry8IY7JZ3xMuppsEV9qFVHOVe8jDzggwUZ9TsM4chyJxL9yi6LvkqcZYU3LmapEE454zBQ==", + "version": "29.3.2", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.3.2.tgz", + "integrity": "sha512-bJJkrWc6PjFVz5g2DGCNUo8z7oFEYaz1xP1NpeDU7KNLMWPpEyV8Chbpkn8xjzgRDpQhnGMyvyldoL7h8JXyug==", "dev": true, "license": "MIT", "dependencies": { @@ -10654,7 +10653,7 @@ "lodash.memoize": "^4.1.2", "make-error": "^1.3.6", "semver": "^7.7.1", - "type-fest": "^4.38.0", + "type-fest": "^4.39.1", "yargs-parser": "^21.1.1" }, "bin": { @@ -10703,9 +10702,9 @@ } }, "node_modules/ts-jest/node_modules/type-fest": { - "version": "4.39.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.39.0.tgz", - "integrity": "sha512-w2IGJU1tIgcrepg9ZJ82d8UmItNQtOFJG0HCUE3SzMokKkTsruVDALl2fAdiEzJlfduoU+VyXJWIIUZ+6jV+nw==", + "version": "4.40.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.40.0.tgz", + "integrity": "sha512-ABHZ2/tS2JkvH1PEjxFDTUWC8dB5OsIGZP4IFLhR293GqT5Y5qB1WwL2kMPYhQW9DVgVD8Hd7I8gjwPIf5GFkw==", "dev": true, "license": "(MIT OR CC0-1.0)", "engines": { @@ -10900,9 +10899,9 @@ "license": "MIT" }, "node_modules/undici-types": { - "version": "6.20.0", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", - "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==", + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", "license": "MIT" }, "node_modules/unicode-canonical-property-names-ecmascript": { @@ -11087,9 +11086,9 @@ } }, "node_modules/webpack": { - "version": "5.98.0", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.98.0.tgz", - "integrity": "sha512-UFynvx+gM44Gv9qFgj0acCQK2VE1CtdfwFdimkapco3hlPCJ/zeq73n2yVKimVbtm+TnApIugGhLJnkU6gjYXA==", + "version": "5.99.5", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.99.5.tgz", + "integrity": "sha512-q+vHBa6H9qwBLUlHL4Y7L0L1/LlyBKZtS9FHNCQmtayxjI5RKC9yD8gpvLeqGv5lCQp1Re04yi0MF40pf30Pvg==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index a3427ed2..e6437a8c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "contentstack", - "version": "3.25.2", + "version": "3.25.3", "description": "Contentstack Javascript SDK", "homepage": "https://www.contentstack.com/", "author": { @@ -100,10 +100,10 @@ "webpack-node-externals": "^3.0.0" }, "dependencies": { - "@contentstack/utils": "^1.3.18", - "@fetch-mock/jest": "^0.2.12", + "@contentstack/utils": "^1.3.20", + "@fetch-mock/jest": "^0.2.15", "es6-promise": "^4.2.8", - "fetch-mock": "^12.4.0", + "fetch-mock": "^12.5.2", "localStorage": "1.0.4", "qs": "^6.14.0" } diff --git a/test/config.js b/test/config.js index 69c45db8..0cea9c0c 100755 --- a/test/config.js +++ b/test/config.js @@ -1,5 +1,15 @@ 'use strict'; -require('dotenv').config() +require('dotenv').config(); + +const requiredVars = ['HOST', 'API_KEY', 'DELIVERY_TOKEN', 'ENVIRONMENT']; +const missingVars = requiredVars.filter((key) => !process.env[key]); + +if (missingVars.length > 0) { + const errorMessage = `\x1b[31mError: Missing environment variables - ${missingVars.join(', ')}`; + const error = new Error(errorMessage); + error.stack = error.message; + throw error; +} module.exports = { stack: { 'api_key': process.env.API_KEY, 'delivery_token': process.env.DELIVERY_TOKEN, 'environment': process.env.ENVIRONMENT, }, diff --git a/test/index.js b/test/index.js index cd96d6b2..91d6debf 100755 --- a/test/index.js +++ b/test/index.js @@ -5,7 +5,7 @@ require('./entry/findone'); require('./entry/findone-result-wrapper'); require('./entry/spread'); -//require('./sync/sync-testcases'); +require('./sync/sync-testcases'); // Assets require('./asset/find'); diff --git a/test/live-preview/live-preview-test.js b/test/live-preview/live-preview-test.js index 4ffc93e2..808e75d2 100644 --- a/test/live-preview/live-preview-test.js +++ b/test/live-preview/live-preview-test.js @@ -1,11 +1,13 @@ 'use strict'; +const init = require("../config.js"); const Contentstack = require('../../dist/node/contentstack.js'); describe('Contentstack Live Preview Tests', () => { test('should check for values initialized', () => { + const stack1 = Contentstack.Stack(init.stack) const stack = Contentstack.Stack({ - 'api_key': process.env.region_API_KEY, + 'api_key': process.env.API_KEY, 'delivery_token': process.env.DELIVERY_TOKEN, 'environment': process.env.ENVIRONMENT }); @@ -16,15 +18,10 @@ describe('Contentstack Live Preview Tests', () => { }); test('should check host when live preview is enabled and management token is provided', () => { - const stack = Contentstack.Stack({ - 'api_key': process.env.API_KEY, - 'delivery_token': process.env.DELIVERY_TOKEN, - 'environment': process.env.ENVIRONMENT, - live_preview: { - enable: true, - management_token: 'management_token' - } - }); + init.stack.live_preview = init.stack.live_preview || {}; + init.stack.live_preview.enable = true; + init.stack.live_preview.management_token = 'management_token'; + const stack = Contentstack.Stack(init.stack); const livePreviewObject = stack.config.live_preview; expect(livePreviewObject).not.toBe('undefined'); @@ -34,15 +31,9 @@ describe('Contentstack Live Preview Tests', () => { }); test('should check host when live preview is disabled and management token is provided', () => { - const stack = Contentstack.Stack({ - 'api_key': process.env.API_KEY, - 'delivery_token': process.env.DELIVERY_TOKEN, - 'environment': process.env.ENVIRONMENT, - live_preview: { - enable: false, - management_token: 'management_token' - } - }); + init.stack.live_preview.enable = false; + init.stack.live_preview.management_token = 'management_token'; + const stack = Contentstack.Stack(init.stack); const livePreviewObject = stack.config.live_preview; expect(livePreviewObject).not.toBe('undefined'); @@ -51,15 +42,9 @@ describe('Contentstack Live Preview Tests', () => { }); test('should check host when live preview is enabled and preview token is provided', () => { - const stack = Contentstack.Stack({ - 'api_key': process.env.API_KEY, - 'delivery_token': process.env.DELIVERY_TOKEN, - 'environment': process.env.ENVIRONMENT, - live_preview: { - enable: true, - preview_token: 'preview_token' - } - }); + init.stack.live_preview.enable = true; + init.stack.live_preview.preview_token = 'preview_token'; + const stack = Contentstack.Stack(init.stack); const livePreviewObject = stack.config.live_preview; expect(livePreviewObject).not.toBe('undefined'); @@ -70,15 +55,9 @@ describe('Contentstack Live Preview Tests', () => { }); test('should check host when live preview is disabled and preview token is provided', () => { - const stack = Contentstack.Stack({ - 'api_key': process.env.API_KEY, - 'delivery_token': process.env.DELIVERY_TOKEN, - 'environment': process.env.ENVIRONMENT, - live_preview: { - enable: false, - preview_token: 'preview_token' - } - }); + init.stack.live_preview.enable = false; + init.stack.live_preview.preview_token = 'preview_token'; + const stack = Contentstack.Stack(init.stack); const livePreviewObject = stack.config.live_preview; expect(livePreviewObject).not.toBe('undefined'); diff --git a/test/sync/sync-testcases.js b/test/sync/sync-testcases.js index 70480e68..3655e5cd 100755 --- a/test/sync/sync-testcases.js +++ b/test/sync/sync-testcases.js @@ -1,108 +1,108 @@ -'use strict'; +"use strict"; /* * Module Dependencies. */ -const sync_testcase = require('tape'); -const Contentstack = require('../../dist/node/contentstack.js'); -const init = require('../sync_config.js'); +const Contentstack = require("../../dist/node/contentstack.js"); +const init = require("../config.js"); + let Stack; let sync_token = ""; -var total_count = 123; var pagination_token = ""; - -/* - * Initalise the Contentstack Instance - * */ -sync_testcase('Initalise the Contentstack Stack Instance', function(TC) { - setTimeout(function() { - Stack = Contentstack.Stack(init.stack); - Stack.setHost(init.host); - TC.end(); - }, 1000); -}); - -sync_testcase('default .Init()', function(assert) { - Stack - .sync({"init" : true}) - .then(function success(data) { - assert.equal(data.total_count, total_count, "Present Data and Totalcount is equal"); - assert.end(); - }); -}); - -sync_testcase('default .startdate()', function(assert) { - var date_entry_count = 7 - Stack - .sync({"init": true, "start_from": "2018-10-22"}) - .then(function success(data) { - assert.equal(data.total_count, date_entry_count, "Present data and filtered data count on date bases is equal"); - assert.end(); - }); -}); - - -sync_testcase('default .locale()', function(assert) { - var locale_entry_count = 123; - Stack - .sync({"init": "true", "locale": "en-us"}) - .then(function success(data) { - assert.equal(data.total_count, locale_entry_count, "Present data and filtered data count on locale bases is equal"); - assert.end(); - }); -}); - -sync_testcase('default .localeDate()', function(assert) { - var locale_date_entry_count = 7; - Stack - .sync({"init": true, "locale": "en-us", "start_from": "2018-10-22"}) - .then(function success(data) { - assert.equal(data.total_count, locale_date_entry_count, "Present data and filtered data count on date and locale bases is equal"); - assert.end(); - }); -}); - - -sync_testcase('default .pagination_token()', function(assert) { - - Stack - .sync({"pagination_token" : pagination_token}) - .then(function success(result) { - let pagination_count = result.items.length - assert.equal(pagination_count, 23, "pagination_token testcase executed successfully"); - assert.end(); - }); -}); - - -sync_testcase('default .contentTypeUid()', function(assert) { - Stack - .sync({"init": true, "content_type_uid": "session"}) - .then(function success(data) { - assert.equal(data.total_count, 31, "Present data and filtered data total count on contentType bases is equal"); - assert.end(); - }); -}); - -sync_testcase('default .type()', function(assert) { - var items_count = 8; - Stack - .sync({"init": true, "type": "asset_published"}) - .then(function success(data) { - assert.equal(data.total_count, items_count, "Present data and filtered data total count on type bases is equal"); - assert.end(); - }); -}); - -sync_testcase('default .sync_token()', function(assert) { - var sync_expected_count = 7 - - Stack - .sync({"sync_token" : sync_token}) - .then(function success(result) { - assert.equal(result.total_count, sync_expected_count, "Synced Data and Sync_total_count is equal"); - assert.end(); - }); +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(); + }); + }); });