Skip to content

Commit

Permalink
added sync calls with ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Varty committed Dec 20, 2019
1 parent 689791f commit 5afe417
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 49 deletions.
43 changes: 31 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/methods/syncContentItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<AgilityFetch.Types.ContentItem>}>} - Returns a list of content item objects.
Expand All @@ -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),
Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/methods/syncPageItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<AgilityFetch.Types.Page>}>} - Returns a list of content item objects.
Expand All @@ -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),
Expand All @@ -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;
}
Expand Down
35 changes: 6 additions & 29 deletions test/syncContentItems.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});


Expand Down
45 changes: 45 additions & 0 deletions test/syncPageItems.tests.js
Original file line number Diff line number Diff line change
@@ -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);

});


});

0 comments on commit 5afe417

Please sign in to comment.