diff --git a/package-lock.json b/package-lock.json index 6f1591a..d7f60b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@agility/content-fetch", - "version": "0.6.2", + "version": "0.7.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2550,7 +2550,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -2571,12 +2572,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2591,17 +2594,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -2718,7 +2724,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -2730,6 +2737,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2744,6 +2752,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2751,12 +2760,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -2775,6 +2786,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2855,7 +2867,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -2867,6 +2880,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2952,7 +2966,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -2988,6 +3003,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -3007,6 +3023,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -3050,12 +3067,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, diff --git a/src/methods/syncContentItems.js b/src/methods/syncContentItems.js index ebaed9d..4e8e163 100644 --- a/src/methods/syncContentItems.js +++ b/src/methods/syncContentItems.js @@ -4,7 +4,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils' * Sync content based on the most recent version id that has been synced. * @memberof AgilityFetch.Client * @param {Object} requestParams - The paramters for the API request. - * @param {number} requestParams.maxVersionID - The most recent versionID of a synced content item in this language. + * @param {number} requestParams.ticks - The ticks value from the most recently synced content item in this language. * @param {string} requestParams.languageCode - The language code of the content you want to retrieve. * @param {number} [requestParams.pageSize] - The number of items to return back with each call. Default is 1000. * @returns {Promise<{Array.}>} - Returns a list of content item objects. @@ -14,7 +14,7 @@ function syncContentItems(requestParams) { validateRequestParams(requestParams); const req = { - url: `/sync/items?pageSize=${requestParams.pageSize}&maxVersionID=${requestParams.maxVersionID}`, + url: `/sync/items?pageSize=${requestParams.pageSize}&ticks=${requestParams.ticks}`, method: 'get', baseURL: buildRequestUrlPath(this.config, requestParams.languageCode), headers: buildAuthHeader(this.config), @@ -28,8 +28,8 @@ function validateRequestParams(requestParams) { if (!requestParams.languageCode) { throw new TypeError('You must include a languageCode in your request params.') } - else if (requestParams.maxVersionID == undefined || requestParams.maxVersionID == null) { - throw new TypeError('You must include a maxVersionID your request params. Use zero (0) to start a new sync.'); + else if (requestParams.ticks == undefined || requestParams.ticks == null) { + throw new TypeError('You must include a ticks value your request params. Use zero (0) to start a new sync.'); } else { return; } diff --git a/src/methods/syncPageItems.js b/src/methods/syncPageItems.js index 08034a3..0c336d7 100644 --- a/src/methods/syncPageItems.js +++ b/src/methods/syncPageItems.js @@ -4,7 +4,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils' * Sync content based on the most recent version id that has been synced. * @memberof AgilityFetch.Client * @param {Object} requestParams - The paramters for the API request. - * @param {number} requestParams.maxVersionID - The most recent versionID of the synced pages. + * @param {number} requestParams.ticks - The most recent ticks value of the synced pages. * @param {string} requestParams.languageCode - The language code of the content you want to retrieve. * @param {number} [requestParams.pageSize] - The number of items to return back with each call. Default is 1000. * @returns {Promise<{Array.}>} - Returns a list of content item objects. @@ -14,7 +14,7 @@ function syncPageItems(requestParams) { validateRequestParams(requestParams); const req = { - url: `/sync/items?pageSize=${requestParams.pageSize}&maxVersionID=${requestParams.maxVersionID}`, + url: `/sync/pages?pageSize=${requestParams.pageSize}&ticks=${requestParams.ticks}`, method: 'get', baseURL: buildRequestUrlPath(this.config, requestParams.languageCode), headers: buildAuthHeader(this.config), @@ -28,8 +28,8 @@ function validateRequestParams(requestParams) { if (!requestParams.languageCode) { throw new TypeError('You must include a languageCode in your request params.') } - else if (!requestParams.maxVersionID) { - throw new TypeError('You must include a maxVersionID your request params. Use zero (0) to start a new sync.'); + else if (requestParams.ticks == undefined || requestParams.ticks == null) { + throw new TypeError('You must include a ticks value your request params. Use zero (0) to start a new sync.'); } else { return; } diff --git a/test/syncContentItems.tests.js b/test/syncContentItems.tests.js index 3137187..366dbbf 100644 --- a/test/syncContentItems.tests.js +++ b/test/syncContentItems.tests.js @@ -18,48 +18,25 @@ describe('syncContentItems:', function () { this.timeout('120s'); - it('should retrieve the oldest 100 content items', function (done) { + it('should retrieve the oldest content items and ticks', function (done) { var api = createApiClient(); - let maxVersionID = 0; + let ticks = 0; //sync from scratch api.syncContentItems({ - maxVersionID: maxVersionID, + ticks: ticks, pageSize: 100, languageCode: 'en-us' }) - .then(function (items) { - - assert.isTrue(items.length > 0, "should return items.") - - // var lastItem = items[items.length - 1]; - // console.log("lastItem"); - // console.log(items.length); - // console.log(lastItem); - // maxVersionID = lastItem.properties.versionID; + .then(function (syncRet) { + assert.isTrue(syncRet.ticks > 0, "should return a ticks value.") + assert.isTrue(syncRet.items.length > 0, "should return items.") done(); - - - }) .catch(done); - - // //sync from the previous max... - // api.syncContentItems({ - // maxVersionID: maxVersionID, - // pageSize: 100, - // languageCode: 'en-us' - // }) - // .then(function (items) { - // if (items.length > 0) { - // assert.isTrue(items[0].properties.versionID > maxVersionID, `should return items with versionID > ${maxVersionID}.`) - // } - // done(); - // }) - // .catch(done); }); diff --git a/test/syncPageItems.tests.js b/test/syncPageItems.tests.js new file mode 100644 index 0000000..3cc4b5f --- /dev/null +++ b/test/syncPageItems.tests.js @@ -0,0 +1,45 @@ +import chai from 'chai' +const assert = chai.assert; +const expect = chai.expect; + +import { createApiClient, createPreviewApiClient, createCachedApiClient } from './apiClients.config' +import { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } from 'constants'; + +/* + This file contains static references to content from the instance configured in the apiClient.config file. +*/ + +const ref = { + publishedContentItemID: 15, + updatesMadeToPublishedContentItemID: 15 +} + +describe('syncPageItems:', function () { + + this.timeout('120s'); + + it('should retrieve the oldest page items and ticks', function (done) { + var api = createApiClient(); + + let ticks = 0; + + //sync from scratch + api.syncPageItems({ + ticks: ticks, + pageSize: 100, + languageCode: 'en-us' + }) + .then(function (syncRet) { + + + assert.isTrue(syncRet.ticks > 0, "should return a ticks value.") + assert.isTrue(syncRet.items.length > 0, "should return items.") + done(); + }) + .catch(done); + + }); + + +}); +