@quintype/framework 7.11.0-react-upgrade.0 → 7.11.0
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.
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [7.11.0](https://github.com/quintype/quintype-node-framework/compare/v7.10.5...v7.11.0) (2022-10-31)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* remove powered by quintype from the footer ([#334](https://github.com/quintype/quintype-node-framework/issues/334)) ([3dbc1f3](https://github.com/quintype/quintype-node-framework/commit/3dbc1f3144536a439ad0ecaacd2313cb6bb528e1))
|
|
11
|
+
|
|
12
|
+
### [7.10.5](https://github.com/quintype/quintype-node-framework/compare/v7.10.4...v7.10.5) (2022-10-17)
|
|
13
|
+
|
|
5
14
|
### [7.10.4](https://github.com/quintype/quintype-node-framework/compare/v7.10.3...v7.10.4) (2022-10-04)
|
|
6
15
|
|
|
7
16
|
## [7.10.0](https://github.com/quintype/quintype-node-framework/compare/v7.7.7...v7.10.0) (2022-10-04)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quintype/framework",
|
|
3
|
-
"version": "7.11.0
|
|
3
|
+
"version": "7.11.0",
|
|
4
4
|
"description": "Libraries to help build Quintype Node.js apps",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"homepage": "https://github.com/quintype/quintype-node-framework#readme",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@ampproject/toolbox-optimizer": "2.8.3",
|
|
34
|
-
"@quintype/amp": "^2.
|
|
35
|
-
"@quintype/backend": "^2.3.
|
|
34
|
+
"@quintype/amp": "^2.7.2",
|
|
35
|
+
"@quintype/backend": "^2.3.3",
|
|
36
36
|
"@quintype/components": "^3.0.0",
|
|
37
37
|
"@quintype/prerender-node": "^3.2.26",
|
|
38
|
-
"@quintype/seo": "1.
|
|
38
|
+
"@quintype/seo": "^1.39.0",
|
|
39
39
|
"atob": "^2.1.2",
|
|
40
40
|
"babel-plugin-react-css-modules": "^5.2.6",
|
|
41
41
|
"chalk": "^4.1.2",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"mocha-snapshots": "^4.2.0",
|
|
53
53
|
"morgan": "^1.10.0",
|
|
54
54
|
"path-to-regexp": "^6.2.0",
|
|
55
|
-
"react": "^
|
|
56
|
-
"react-dom": "^
|
|
55
|
+
"react": "^16.14.0",
|
|
56
|
+
"react-dom": "^16.14.0",
|
|
57
57
|
"react-redux": "^7.2.5",
|
|
58
58
|
"react-router": "^5.2.1",
|
|
59
59
|
"redux": "^4.1.1",
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"supertest": "^6.1.6"
|
|
100
100
|
},
|
|
101
101
|
"peerDependencies": {
|
|
102
|
-
"@quintype/seo": "1.
|
|
102
|
+
"@quintype/seo": "^1.39.0"
|
|
103
103
|
},
|
|
104
104
|
"nyc": {
|
|
105
105
|
"exclude": [
|
|
@@ -57,7 +57,7 @@ class InfiniteScrollAmp {
|
|
|
57
57
|
};
|
|
58
58
|
if (this.infiniteScrollSource === "relatedStoriesApi") {
|
|
59
59
|
const relatedStoriesList = await this.client.getRelatedStories(storyId, null, params);
|
|
60
|
-
if (!relatedStoriesList)
|
|
60
|
+
if (!relatedStoriesList || !relatedStoriesList["related-stories"].length)
|
|
61
61
|
return new Error();
|
|
62
62
|
return filteredItems = this.getFilteredApiItems(relatedStoriesList["related-stories"]);
|
|
63
63
|
} else {
|
|
@@ -3,17 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
const assert = require("assert");
|
|
5
5
|
const InfiniteScrollAmp = require("../../../server/amp/helpers/infinite-scroll");
|
|
6
|
-
const { getTextStory } = require("../../data/amp-test-data");
|
|
7
6
|
|
|
8
7
|
function getClientStub({
|
|
9
|
-
getStoryById = (id) =>
|
|
10
|
-
new Promise((resolve) => {
|
|
11
|
-
if (id === "4444")
|
|
12
|
-
resolve({
|
|
13
|
-
story: getTextStory({ "story-content-id": "7f3d5bdb-ec52-4047-ac0d-df4036ec974b" }),
|
|
14
|
-
});
|
|
15
|
-
resolve(null);
|
|
16
|
-
}),
|
|
17
8
|
getCollectionBySlug = (slug) =>
|
|
18
9
|
new Promise((resolve) => {
|
|
19
10
|
if (slug === "amp-infinite-scroll")
|
|
@@ -119,10 +110,152 @@ function getClientStub({
|
|
|
119
110
|
});
|
|
120
111
|
resolve(null);
|
|
121
112
|
}),
|
|
113
|
+
getRelatedStories = () =>
|
|
114
|
+
new Promise((resolve) => {
|
|
115
|
+
resolve({
|
|
116
|
+
"related-stories": [
|
|
117
|
+
{
|
|
118
|
+
"story-template": "text",
|
|
119
|
+
headline: "aaa",
|
|
120
|
+
"story-content-id": 1111,
|
|
121
|
+
slug: "sports/aa",
|
|
122
|
+
"hero-image-s3-key": "aa/a.jpg",
|
|
123
|
+
access: "public",
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"story-template": "visual-story",
|
|
127
|
+
headline: "bbb",
|
|
128
|
+
"story-content-id": 2222,
|
|
129
|
+
slug: "sports/bb",
|
|
130
|
+
"hero-image-s3-key": "bb/b.jpg",
|
|
131
|
+
access: "public",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"story-template": "text",
|
|
135
|
+
headline: "ccc",
|
|
136
|
+
"story-content-id": 3333,
|
|
137
|
+
slug: "sports/cc",
|
|
138
|
+
"hero-image-s3-key": "cc/c.jpg",
|
|
139
|
+
access: "public",
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"story-template": "text",
|
|
143
|
+
headline: "ddd",
|
|
144
|
+
"story-content-id": 4444,
|
|
145
|
+
slug: "sports/dd",
|
|
146
|
+
"hero-image-s3-key": "dd/d.jpg",
|
|
147
|
+
access: "public",
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"story-template": "text",
|
|
151
|
+
headline: "eee",
|
|
152
|
+
"story-content-id": 5555,
|
|
153
|
+
slug: "politics/ee",
|
|
154
|
+
"hero-image-s3-key": "ee/e.jpg",
|
|
155
|
+
access: "public",
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"story-template": "text",
|
|
159
|
+
headline: "fff",
|
|
160
|
+
"story-content-id": 6666,
|
|
161
|
+
slug: "politics/ff",
|
|
162
|
+
"hero-image-s3-key": "ff/f.jpg",
|
|
163
|
+
access: "public",
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"story-template": "text",
|
|
167
|
+
headline: "ggg",
|
|
168
|
+
"story-content-id": 7777,
|
|
169
|
+
slug: "politics/gg",
|
|
170
|
+
"hero-image-s3-key": "gg/g.jpg",
|
|
171
|
+
access: "public",
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"story-template": "text",
|
|
175
|
+
headline: "hhh",
|
|
176
|
+
"story-content-id": 8888,
|
|
177
|
+
slug: "politics/hh",
|
|
178
|
+
"hero-image-s3-key": "hh/h.jpg",
|
|
179
|
+
access: "public",
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
});
|
|
183
|
+
}),
|
|
122
184
|
} = {}) {
|
|
123
185
|
return {
|
|
124
186
|
getCollectionBySlug,
|
|
125
|
-
|
|
187
|
+
getRelatedStories,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function getCustomApiStoriesClientStub({
|
|
191
|
+
getCustomApiStories = () =>
|
|
192
|
+
new Promise((resolve) => {
|
|
193
|
+
resolve(
|
|
194
|
+
[
|
|
195
|
+
{
|
|
196
|
+
title: "aaa",
|
|
197
|
+
url: "sports/aa",
|
|
198
|
+
image: "aa/a.jpg",
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
title: "bbb",
|
|
202
|
+
url: "sports/bb",
|
|
203
|
+
image: "bb/b.jpg",
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
title: "ccc",
|
|
207
|
+
url: "sports/cc",
|
|
208
|
+
image: "cc/c.jpg",
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
title: "ddd",
|
|
212
|
+
url: "sports/dd",
|
|
213
|
+
image: "dd/d.jpg",
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
title: "eee",
|
|
217
|
+
url: "politics/ee",
|
|
218
|
+
image: "ee/e.jpg",
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
title: "fff",
|
|
222
|
+
url: "politics/ff",
|
|
223
|
+
image: "ff/f.jpg",
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
title: "ggg",
|
|
227
|
+
url: "politics/gg",
|
|
228
|
+
image: "gg/g.jpg",
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
title: "hhh",
|
|
232
|
+
url: "politics/hh",
|
|
233
|
+
image: "hh/h.jpg",
|
|
234
|
+
},
|
|
235
|
+
]
|
|
236
|
+
);
|
|
237
|
+
}),
|
|
238
|
+
} = {}) {
|
|
239
|
+
return {
|
|
240
|
+
getCustomApiStories,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
class CustomInfiniteScrollAmp {
|
|
244
|
+
constructor({ client, publisherConfig, queryParams, infiniteScrollSource }) {
|
|
245
|
+
this.client = client;
|
|
246
|
+
this.publisherConfig = publisherConfig;
|
|
247
|
+
this.queryParams = queryParams;
|
|
248
|
+
this.infiniteScrollSource = infiniteScrollSource;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async getCustomStoryList({ type = "inlineConfig" }) {
|
|
252
|
+
const customStories = await this.client.getCustomApiStories();
|
|
253
|
+
if (!customStories || customStories.length === 0)
|
|
254
|
+
return new Error();
|
|
255
|
+
if (type === "remoteConfig") {
|
|
256
|
+
return JSON.stringify({ pages: customStories });
|
|
257
|
+
}
|
|
258
|
+
return JSON.stringify(customStories);
|
|
126
259
|
};
|
|
127
260
|
}
|
|
128
261
|
const dummyPublisherConfig = {
|
|
@@ -130,6 +263,7 @@ const dummyPublisherConfig = {
|
|
|
130
263
|
};
|
|
131
264
|
|
|
132
265
|
describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", function () {
|
|
266
|
+
// collection
|
|
133
267
|
it("should throw err if storyId isn't passed", async function () {
|
|
134
268
|
const infiniteScrollAmp = new InfiniteScrollAmp({
|
|
135
269
|
ampConfig: {},
|
|
@@ -230,23 +364,179 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
|
|
|
230
364
|
// it("should take the first 'n' stories", async function() {
|
|
231
365
|
// // this test needs to be written after https://github.com/quintype/quintype-node-framework/pull/202 is merged
|
|
232
366
|
// })
|
|
367
|
+
/// related-stories
|
|
368
|
+
it("should throw err if storyId isn't passed for relatedStoriesApi", async function () {
|
|
369
|
+
const infiniteScrollAmp = new InfiniteScrollAmp({
|
|
370
|
+
ampConfig: {},
|
|
371
|
+
client: getClientStub(),
|
|
372
|
+
publisherConfig: dummyPublisherConfig,
|
|
373
|
+
infiniteScrollSource: "relatedStoriesApi",
|
|
374
|
+
});
|
|
375
|
+
const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({ storyId: "" });
|
|
376
|
+
assert.strictEqual(inlineConfig instanceof Error, true);
|
|
377
|
+
assert.throws(() => {
|
|
378
|
+
throw new Error("Required params for getInitialInlineConfig missing");
|
|
379
|
+
}, inlineConfig);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("should return null if relatedStoriesApi infinite scroll collection doesn't exist", async function () {
|
|
383
|
+
const clientStub = getClientStub({
|
|
384
|
+
getRelatedStories: () =>
|
|
385
|
+
new Promise((resolve) => {
|
|
386
|
+
resolve(null);
|
|
387
|
+
}),
|
|
388
|
+
});
|
|
389
|
+
const infiniteScrollAmp = new InfiniteScrollAmp({
|
|
390
|
+
ampConfig: {},
|
|
391
|
+
client: clientStub,
|
|
392
|
+
publisherConfig: dummyPublisherConfig,
|
|
393
|
+
infiniteScrollSource: "relatedStoriesApi",
|
|
394
|
+
});
|
|
395
|
+
const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
|
|
396
|
+
storyId: 2222,
|
|
397
|
+
});
|
|
398
|
+
assert.strictEqual(inlineConfig, null);
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it("should return null if relatedStoriesApi infinite scroll collection contains no stories", async function () {
|
|
402
|
+
const clientStub = getClientStub({
|
|
403
|
+
getRelatedStories: () =>
|
|
404
|
+
new Promise((resolve) => {
|
|
405
|
+
resolve({
|
|
406
|
+
"related-stories": [],
|
|
407
|
+
});
|
|
408
|
+
}),
|
|
409
|
+
});
|
|
410
|
+
const infiniteScrollAmp = new InfiniteScrollAmp({
|
|
411
|
+
ampConfig: {},
|
|
412
|
+
client: clientStub,
|
|
413
|
+
publisherConfig: dummyPublisherConfig,
|
|
414
|
+
infiniteScrollSource: "relatedStoriesApi",
|
|
415
|
+
});
|
|
416
|
+
const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
|
|
417
|
+
storyId: 2222,
|
|
418
|
+
});
|
|
419
|
+
assert.strictEqual(inlineConfig, null);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
it("should remove visual stories from relatedStoriesApi infinite scroll", async function () {
|
|
423
|
+
const clientStub = getClientStub();
|
|
424
|
+
const infiniteScrollAmp = new InfiniteScrollAmp({
|
|
425
|
+
ampConfig: {},
|
|
426
|
+
client: clientStub,
|
|
427
|
+
publisherConfig: dummyPublisherConfig,
|
|
428
|
+
infiniteScrollSource: "relatedStoriesApi",
|
|
429
|
+
});
|
|
430
|
+
const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
|
|
431
|
+
storyId: 3333,
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
assert.strictEqual(false, /sports\/bb/.test(inlineConfig));
|
|
435
|
+
assert.strictEqual(false, /bb\/b.jpg/.test(inlineConfig));
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it("relatedStoriesApi Response should be in JSON format as per AMP spec", async function () {
|
|
439
|
+
// https://amp.dev/documentation/components/amp-next-page/
|
|
440
|
+
const clientStub = getClientStub();
|
|
441
|
+
const infiniteScrollAmp = new InfiniteScrollAmp({
|
|
442
|
+
ampConfig: {},
|
|
443
|
+
client: clientStub,
|
|
444
|
+
publisherConfig: dummyPublisherConfig,
|
|
445
|
+
infiniteScrollSource: "relatedStoriesApi",
|
|
446
|
+
});
|
|
447
|
+
const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
|
|
448
|
+
storyId: 2222,
|
|
449
|
+
});
|
|
450
|
+
function isInlineConfigStructureValid(jsonStr) {
|
|
451
|
+
const stories = JSON.parse(jsonStr);
|
|
452
|
+
if (!stories.length) throw new Error("Can't verify empty array!");
|
|
453
|
+
stories.forEach((story) => {
|
|
454
|
+
const keys = Object.keys(story);
|
|
455
|
+
if (keys.includes("image") && keys.includes("url") && keys.includes("title") && keys.length === 3) return;
|
|
456
|
+
throw new Error("Invalid InlineConfigStructure");
|
|
457
|
+
});
|
|
458
|
+
return true;
|
|
459
|
+
}
|
|
460
|
+
assert.strictEqual(isInlineConfigStructureValid(inlineConfig), true);
|
|
461
|
+
});
|
|
462
|
+
/// custom-stories
|
|
463
|
+
it("should return null if CustomApi Stories infinite scroll collection doesn't exist", async function () {
|
|
464
|
+
const clientStub = getCustomApiStoriesClientStub({
|
|
465
|
+
getCustomApiStories: () =>
|
|
466
|
+
new Promise((resolve) => {
|
|
467
|
+
resolve(null);
|
|
468
|
+
}),
|
|
469
|
+
});
|
|
470
|
+
const customInfiniteScrollAmp = new CustomInfiniteScrollAmp({
|
|
471
|
+
client: clientStub,
|
|
472
|
+
publisherConfig: dummyPublisherConfig,
|
|
473
|
+
infiniteScrollSource: "custom",
|
|
474
|
+
});
|
|
475
|
+
const inlineConfig = await customInfiniteScrollAmp.getCustomStoryList({
|
|
476
|
+
type: "inlineConfig",
|
|
477
|
+
});
|
|
478
|
+
assert.strictEqual(inlineConfig instanceof Error, true);
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
it("should return null if CustomApi Stories infinite scroll collection contains no stories", async function () {
|
|
482
|
+
const clientStub = getCustomApiStoriesClientStub({
|
|
483
|
+
getCustomApiStories: () =>
|
|
484
|
+
new Promise((resolve) => {
|
|
485
|
+
resolve([]);
|
|
486
|
+
}),
|
|
487
|
+
});
|
|
488
|
+
const customInfiniteScrollAmp = new CustomInfiniteScrollAmp({
|
|
489
|
+
client: clientStub,
|
|
490
|
+
publisherConfig: dummyPublisherConfig,
|
|
491
|
+
infiniteScrollSource: "custom",
|
|
492
|
+
});
|
|
493
|
+
const inlineConfig = await customInfiniteScrollAmp.getCustomStoryList({
|
|
494
|
+
type: "inlineConfig",
|
|
495
|
+
});
|
|
496
|
+
assert.strictEqual(inlineConfig instanceof Error, true);
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
it("CustomApi Stories Response should be in JSON format as per AMP spec", async function () {
|
|
500
|
+
// https://amp.dev/documentation/components/amp-next-page/
|
|
501
|
+
const clientStub = getCustomApiStoriesClientStub();
|
|
502
|
+
const customInfiniteScrollAmp = new CustomInfiniteScrollAmp({
|
|
503
|
+
client: clientStub,
|
|
504
|
+
publisherConfig: dummyPublisherConfig,
|
|
505
|
+
infiniteScrollSource: "custom",
|
|
506
|
+
});
|
|
507
|
+
const inlineConfig = await customInfiniteScrollAmp.getCustomStoryList({
|
|
508
|
+
type: "inlineConfig",
|
|
509
|
+
});
|
|
510
|
+
function isInlineConfigStructureValid(jsonStr) {
|
|
511
|
+
const stories = JSON.parse(jsonStr);
|
|
512
|
+
if (!stories.length) throw new Error("Can't verify empty array!");
|
|
513
|
+
stories.forEach((story) => {
|
|
514
|
+
const keys = Object.keys(story);
|
|
515
|
+
if (keys.includes("image") && keys.includes("url") && keys.includes("title") && keys.length === 3) return;
|
|
516
|
+
throw new Error("Invalid InlineConfigStructure");
|
|
517
|
+
});
|
|
518
|
+
return true;
|
|
519
|
+
}
|
|
520
|
+
assert.strictEqual(isInlineConfigStructureValid(inlineConfig), true);
|
|
521
|
+
});
|
|
233
522
|
});
|
|
234
523
|
|
|
235
524
|
describe("getResponse method of InfiniteScrollAmp helper function", function () {
|
|
236
|
-
|
|
525
|
+
// collection
|
|
526
|
+
it("should throw an error in Collection if 'story-id' isn't passed as query param", async function () {
|
|
237
527
|
const infiniteScrollAmp = new InfiniteScrollAmp({
|
|
238
528
|
ampConfig: {},
|
|
239
529
|
client: getClientStub(),
|
|
240
530
|
publisherConfig: dummyPublisherConfig,
|
|
241
531
|
queryParams: { foo: "bar" },
|
|
242
532
|
});
|
|
243
|
-
const jsonResponse = await infiniteScrollAmp.getResponse(
|
|
533
|
+
const jsonResponse = await infiniteScrollAmp.getResponse();
|
|
244
534
|
assert.strictEqual(jsonResponse instanceof Error, true);
|
|
245
535
|
assert.throws(() => {
|
|
246
536
|
throw new Error(`Query param "story-id" missing`);
|
|
247
537
|
}, jsonResponse);
|
|
248
538
|
});
|
|
249
|
-
it("should throw an error if infinite scroll collection doesn't exist", async function () {
|
|
539
|
+
it("should throw an error if Collection infinite scroll collection doesn't exist", async function () {
|
|
250
540
|
const clientStub = getClientStub({
|
|
251
541
|
getCollectionBySlug: () =>
|
|
252
542
|
new Promise((resolve) => {
|
|
@@ -259,10 +549,10 @@ describe("getResponse method of InfiniteScrollAmp helper function", function ()
|
|
|
259
549
|
publisherConfig: dummyPublisherConfig,
|
|
260
550
|
queryParams: { "story-id": 2222 },
|
|
261
551
|
});
|
|
262
|
-
const jsonResponse = await infiniteScrollAmp.getResponse(
|
|
552
|
+
const jsonResponse = await infiniteScrollAmp.getResponse();
|
|
263
553
|
assert.strictEqual(jsonResponse instanceof Error, true);
|
|
264
554
|
});
|
|
265
|
-
it("should remove current story from response", async function () {
|
|
555
|
+
it("should remove current story from Collection response", async function () {
|
|
266
556
|
const clientStub = getClientStub();
|
|
267
557
|
const infiniteScrollAmp = new InfiniteScrollAmp({
|
|
268
558
|
ampConfig: {},
|
|
@@ -270,11 +560,11 @@ describe("getResponse method of InfiniteScrollAmp helper function", function ()
|
|
|
270
560
|
publisherConfig: dummyPublisherConfig,
|
|
271
561
|
queryParams: { "story-id": 4444 },
|
|
272
562
|
});
|
|
273
|
-
const jsonResponse = await infiniteScrollAmp.getResponse(
|
|
563
|
+
const jsonResponse = await infiniteScrollAmp.getResponse();
|
|
274
564
|
assert.strictEqual(false, /sports\/dd/.test(jsonResponse));
|
|
275
565
|
assert.strictEqual(false, /dd\/d.jpg/.test(jsonResponse));
|
|
276
566
|
});
|
|
277
|
-
it("should remove visual stories from response", async function () {
|
|
567
|
+
it("should remove visual stories from Collection response", async function () {
|
|
278
568
|
const clientStub = getClientStub();
|
|
279
569
|
const infiniteScrollAmp = new InfiniteScrollAmp({
|
|
280
570
|
ampConfig: {},
|
|
@@ -282,11 +572,11 @@ describe("getResponse method of InfiniteScrollAmp helper function", function ()
|
|
|
282
572
|
publisherConfig: dummyPublisherConfig,
|
|
283
573
|
queryParams: { "story-id": 4444 },
|
|
284
574
|
});
|
|
285
|
-
const jsonResponse = await infiniteScrollAmp.getResponse(
|
|
575
|
+
const jsonResponse = await infiniteScrollAmp.getResponse();
|
|
286
576
|
assert.strictEqual(false, /sports\/bb/.test(jsonResponse));
|
|
287
577
|
assert.strictEqual(false, /bb\/b.jpg/.test(jsonResponse));
|
|
288
578
|
});
|
|
289
|
-
it("should format JSON as per AMP spec", async function () {
|
|
579
|
+
it("should format Collection JSON as per AMP spec", async function () {
|
|
290
580
|
// https://amp.dev/documentation/components/amp-next-page/
|
|
291
581
|
const clientStub = getClientStub();
|
|
292
582
|
const infiniteScrollAmp = new InfiniteScrollAmp({
|
|
@@ -295,7 +585,7 @@ describe("getResponse method of InfiniteScrollAmp helper function", function ()
|
|
|
295
585
|
publisherConfig: dummyPublisherConfig,
|
|
296
586
|
queryParams: { "story-id": 4444 },
|
|
297
587
|
});
|
|
298
|
-
const jsonResponse = await infiniteScrollAmp.getResponse(
|
|
588
|
+
const jsonResponse = await infiniteScrollAmp.getResponse();
|
|
299
589
|
function isJsonConfigStructureValid(jsonStr) {
|
|
300
590
|
const parsed = JSON.parse(jsonStr);
|
|
301
591
|
const stories = parsed.pages;
|
|
@@ -312,4 +602,120 @@ describe("getResponse method of InfiniteScrollAmp helper function", function ()
|
|
|
312
602
|
// it("should omit the first 'n' stories, take the rest", async function() {
|
|
313
603
|
// // this test needs to be written after https://github.com/quintype/quintype-node-framework/pull/202 is merged
|
|
314
604
|
// })
|
|
605
|
+
// related-stories
|
|
606
|
+
it("should throw an error in relatedStoriesApi if 'story-id' isn't passed as query param", async function () {
|
|
607
|
+
const infiniteScrollAmp = new InfiniteScrollAmp({
|
|
608
|
+
ampConfig: {},
|
|
609
|
+
client: getClientStub(),
|
|
610
|
+
publisherConfig: dummyPublisherConfig,
|
|
611
|
+
queryParams: { foo: "bar" },
|
|
612
|
+
infiniteScrollSource: "relatedStoriesApi",
|
|
613
|
+
});
|
|
614
|
+
const jsonResponse = await infiniteScrollAmp.getResponse();
|
|
615
|
+
assert.strictEqual(jsonResponse instanceof Error, true);
|
|
616
|
+
assert.throws(() => {
|
|
617
|
+
throw new Error(`Query param "story-id" missing`);
|
|
618
|
+
}, jsonResponse);
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
it("should throw an error if relatedStoriesApi scroll collection doesn't exist", async function () {
|
|
622
|
+
const clientStub = getClientStub({
|
|
623
|
+
getRelatedStories: () =>
|
|
624
|
+
new Promise((resolve) => {
|
|
625
|
+
resolve(null);
|
|
626
|
+
}),
|
|
627
|
+
});
|
|
628
|
+
const infiniteScrollAmp = new InfiniteScrollAmp({
|
|
629
|
+
ampConfig: {},
|
|
630
|
+
client: clientStub,
|
|
631
|
+
publisherConfig: dummyPublisherConfig,
|
|
632
|
+
queryParams: { "story-id": 2222 },
|
|
633
|
+
infiniteScrollSource: "relatedStoriesApi",
|
|
634
|
+
});
|
|
635
|
+
const jsonResponse = await infiniteScrollAmp.getResponse();
|
|
636
|
+
assert.strictEqual(jsonResponse instanceof Error, true);
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
it("should remove visual stories from relatedStoriesApi response", async function () {
|
|
640
|
+
const clientStub = getClientStub();
|
|
641
|
+
const infiniteScrollAmp = new InfiniteScrollAmp({
|
|
642
|
+
ampConfig: {},
|
|
643
|
+
client: clientStub,
|
|
644
|
+
publisherConfig: dummyPublisherConfig,
|
|
645
|
+
queryParams: { "story-id": 4444 },
|
|
646
|
+
infiniteScrollSource: "relatedStoriesApi",
|
|
647
|
+
});
|
|
648
|
+
const jsonResponse = await infiniteScrollAmp.getResponse();
|
|
649
|
+
assert.strictEqual(false, /sports\/bb/.test(jsonResponse));
|
|
650
|
+
assert.strictEqual(false, /bb\/b.jpg/.test(jsonResponse));
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
it("should format relatedStoriesApi JSON as per AMP spec", async function () {
|
|
654
|
+
// https://amp.dev/documentation/components/amp-next-page/
|
|
655
|
+
const clientStub = getClientStub();
|
|
656
|
+
const infiniteScrollAmp = new InfiniteScrollAmp({
|
|
657
|
+
ampConfig: {},
|
|
658
|
+
client: clientStub,
|
|
659
|
+
publisherConfig: dummyPublisherConfig,
|
|
660
|
+
queryParams: { "story-id": 4444 },
|
|
661
|
+
infiniteScrollSource: "relatedStoriesApi",
|
|
662
|
+
});
|
|
663
|
+
const jsonResponse = await infiniteScrollAmp.getResponse();
|
|
664
|
+
function isJsonConfigStructureValid(jsonStr) {
|
|
665
|
+
const parsed = JSON.parse(jsonStr);
|
|
666
|
+
const stories = parsed.pages;
|
|
667
|
+
if (!stories.length) throw new Error("Can't verify empty array!");
|
|
668
|
+
stories.forEach((story) => {
|
|
669
|
+
const keys = Object.keys(story);
|
|
670
|
+
if (keys.includes("image") && keys.includes("url") && keys.includes("title") && keys.length === 3) return;
|
|
671
|
+
throw new Error("Invalid InlineConfigStructure");
|
|
672
|
+
});
|
|
673
|
+
return true;
|
|
674
|
+
}
|
|
675
|
+
assert.strictEqual(isJsonConfigStructureValid(jsonResponse), true);
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
// custom-stories
|
|
679
|
+
it("should throw an error if customApi infinite scroll collection doesn't exist", async function () {
|
|
680
|
+
const clientStub = getCustomApiStoriesClientStub({
|
|
681
|
+
getCustomApiStories: () =>
|
|
682
|
+
new Promise((resolve) => {
|
|
683
|
+
resolve(null);
|
|
684
|
+
}),
|
|
685
|
+
});
|
|
686
|
+
const customInfiniteScrollAmp = new CustomInfiniteScrollAmp({
|
|
687
|
+
client: clientStub,
|
|
688
|
+
publisherConfig: dummyPublisherConfig,
|
|
689
|
+
infiniteScrollSource: "custom",
|
|
690
|
+
});
|
|
691
|
+
const jsonResponse = await customInfiniteScrollAmp.getCustomStoryList({
|
|
692
|
+
type: "remoteConfig",
|
|
693
|
+
});
|
|
694
|
+
assert.strictEqual(jsonResponse instanceof Error, true);
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
it("should format JSON as per AMP spec in customApi list", async function () {
|
|
698
|
+
// https://amp.dev/documentation/components/amp-next-page/
|
|
699
|
+
const clientStub = getCustomApiStoriesClientStub();
|
|
700
|
+
const customInfiniteScrollAmp = new CustomInfiniteScrollAmp({
|
|
701
|
+
client: clientStub,
|
|
702
|
+
publisherConfig: dummyPublisherConfig,
|
|
703
|
+
infiniteScrollSource: "custom",
|
|
704
|
+
});
|
|
705
|
+
const jsonResponse = await customInfiniteScrollAmp.getCustomStoryList({
|
|
706
|
+
type: "remoteConfig",
|
|
707
|
+
});
|
|
708
|
+
function isJsonConfigStructureValid(jsonStr) {
|
|
709
|
+
const parsed = JSON.parse(jsonStr);
|
|
710
|
+
const stories = parsed.pages;
|
|
711
|
+
if (!stories.length) throw new Error("Can't verify empty array!");
|
|
712
|
+
stories.forEach((story) => {
|
|
713
|
+
const keys = Object.keys(story);
|
|
714
|
+
if (keys.includes("image") && keys.includes("url") && keys.includes("title") && keys.length === 3) return;
|
|
715
|
+
throw new Error("Invalid InlineConfigStructure");
|
|
716
|
+
});
|
|
717
|
+
return true;
|
|
718
|
+
}
|
|
719
|
+
assert.strictEqual(isJsonConfigStructureValid(jsonResponse), true);
|
|
720
|
+
});
|
|
315
721
|
});
|