@agility/content-fetch 1.1.0 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ const expect = chai.expect;
5
5
  import {
6
6
  createApiClient,
7
7
  createPreviewApiClient,
8
+ createCachedApiClient,
8
9
  createApiClientWithNewCdn
9
10
  } from './apiClients.config'
10
11
 
@@ -25,7 +26,7 @@ describe('getContentItem:', function() {
25
26
  var api = createApiClient();
26
27
  api.getContentItem({
27
28
  contentID: ref.updatesMadeToPublishedContentItemID,
28
- languageCode: 'en-us'
29
+ locale: 'en-us'
29
30
  })
30
31
  .then(function(contentItem) {
31
32
  assert.strictEqual(contentItem.contentID, ref.updatesMadeToPublishedContentItemID, 'retrieved content item we asked for');
@@ -39,7 +40,7 @@ describe('getContentItem:', function() {
39
40
  var api = createPreviewApiClient();
40
41
  api.getContentItem({
41
42
  contentID: ref.updatesMadeToPublishedContentItemID,
42
- languageCode: 'en-us'
43
+ locale: 'en-us'
43
44
  })
44
45
  .then(function(contentItem) {
45
46
  assert.strictEqual(contentItem.contentID, ref.updatesMadeToPublishedContentItemID, 'retrieved content item we asked for');
@@ -49,13 +50,39 @@ describe('getContentItem:', function() {
49
50
  .catch(done);
50
51
  })
51
52
 
53
+ it('should retrieve a content item in live/fetch mode, then subsequent requests are returned from cache (memory)', function(done) {
54
+ var api = createCachedApiClient();
55
+ api.getContentItem({
56
+ contentID: ref.updatesMadeToPublishedContentItemID,
57
+ locale: 'en-us'
58
+ })
59
+ .then(function(contentItem) {
60
+
61
+ assert.strictEqual(contentItem.contentID, ref.updatesMadeToPublishedContentItemID, 'retrieved content item we asked for');
62
+ assert.notExists(contentItem.fromCache, 'content item should not be served from cache on first request')
63
+
64
+ api.getContentItem({
65
+ contentID: ref.updatesMadeToPublishedContentItemID,
66
+ locale: 'en-us'
67
+ })
68
+ .then(function(contentItem2) {
69
+
70
+ assert.strictEqual(contentItem2.contentID, ref.updatesMadeToPublishedContentItemID, 'retrieved content item we asked for');
71
+ assert.strictEqual(contentItem2.fromCache, true, 'content item was retrieved from memory cache')
72
+ done();
73
+ })
74
+ .catch(done)
75
+
76
+ })
77
+ .catch(done);
78
+ })
52
79
 
53
80
  it('should throw error if contentID not passed as argument for getContentItem', function(done) {
54
81
  expect(function() {
55
82
  var api = createApiClient();
56
83
  api.getContentItem({
57
84
  someOtherParam: 22,
58
- languageCode: 'en-us'
85
+ locale: 'en-us'
59
86
  })
60
87
  .then(function(contentItem) {
61
88
  assert.strictEqual(contentItem.contentID, 22);
@@ -66,7 +93,7 @@ describe('getContentItem:', function() {
66
93
  done();
67
94
  })
68
95
 
69
- it('should throw error if languageCode not passed as argument for getContentItem', function(done) {
96
+ it('should throw error if locale not passed as argument for getContentItem', function(done) {
70
97
  expect(function() {
71
98
  var api = createApiClient();
72
99
  api.getContentItem({
@@ -86,7 +113,7 @@ describe('getContentItem:', function() {
86
113
  var api = createApiClient();
87
114
  api.getContentItem({
88
115
  contentID: 22,
89
- languageCode: 'en-us',
116
+ locale: 'en-us',
90
117
  contentLinkDepth: 'something'
91
118
  })
92
119
  .then(function(contentItem) {
@@ -103,7 +130,7 @@ describe('getContentItem:', function() {
103
130
  var api = createApiClient();
104
131
  api.getContentItem({
105
132
  contentID: 22,
106
- languageCode: 'en-us',
133
+ locale: 'en-us',
107
134
  expandAllContentLinks: 'something'
108
135
  })
109
136
  .then(function(contentItem) {
@@ -119,7 +146,7 @@ describe('getContentItem:', function() {
119
146
  var api = createApiClient();
120
147
  api.getContentItem({
121
148
  contentID: 65, //item within listwithnestedcontentlinks
122
- languageCode: 'en-us',
149
+ locale: 'en-us',
123
150
  expandAllContentLinks: true
124
151
  })
125
152
  .then(function(contentItem) {
@@ -133,7 +160,7 @@ describe('getContentItem:', function() {
133
160
  var api = createApiClient();
134
161
  api.getContentItem({
135
162
  contentID: 65, //item within listwithnestedcontentlinks
136
- languageCode: 'en-us',
163
+ locale: 'en-us',
137
164
  expandAllContentLinks: false
138
165
  })
139
166
  .then(function(contentItem) {
@@ -147,7 +174,7 @@ describe('getContentItem:', function() {
147
174
  var api = createApiClient();
148
175
  api.getContentItem({
149
176
  contentID: 65, //item within listwithnestedcontentlinks
150
- languageCode: 'en-us',
177
+ locale: 'en-us',
151
178
  })
152
179
  .then(function(contentItem) {
153
180
  assert.strictEqual(Array.isArray(contentItem.fields.posts), false);
@@ -160,7 +187,7 @@ describe('getContentItem:', function() {
160
187
  var api = createApiClientWithNewCdn();
161
188
  api.getContentItem({
162
189
  contentID: 4, //item within jssdklist
163
- languageCode: 'en-us',
190
+ locale: 'en-us',
164
191
  })
165
192
  .then(function(contentItem) {
166
193
  assert.strictEqual(contentItem.fields.title, 'JS SDK Item - DO NOT DELETE');
@@ -4,6 +4,7 @@ const expect = chai.expect;
4
4
  import {
5
5
  createApiClient,
6
6
  createPreviewApiClient,
7
+ createCachedApiClient,
7
8
  createApiClientWithNewCdn
8
9
  } from './apiClients.config'
9
10
 
@@ -21,7 +22,7 @@ describe('getContentList:', function() {
21
22
  var api = createApiClient();
22
23
  api.getContentList({
23
24
  referenceName: 'posts',
24
- languageCode: 'en-us'
25
+ locale: 'en-us'
25
26
  })
26
27
  .then(function(contentList) {
27
28
  assert.strictEqual(contentList.items[0].contentID, 15);
@@ -35,7 +36,7 @@ describe('getContentList:', function() {
35
36
  var api = createPreviewApiClient();
36
37
  api.getContentList({
37
38
  referenceName: 'posts',
38
- languageCode: 'en-us'
39
+ locale: 'en-us'
39
40
  })
40
41
  .then(function(contentList) {
41
42
  assert.strictEqual(contentList.items[0].contentID, 15);
@@ -50,7 +51,7 @@ describe('getContentList:', function() {
50
51
  var api = createApiClient();
51
52
  api.getContentList({
52
53
  someOtherParam: 'posts',
53
- languageCode: 'en-us'
54
+ locale: 'en-us'
54
55
  })
55
56
  .then(function(contentList) {
56
57
  assert.strictEqual(contentList[0].contentID, 24);
@@ -62,7 +63,7 @@ describe('getContentList:', function() {
62
63
  done();
63
64
  });
64
65
 
65
- it('should throw error if languageCode param is missing in getContentList', function(done) {
66
+ it('should throw error if locale param is missing in getContentList', function(done) {
66
67
  expect(function() {
67
68
  var api = createApiClient();
68
69
  api.getContentList({
@@ -83,7 +84,7 @@ describe('getContentList:', function() {
83
84
  var api = createApiClient();
84
85
  api.getContentList({
85
86
  referenceName: 'posts',
86
- languageCode: 'en-us',
87
+ locale: 'en-us',
87
88
  take: 'ten'
88
89
  })
89
90
  .then(function(contentList) {
@@ -101,7 +102,7 @@ describe('getContentList:', function() {
101
102
  var api = createApiClient();
102
103
  api.getContentList({
103
104
  referenceName: 'posts',
104
- languageCode: 'en-us',
105
+ locale: 'en-us',
105
106
  take: 0
106
107
  })
107
108
  .then(function(contentList) {
@@ -114,13 +115,13 @@ describe('getContentList:', function() {
114
115
  done();
115
116
  });
116
117
 
117
- it('should throw error if take parameter is a number greater than 50 in getContentList', function(done) {
118
+ it('should throw error if take parameter is a number greater than 250 in getContentList', function(done) {
118
119
  expect(function() {
119
120
  var api = createApiClient();
120
121
  api.getContentList({
121
122
  referenceName: 'posts',
122
- languageCode: 'en-us',
123
- take: 51
123
+ locale: 'en-us',
124
+ take: 251
124
125
  })
125
126
  .then(function(contentList) {
126
127
  assert.strictEqual(contentList[0].contentID, 24);
@@ -137,7 +138,7 @@ describe('getContentList:', function() {
137
138
  var api = createApiClient();
138
139
  api.getContentList({
139
140
  referenceName: 'posts',
140
- languageCode: 'en-us',
141
+ locale: 'en-us',
141
142
  skip: -1
142
143
  })
143
144
  .then(function(contentList) {
@@ -155,7 +156,7 @@ describe('getContentList:', function() {
155
156
  var api = createApiClient();
156
157
  api.getContentList({
157
158
  referenceName: 'posts',
158
- languageCode: 'en-us',
159
+ locale: 'en-us',
159
160
  skip: 'ten'
160
161
  })
161
162
  .then(function(contentList) {
@@ -173,7 +174,7 @@ describe('getContentList:', function() {
173
174
  var api = createApiClient();
174
175
  api.getContentList({
175
176
  referenceName: 'posts',
176
- languageCode: 'en-us',
177
+ locale: 'en-us',
177
178
  sort: 'fields.title',
178
179
  direction: 'up'
179
180
  })
@@ -191,12 +192,11 @@ describe('getContentList:', function() {
191
192
  var api = createApiClient();
192
193
  api.getContentList({
193
194
  referenceName: 'posts',
194
- languageCode: 'en-us',
195
- sort: 'properties.versionID',
196
- direction: api.types.SortDirections.DESC
195
+ locale: 'en-us',
196
+ sort: 'contentID',
197
197
  })
198
198
  .then(function(contentList) {
199
- assert.isTrue(contentList.items[0].contentID > contentList.items[1].contentID);
199
+ assert.isTrue(contentList.items[0].contentID < contentList.items[1].contentID);
200
200
  done();
201
201
  })
202
202
  .catch(done);
@@ -207,7 +207,7 @@ describe('getContentList:', function() {
207
207
  var api = createApiClient();
208
208
  api.getContentList({
209
209
  referenceName: 'posts',
210
- languageCode: 'en-us',
210
+ locale: 'en-us',
211
211
  filters: [{operator: api.types.FilterOperators.EQUAL_TO, value: '40'}]
212
212
  })
213
213
  .then(function(contentList) {
@@ -223,7 +223,7 @@ describe('getContentList:', function() {
223
223
  var api = createApiClient();
224
224
  api.getContentList({
225
225
  referenceName: 'posts',
226
- languageCode: 'en-us',
226
+ locale: 'en-us',
227
227
  filters: [{property: 'properties.versionID', value: '40'}]
228
228
  })
229
229
  .then(function(contentList) {
@@ -239,7 +239,7 @@ describe('getContentList:', function() {
239
239
  var api = createApiClient();
240
240
  api.getContentList({
241
241
  referenceName: 'posts',
242
- languageCode: 'en-us',
242
+ locale: 'en-us',
243
243
  filters: [{property: 'properties.versionID', operator: api.types.FilterOperators.EQUAL_TO}]
244
244
  })
245
245
  .then(function(contentList) {
@@ -255,7 +255,7 @@ describe('getContentList:', function() {
255
255
  var api = createApiClient();
256
256
  api.getContentList({
257
257
  referenceName: 'posts',
258
- languageCode: 'en-us',
258
+ locale: 'en-us',
259
259
  filters: [{property: 'properties.versionID', operator: 'xx', value: '40'}]
260
260
  })
261
261
  .then(function(contentList) {
@@ -271,7 +271,7 @@ describe('getContentList:', function() {
271
271
  var api = createApiClient();
272
272
  api.getContentList({
273
273
  referenceName: 'posts',
274
- languageCode: 'en-us',
274
+ locale: 'en-us',
275
275
  filtersLogicOperator: 'SOME'
276
276
  })
277
277
  .then(function(contentList) {
@@ -286,7 +286,7 @@ describe('getContentList:', function() {
286
286
  var api = createApiClient();
287
287
  api.getContentList({
288
288
  referenceName: 'posts',
289
- languageCode: 'en-us',
289
+ locale: 'en-us',
290
290
  filters: [{property: 'contentID', operator: api.types.FilterOperators.EQUAL_TO, value: '15'}, {property: 'properties.referenceName', operator: api.types.FilterOperators.LIKE, value: 'posts'}],
291
291
  filtersLogicOperator: api.types.FilterLogicOperators.OR
292
292
  })
@@ -302,7 +302,7 @@ describe('getContentList:', function() {
302
302
  var api = createApiClient();
303
303
  api.getContentList({
304
304
  referenceName: 'posts',
305
- languageCode: 'en-us',
305
+ locale: 'en-us',
306
306
  filters: [{property: 'contentID', operator: api.types.FilterOperators.EQUAL_TO, value: '16'}, {property: 'properties.referenceName', operator: api.types.FilterOperators.LIKE, value: 'posts'}],
307
307
  filtersLogicOperator: api.types.FilterLogicOperators.AND
308
308
  })
@@ -318,7 +318,7 @@ describe('getContentList:', function() {
318
318
  var api = createApiClient();
319
319
  api.getContentList({
320
320
  referenceName: 'listwithnestedcontentlink',
321
- languageCode: 'en-us',
321
+ locale: 'en-us',
322
322
  expandAllContentLinks: true
323
323
  })
324
324
  .then(function(contentList) {
@@ -332,7 +332,7 @@ describe('getContentList:', function() {
332
332
  var api = createApiClient();
333
333
  api.getContentList({
334
334
  referenceName: 'listwithnestedcontentlink',
335
- languageCode: 'en-us',
335
+ locale: 'en-us',
336
336
  expandAllContentLinks: false
337
337
  })
338
338
  .then(function(contentList) {
@@ -346,7 +346,7 @@ describe('getContentList:', function() {
346
346
  var api = createApiClient();
347
347
  api.getContentList({
348
348
  referenceName: 'listwithnestedcontentlink',
349
- languageCode: 'en-us'
349
+ locale: 'en-us'
350
350
  })
351
351
  .then(function(contentList) {
352
352
  assert.strictEqual(Array.isArray(contentList.items[0].fields.posts), false);
@@ -360,7 +360,7 @@ describe('getContentList:', function() {
360
360
  let referenceName = 'jssdklist';
361
361
  api.getContentList({
362
362
  referenceName: referenceName,
363
- languageCode: 'en-us'
363
+ locale: 'en-us'
364
364
  })
365
365
  .then(function(contentList) {
366
366
  assert.strictEqual(contentList.items[0].properties.referenceName, referenceName);
@@ -2,7 +2,7 @@ import chai from 'chai'
2
2
  const assert = chai.assert;
3
3
  const expect = chai.expect;
4
4
 
5
- import { createApiClient, createPreviewApiClient } from './apiClients.config'
5
+ import { createApiClient, createPreviewApiClient, createCatchedApiClient } from './apiClients.config'
6
6
 
7
7
  /*
8
8
  This file contains static references to content from the instance configured in the apiClient.config file.
@@ -21,7 +21,7 @@ import { createApiClient, createPreviewApiClient } from './apiClients.config'
21
21
  var api = createApiClient();
22
22
  api.getPage({
23
23
  pageID: 2,
24
- languageCode: 'en-us'
24
+ locale: 'en-us'
25
25
  })
26
26
  .then(function(page) {
27
27
  assert.strictEqual(page.pageID, 2);
@@ -34,7 +34,7 @@ import { createApiClient, createPreviewApiClient } from './apiClients.config'
34
34
  var api = createPreviewApiClient();
35
35
  api.getPage({
36
36
  pageID: 2,
37
- languageCode: 'en-us'
37
+ locale: 'en-us'
38
38
  })
39
39
  .then(function(page) {
40
40
  assert.strictEqual(page.pageID, 2);
@@ -48,7 +48,7 @@ import { createApiClient, createPreviewApiClient } from './apiClients.config'
48
48
  var api = createApiClient();
49
49
  api.getPage({
50
50
  someOtherParam: 1,
51
- languageCode: 'en-us'
51
+ locale: 'en-us'
52
52
  })
53
53
  .then(function(page) {
54
54
  assert.strictEqual(page.pageID, 2);
@@ -59,7 +59,7 @@ import { createApiClient, createPreviewApiClient } from './apiClients.config'
59
59
  done();
60
60
  })
61
61
 
62
- it('should throw error if languageCode not passed as argument for getPage', function(done) {
62
+ it('should throw error if locale not passed as argument for getPage', function(done) {
63
63
  expect(function() {
64
64
  var api = createApiClient();
65
65
  api.getPage({
@@ -78,7 +78,7 @@ import { createApiClient, createPreviewApiClient } from './apiClients.config'
78
78
  var api = createApiClient();
79
79
  api.getPage({
80
80
  pageID: 2,
81
- languageCode: 'en-us',
81
+ locale: 'en-us',
82
82
  expandAllContentLinks: true
83
83
  })
84
84
  .then(function(page) {
@@ -2,7 +2,7 @@ import chai from 'chai'
2
2
  const assert = chai.assert;
3
3
  const expect = chai.expect;
4
4
 
5
- import { createApiClient, createPreviewApiClient } from './apiClients.config'
5
+ import { createApiClient, createPreviewApiClient, createCatchedApiClient } from './apiClients.config'
6
6
 
7
7
  /*
8
8
  This file contains static references to content from the instance configured in the apiClient.config file.
@@ -18,7 +18,7 @@ describe('getSitemapFlat:', function() {
18
18
  var api = createApiClient();
19
19
  api.getSitemapFlat({
20
20
  channelName: 'website',
21
- languageCode: 'en-us'
21
+ locale: 'en-us'
22
22
  })
23
23
  .then(function(sitemap) {
24
24
  assert.strictEqual(sitemap['/home'].pageID, 2);
@@ -31,7 +31,7 @@ describe('getSitemapFlat:', function() {
31
31
  var api = createPreviewApiClient();
32
32
  api.getSitemapFlat({
33
33
  channelName: 'website',
34
- languageCode: 'en-us'
34
+ locale: 'en-us'
35
35
  })
36
36
  .then(function(sitemap) {
37
37
  assert.strictEqual(sitemap['/home'].pageID, 2);
@@ -45,7 +45,7 @@ describe('getSitemapFlat:', function() {
45
45
  var api = createApiClient();
46
46
  api.getSitemapFlat({
47
47
  someOtherParam: 1,
48
- languageCode: 'en-us'
48
+ locale: 'en-us'
49
49
  })
50
50
  .then(function(sitemap) {
51
51
  assert.strictEqual(sitemap['/home'].pageID, 2);
@@ -56,7 +56,7 @@ describe('getSitemapFlat:', function() {
56
56
  done();
57
57
  })
58
58
 
59
- it('should throw error if languageCode not passed as argument for getSitemapFlat', function(done) {
59
+ it('should throw error if locale not passed as argument for getSitemapFlat', function(done) {
60
60
  expect(function() {
61
61
  var api = createApiClient();
62
62
  api.getSitemapFlat({
@@ -2,7 +2,7 @@ import chai from 'chai'
2
2
  const assert = chai.assert;
3
3
  const expect = chai.expect;
4
4
 
5
- import { createApiClient, createPreviewApiClient } from './apiClients.config'
5
+ import { createApiClient, createPreviewApiClient, createCatchedApiClient } from './apiClients.config'
6
6
 
7
7
  /*
8
8
  This file contains static references to content from the instance configured in the apiClient.config file.
@@ -18,7 +18,7 @@ describe('getSitemapNested:', function() {
18
18
  var api = createApiClient();
19
19
  api.getSitemapNested({
20
20
  channelName: 'website',
21
- languageCode: 'en-us'
21
+ locale: 'en-us'
22
22
  })
23
23
  .then(function(sitemap) {
24
24
  assert.strictEqual(sitemap[0].pageID, 2);
@@ -31,7 +31,7 @@ describe('getSitemapNested:', function() {
31
31
  var api = createPreviewApiClient();
32
32
  api.getSitemapNested({
33
33
  channelName: 'website',
34
- languageCode: 'en-us'
34
+ locale: 'en-us'
35
35
  })
36
36
  .then(function(sitemap) {
37
37
  assert.strictEqual(sitemap[0].pageID, 2);
@@ -45,7 +45,7 @@ describe('getSitemapNested:', function() {
45
45
  var api = createApiClient();
46
46
  api.getSitemapNested({
47
47
  someOtherParam: 1,
48
- languageCode: 'en-us'
48
+ locale: 'en-us'
49
49
  })
50
50
  .then(function(sitemap) {
51
51
  assert.strictEqual(sitemap[0].pageID, 2);
@@ -56,7 +56,7 @@ describe('getSitemapNested:', function() {
56
56
  done();
57
57
  })
58
58
 
59
- it('should throw error if languageCode not passed as argument for getSitemapNested', function(done) {
59
+ it('should throw error if locale not passed as argument for getSitemapNested', function(done) {
60
60
  expect(function() {
61
61
  var api = createApiClient();
62
62
  api.getSitemapNested({
@@ -2,7 +2,7 @@ import chai from 'chai'
2
2
  const assert = chai.assert;
3
3
  const expect = chai.expect;
4
4
 
5
- import { createApiClient, createPreviewApiClient } from './apiClients.config'
5
+ import { createApiClient, createPreviewApiClient, createCachedApiClient } from './apiClients.config'
6
6
  import { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } from 'constants';
7
7
 
8
8
  /*
@@ -27,7 +27,7 @@ describe('getSyncContent:', function () {
27
27
  api.getSyncContent({
28
28
  syncToken: syncToken,
29
29
  pageSize: 100,
30
- languageCode: 'en-us'
30
+ locale: 'en-us'
31
31
  })
32
32
  .then(function (syncRet) {
33
33
 
@@ -2,7 +2,7 @@ import chai from 'chai'
2
2
  const assert = chai.assert;
3
3
  const expect = chai.expect;
4
4
 
5
- import { createApiClient, createPreviewApiClient } from './apiClients.config'
5
+ import { createApiClient, createPreviewApiClient, createCachedApiClient } from './apiClients.config'
6
6
  import { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } from 'constants';
7
7
 
8
8
  /*
@@ -27,7 +27,7 @@ describe('getSyncPages:', function () {
27
27
  api.getSyncPages({
28
28
  syncToken: syncToken,
29
29
  pageSize: 100,
30
- languageCode: 'en-us'
30
+ locale: 'en-us'
31
31
  })
32
32
  .then(function (syncRet) {
33
33