@quintype/framework 7.9.0-custom-inifinite-scroller.2 → 7.9.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,13 @@
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.9.0](https://github.com/quintype/quintype-node-framework/compare/v7.8.0...v7.9.0) (2022-10-03)
6
+
7
+
8
+ ### Features
9
+
10
+ * **SW:** Disable sw shell ([#321](https://github.com/quintype/quintype-node-framework/issues/321)) ([6d04bc8](https://github.com/quintype/quintype-node-framework/commit/6d04bc87dd42c647ec9763eca430ada2f4a4d8ea))
11
+
5
12
  ## [7.8.0](https://github.com/quintype/quintype-node-framework/compare/v7.7.7...v7.8.0) (2022-09-19)
6
13
 
7
14
 
@@ -1,17 +1,17 @@
1
1
  import { SERVICE_WORKER_UPDATED } from "@quintype/components";
2
2
 
3
3
  export function registerServiceWorker({
4
- enableServiceWorker = false,
5
- serviceWorkerLocation = "/service-worker.js",
6
- navigator = global.navigator,
7
- mountAt = global.qtMountAt || "",
8
- version = 0,
9
- }) {
4
+ enableServiceWorker = false,
5
+ serviceWorkerLocation = "/service-worker.js",
6
+ navigator = global.navigator,
7
+ mountAt = global.qtMountAt || "",
8
+ version = 0,
9
+ }) {
10
10
  if (enableServiceWorker && navigator.serviceWorker) {
11
11
  const location =
12
- serviceWorkerLocation === "/OneSignalSDKWorker.js"
13
- ? `${serviceWorkerLocation}?version=${version}`
14
- : serviceWorkerLocation;
12
+ serviceWorkerLocation === "/OneSignalSDKWorker.js"
13
+ ? `${serviceWorkerLocation}?version=${version}`
14
+ : serviceWorkerLocation;
15
15
  return navigator.serviceWorker.register(`${mountAt}${location}`);
16
16
  }
17
17
  return Promise.resolve(null);
@@ -22,7 +22,7 @@ function updateOneSignalWorker(appVersion, page, opts) {
22
22
  const version = pageThemeAttributes["cache-burst"] || appVersion;
23
23
 
24
24
  registerServiceWorker({ ...opts, serviceWorkerLocation: "/OneSignalSDKWorker.js", version }).then(() =>
25
- console.log("Updated OneSignal Worker")
25
+ console.log("Updated OneSignal Worker")
26
26
  );
27
27
  }
28
28
 
@@ -34,7 +34,7 @@ export function setupServiceWorkerUpdates(serviceWorkerPromise, app, store, page
34
34
 
35
35
  if (registration.update) {
36
36
  app.updateServiceWorker = () =>
37
- registration.update().then(() => store.dispatch({ type: SERVICE_WORKER_UPDATED }));
37
+ registration.update().then(() => store.dispatch({ type: SERVICE_WORKER_UPDATED }));
38
38
 
39
39
  if (global.OneSignal) {
40
40
  const appVersion = app.getAppVersion();
@@ -56,9 +56,20 @@ function updateServiceWorker(app) {
56
56
  }
57
57
  }
58
58
 
59
+ function clearServiceWorkerCache() {
60
+ if ('serviceWorker' in navigator) {
61
+ caches.keys().then(function(cacheNames) {
62
+ cacheNames.forEach(function(cacheName) {
63
+ caches.delete(cacheName);
64
+ });
65
+ });
66
+ }
67
+ }
68
+
59
69
  export function checkForServiceWorkerUpdates(app, page = {}) {
60
70
  if (page.appVersion && app.getAppVersion && app.getAppVersion() < page.appVersion) {
61
71
  console && console.log("Updating the Service Worker");
72
+ clearServiceWorkerCache();
62
73
  updateServiceWorker(app);
63
74
  } else if (global && global.qtVersion) {
64
75
  /* Check if the config is updated and update the service worker if true */
@@ -66,6 +77,7 @@ export function checkForServiceWorkerUpdates(app, page = {}) {
66
77
  const { config: { "theme-attributes": pageThemeAttributes = {} } = {} } = page;
67
78
  if ((pageThemeAttributes["cache-burst"] || 0) > parseInt(configVersion)) {
68
79
  console.log(`Updating service worker due to config change`);
80
+ clearServiceWorkerCache();
69
81
  updateServiceWorker(app);
70
82
  }
71
83
  }
package/client/start.js CHANGED
@@ -55,20 +55,20 @@ function getRouteData(path, { location = global.location, existingFetch, mountAt
55
55
  const [routeDataPath, relativePath] = getRouteDataAndPath(path, mountAt);
56
56
  const url = new URL(relativePath, location.origin);
57
57
  return (
58
- existingFetch ||
59
- fetch(`${routeDataPath}?path=${encodeURIComponent(url.pathname)}${url.search ? `&${url.search.slice(1)}` : ""}`, {
60
- credentials: "same-origin",
61
- })
58
+ existingFetch ||
59
+ fetch(`${routeDataPath}?path=${encodeURIComponent(url.pathname)}${url.search ? `&${url.search.slice(1)}` : ""}`, {
60
+ credentials: "same-origin",
61
+ })
62
62
  )
63
- .then((response) => {
64
- if (response.status == 404) {
65
- // There is a chance this might abort
66
- maybeBypassServiceWorker();
67
- }
63
+ .then((response) => {
64
+ if (response.status == 404) {
65
+ // There is a chance this might abort
66
+ maybeBypassServiceWorker();
67
+ }
68
68
 
69
- return response.json();
70
- })
71
- .then(maybeRedirect);
69
+ return response.json();
70
+ })
71
+ .then(maybeRedirect);
72
72
 
73
73
  function maybeRedirect(page) {
74
74
  // This next line aborts the entire load
@@ -123,7 +123,7 @@ export function navigateToPage(dispatch, path, doNotPushPath) {
123
123
  }
124
124
 
125
125
  Promise.resolve(
126
- pickComponentWrapper && pickComponentWrapper.preloadComponent(page.pageType, page.subPageType)
126
+ pickComponentWrapper && pickComponentWrapper.preloadComponent(page.pageType, page.subPageType)
127
127
  ).then(() => {
128
128
  dispatch({
129
129
  type: NAVIGATE_TO_PAGE,
@@ -181,10 +181,17 @@ export function maybeSetUrl(path, title) {
181
181
  export function renderComponent(clazz, container, store, props = {}, callback) {
182
182
  const component = React.createElement(Provider, { store }, React.createElement(clazz, props || {}));
183
183
 
184
+ const containerEle = document.getElementById(container);
185
+
186
+ if(!containerEle){
187
+ console && console.log(`Rendering component on DOM id ${container} FAILED, node not available`);
188
+ return null;
189
+ }
190
+
184
191
  if (props.hydrate) {
185
- return ReactDOM.hydrate(component, document.getElementById(container), callback);
192
+ return ReactDOM.hydrate(component, containerEle, callback);
186
193
  }
187
- return ReactDOM.render(component, document.getElementById(container), callback);
194
+ return ReactDOM.render(component, containerEle, callback);
188
195
  }
189
196
 
190
197
  /**
@@ -199,16 +206,16 @@ export function renderIsomorphicComponent(container, store, pickComponent, props
199
206
  if (!store.getState().qt.disableIsomorphicComponent) {
200
207
  pickComponentWrapper = makePickComponentSync(pickComponent);
201
208
  return pickComponentWrapper
202
- .preloadComponent(store.getState().qt.pageType, store.getState().qt.subPageType)
203
- .then(() =>
204
- renderComponent(
205
- IsomorphicComponent,
206
- container,
207
- store,
208
- Object.assign({ pickComponent: pickComponentWrapper }, props),
209
- () => store.dispatch({ type: CLIENT_SIDE_RENDERED })
210
- )
211
- );
209
+ .preloadComponent(store.getState().qt.pageType, store.getState().qt.subPageType)
210
+ .then(() =>
211
+ renderComponent(
212
+ IsomorphicComponent,
213
+ container,
214
+ store,
215
+ Object.assign({ pickComponent: pickComponentWrapper }, props),
216
+ () => store.dispatch({ type: CLIENT_SIDE_RENDERED })
217
+ )
218
+ );
212
219
  }
213
220
  console && console.log("IsomorphicComponent is disabled");
214
221
  }
@@ -257,15 +264,15 @@ export function startApp(renderApplication, reducers, opts) {
257
264
  const path = `${location.pathname}${location.search || ""}`;
258
265
  const staticData = global.staticPageStoreContent || getJsonContent("static-page");
259
266
  const dataPromise = staticData
260
- ? Promise.resolve(staticData.qt)
261
- : getRouteData(path, { existingFetch: global.initialFetch });
267
+ ? Promise.resolve(staticData.qt)
268
+ : getRouteData(path, { existingFetch: global.initialFetch });
262
269
 
263
270
  startAnalytics();
264
271
 
265
272
  const store = createQtStore(
266
- reducers,
267
- (staticData && staticData.qt) || global.initialPage || getJsonContent("initial-page") || {},
268
- {}
273
+ reducers,
274
+ (staticData && staticData.qt) || global.initialPage || getJsonContent("initial-page") || {},
275
+ {}
269
276
  );
270
277
 
271
278
  if (opts.preRenderApplication) {
@@ -307,9 +314,9 @@ export function startApp(renderApplication, reducers, opts) {
307
314
 
308
315
  if (page.title) {
309
316
  global.document.title = get(
310
- page,
311
- ["data", "customSeo", "title"],
312
- get(page, ["data", "story", "seo", "meta-title"], page.title)
317
+ page,
318
+ ["data", "customSeo", "title"],
319
+ get(page, ["data", "story", "seo", "meta-title"], page.title)
313
320
  );
314
321
  }
315
322
  return store;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/framework",
3
- "version": "7.9.0-custom-inifinite-scroller.2",
3
+ "version": "7.9.0",
4
4
  "description": "Libraries to help build Quintype Node.js apps",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -31,8 +31,8 @@
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.6.0-custom-infinite-scroll.1",
35
- "@quintype/backend": "2.3.2-related-stories-inf-scroll.3",
34
+ "@quintype/amp": "^2.5.0",
35
+ "@quintype/backend": "^2.3.1",
36
36
  "@quintype/components": "^3.0.0",
37
37
  "@quintype/prerender-node": "^3.2.26",
38
38
  "@quintype/seo": "^1.39.0",
@@ -1,23 +1,18 @@
1
1
  const { AmpConfig } = require("../../impl/api-client-impl");
2
2
  const InfiniteScrollAmp = require("../helpers/infinite-scroll");
3
3
  const { setCorsHeaders } = require("../helpers");
4
- const get = require("lodash/get");
5
- const cloneDeep = require("lodash/cloneDeep");
6
4
 
7
5
  // eslint-disable-next-line consistent-return
8
- async function storyPageInfiniteScrollHandler(req, res, next, { client, config, ...rest }) {
6
+ async function storyPageInfiniteScrollHandler(req, res, next, { client, config }) {
9
7
  const ampConfig = await config.memoizeAsync("amp-config", async () => await AmpConfig.getAmpConfig(client));
10
- const opts = cloneDeep(rest);
11
- const infiniteScrollSource = get(opts, ["featureConfig", "infiniteScroll", "source"], "collection");
12
8
 
13
9
  const infiniteScrollAmp = new InfiniteScrollAmp({
14
10
  ampConfig,
15
11
  publisherConfig: config,
16
12
  client,
17
13
  queryParams: req.query,
18
- infiniteScrollSource,
19
14
  });
20
- const jsonResponse = await infiniteScrollAmp.getResponse();
15
+ const jsonResponse = await infiniteScrollAmp.getResponse({ itemsTaken: 5 }); // itemsTaken has to match with itemsToTake in ampStoryPageHandler
21
16
  if (jsonResponse instanceof Error) return next(jsonResponse);
22
17
  res.set("Content-Type", "application/json; charset=utf-8");
23
18
  setCorsHeaders({ req, res, next, publisherConfig: config });
@@ -86,28 +86,15 @@ async function ampStoryPageHandler(
86
86
  const seoTags =
87
87
  seoInstance && seoInstance.getMetaTags(config, "story-page-amp", { data: { story, timezone }, config }, { url });
88
88
 
89
- const infiniteScrollConfig = get(opts, ["featureConfig", "infiniteScroll"], "");
90
- const infiniteScrollSource = get(infiniteScrollConfig, ["source"], "collection");
91
- const inlineConfig = get(infiniteScrollConfig, ["inlineConfig"], "");
92
- const remoteConfigEndpoint = get(infiniteScrollConfig, ["remoteConfigEndpoint"], "");
93
-
94
- let infiniteScrollInlineConfig = [];
95
-
96
- if (infiniteScrollSource === "custom") {
97
- if (!inlineConfig || !remoteConfigEndpoint)
98
- throw new Error("Required params of 'custom' source (inlineConfig /remoteConfigEndpoint) is missing!!");
99
- infiniteScrollInlineConfig = await inlineConfig();
100
- } else {
101
- const infiniteScrollAmp = new InfiniteScrollAmp({
102
- ampConfig,
103
- publisherConfig: config,
104
- client,
105
- infiniteScrollSource,
106
- });
107
- infiniteScrollInlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
108
- storyId: story["story-content-id"],
109
- });
110
- }
89
+ const infiniteScrollAmp = new InfiniteScrollAmp({
90
+ ampConfig,
91
+ publisherConfig: config,
92
+ client,
93
+ });
94
+ const infiniteScrollInlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
95
+ itemsToTake: 5,
96
+ storyId: story["story-content-id"],
97
+ });
111
98
  if (infiniteScrollInlineConfig instanceof Error) return next(infiniteScrollInlineConfig);
112
99
  if (infiniteScrollInlineConfig) {
113
100
  set(
@@ -1,9 +1,9 @@
1
1
  class InfiniteScrollAmp {
2
- constructor({ ampConfig, client, publisherConfig, queryParams, infiniteScrollSource }) {
2
+ constructor({ ampConfig, client, publisherConfig, queryParams }) {
3
3
  this.client = client;
4
4
  this.publisherConfig = publisherConfig;
5
5
  this.queryParams = queryParams;
6
- this.infiniteScrollSource = infiniteScrollSource;
6
+ this.collSlug = "amp-infinite-scroll"; // this is hardcoded to "amp-infinite-scroll" temporarily. Ideally it should come from ampConfig from platform
7
7
  }
8
8
 
9
9
  // eslint-disable-next-line class-methods-use-this
@@ -17,20 +17,12 @@ class InfiniteScrollAmp {
17
17
  );
18
18
  }
19
19
 
20
- getFilteredApiItems(relatedStories) {
21
- return relatedStories.filter(
22
- (story) =>
23
- story.access !== "subscription" &&
24
- story["story-template"] !== "visual-story"
25
- );
26
- }
27
-
28
20
  formatData({ itemsArr, type }) {
29
21
  // formats configuration as per need of amp infinite scroll
30
22
  const arr = itemsArr.map((item) => ({
31
23
  image: this.getImagePath(item),
32
- title: item.headline,
33
- url: `/amp/story/${item.slug}`,
24
+ title: item.story.headline,
25
+ url: `/amp/story/${item.story.slug}`,
34
26
  }));
35
27
  switch (type) {
36
28
  case "inline":
@@ -44,51 +36,39 @@ class InfiniteScrollAmp {
44
36
 
45
37
  getImagePath(item) {
46
38
  const cdnImage = this.publisherConfig["cdn-image"];
47
- const s3Key = item["hero-image-s3-key"];
39
+ const s3Key = item.story["hero-image-s3-key"];
48
40
  const hostWithProtocol = /^https:\/\//.test(cdnImage) ? cdnImage : `https://${cdnImage}`;
49
41
  return `${hostWithProtocol}/${s3Key}?format=webp&w=250`;
50
42
  }
51
43
 
52
- async getInfiniteScrollList({ storyId, type, offset = 0, limit = null }) {
53
- let filteredItems = [];
54
- const params = { offset, limit };
55
- if (this.infiniteScrollSource === "relatedStoriesApi") {
56
- const relatedStoriesList = await this.client.getRelatedStories(storyId, null, params);
57
- if (!relatedStoriesList)
58
- return new Error();
59
- return filteredItems = this.getFilteredApiItems(relatedStoriesList["related-stories"]);
60
- } else {
61
- const collection = await this.client.getCollectionBySlug("amp-infinite-scroll");
62
- if (!collection || (collection.items && !collection.items.length) || collection.error || collection === null)
63
- return new Error();
64
- const collectionItems = this.getFilteredCollItems(collection, storyId).map(items => items.story);
65
- return filteredItems = type === "inlineConfig"
66
- ? collectionItems.slice(0, 5)
67
- : collectionItems.slice(5);
68
- }
69
- }
70
-
71
- async getResponse() {
44
+ async getResponse({ itemsTaken }) {
72
45
  const { "story-id": storyId } = this.queryParams;
73
46
  if (!storyId) return new Error(`Query param "story-id" missing`);
74
- const filteredItems =
75
- await this.getInfiniteScrollList({ storyId, type: "remoteConfig", offset: 5 });
76
- if (filteredItems instanceof Error) return new Error(`Infinite scroll collection amp-infinite-scroll returned falsy value`);
77
- const formattedData = this.formatData({ itemsArr: filteredItems });
47
+
48
+ const collection = await this.client.getCollectionBySlug(this.collSlug);
49
+ if (!collection || collection.error)
50
+ return new Error(`Infinite scroll collection ${this.collSlug} returned falsy value`);
51
+ const filteredItems = this.getFilteredCollItems(collection, storyId);
52
+ const slicedItems = filteredItems.slice(itemsTaken);
53
+ const formattedData = this.formatData({ itemsArr: slicedItems });
54
+
78
55
  return JSON.stringify(formattedData);
79
56
  }
80
57
 
81
- async getInitialInlineConfig(storyId) {
82
- if (!storyId) return new Error("Required params for getInitialInlineConfig missing");
83
- const filteredItems =
84
- await this.getInfiniteScrollList({ storyId, type: "inlineConfig", offset: 0, limit: 5 });
58
+ async getInitialInlineConfig({ itemsToTake, storyId }) {
59
+ if (!itemsToTake || !storyId) return new Error("Required params for getInitialInlineConfig missing");
85
60
 
86
- if (filteredItems instanceof Error) return null;
87
- const formattedData = filteredItems.length > 0 && this.formatData({
88
- itemsArr: filteredItems,
61
+ const collection = await this.client.getCollectionBySlug(this.collSlug);
62
+ if (!collection || (collection.items && !collection.items.length) || collection.error) return null;
63
+ const filteredItems = this.getFilteredCollItems(collection, storyId);
64
+ const slicedItems = filteredItems.slice(0, itemsToTake);
65
+ const formattedData = this.formatData({
66
+ itemsArr: slicedItems,
89
67
  type: "inline",
90
68
  });
69
+
91
70
  return JSON.stringify(formattedData);
92
71
  }
93
72
  }
73
+
94
74
  module.exports = InfiniteScrollAmp;
@@ -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")
@@ -28,7 +19,6 @@ function getClientStub({
28
19
  "story-content-id": 1111,
29
20
  slug: "sports/aa",
30
21
  "hero-image-s3-key": "aa/a.jpg",
31
- access: "public",
32
22
  },
33
23
  },
34
24
  {
@@ -40,7 +30,6 @@ function getClientStub({
40
30
  "story-content-id": 2222,
41
31
  slug: "sports/bb",
42
32
  "hero-image-s3-key": "bb/b.jpg",
43
- access: "public",
44
33
  },
45
34
  },
46
35
  {
@@ -52,7 +41,6 @@ function getClientStub({
52
41
  "story-content-id": 3333,
53
42
  slug: "sports/cc",
54
43
  "hero-image-s3-key": "cc/c.jpg",
55
- access: "public",
56
44
  },
57
45
  },
58
46
  {
@@ -64,7 +52,6 @@ function getClientStub({
64
52
  "story-content-id": 4444,
65
53
  slug: "sports/dd",
66
54
  "hero-image-s3-key": "dd/d.jpg",
67
- access: "public",
68
55
  },
69
56
  },
70
57
  {
@@ -76,7 +63,6 @@ function getClientStub({
76
63
  "story-content-id": 5555,
77
64
  slug: "sports/ee",
78
65
  "hero-image-s3-key": "ee/e.jpg",
79
- access: "public",
80
66
  },
81
67
  },
82
68
  {
@@ -88,31 +74,6 @@ function getClientStub({
88
74
  "story-content-id": 6666,
89
75
  slug: "sports/ff",
90
76
  "hero-image-s3-key": "ff/f.jpg",
91
- access: "public",
92
- },
93
- },
94
- {
95
- type: "story",
96
- id: 7777,
97
- story: {
98
- "story-template": "text",
99
- headline: "ggg",
100
- "story-content-id": 7777,
101
- slug: "sports/gg",
102
- "hero-image-s3-key": "gg/g.jpg",
103
- access: "public",
104
- },
105
- },
106
- {
107
- type: "story",
108
- id: 8888,
109
- story: {
110
- "story-template": "text",
111
- headline: "hhh",
112
- "story-content-id": 8888,
113
- slug: "sports/hh",
114
- "hero-image-s3-key": "hh/h.jpg",
115
- access: "public",
116
77
  },
117
78
  },
118
79
  ],
@@ -122,7 +83,6 @@ function getClientStub({
122
83
  } = {}) {
123
84
  return {
124
85
  getCollectionBySlug,
125
- getStoryById
126
86
  };
127
87
  }
128
88
  const dummyPublisherConfig = {
@@ -136,7 +96,9 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
136
96
  client: getClientStub(),
137
97
  publisherConfig: dummyPublisherConfig,
138
98
  });
139
- const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig();
99
+ const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
100
+ itemsToTake: 5,
101
+ });
140
102
  assert.strictEqual(inlineConfig instanceof Error, true);
141
103
  assert.throws(() => {
142
104
  throw new Error("Required params for getInitialInlineConfig missing");
@@ -155,7 +117,8 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
155
117
  publisherConfig: dummyPublisherConfig,
156
118
  });
157
119
  const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
158
- storyId: 1111,
120
+ itemsToTake: 5,
121
+ storyId: 2222,
159
122
  });
160
123
  assert.strictEqual(inlineConfig, null);
161
124
  });
@@ -174,7 +137,8 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
174
137
  publisherConfig: dummyPublisherConfig,
175
138
  });
176
139
  const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
177
- storyId: 1111,
140
+ itemsToTake: 5,
141
+ storyId: 2222,
178
142
  });
179
143
  assert.strictEqual(inlineConfig, null);
180
144
  });
@@ -186,7 +150,8 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
186
150
  publisherConfig: dummyPublisherConfig,
187
151
  });
188
152
  const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
189
- storyId: 1111,
153
+ itemsToTake: 5,
154
+ storyId: 2222,
190
155
  });
191
156
  assert.strictEqual(false, /sports\/bb/.test(inlineConfig));
192
157
  assert.strictEqual(false, /bb\/b.jpg/.test(inlineConfig));
@@ -199,7 +164,8 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
199
164
  publisherConfig: dummyPublisherConfig,
200
165
  });
201
166
  const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
202
- storyId: 1111,
167
+ itemsToTake: 5,
168
+ storyId: 3333,
203
169
  });
204
170
  assert.strictEqual(false, /sports\/bb/.test(inlineConfig));
205
171
  assert.strictEqual(false, /bb\/b.jpg/.test(inlineConfig));
@@ -213,7 +179,8 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
213
179
  publisherConfig: dummyPublisherConfig,
214
180
  });
215
181
  const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
216
- storyId: 1111,
182
+ itemsToTake: 5,
183
+ storyId: 2222,
217
184
  });
218
185
  function isInlineConfigStructureValid(jsonStr) {
219
186
  const stories = JSON.parse(jsonStr);
@@ -240,7 +207,7 @@ describe("getResponse method of InfiniteScrollAmp helper function", function ()
240
207
  publisherConfig: dummyPublisherConfig,
241
208
  queryParams: { foo: "bar" },
242
209
  });
243
- const jsonResponse = await infiniteScrollAmp.getResponse();
210
+ const jsonResponse = await infiniteScrollAmp.getResponse({ itemsTaken: 2 });
244
211
  assert.strictEqual(jsonResponse instanceof Error, true);
245
212
  assert.throws(() => {
246
213
  throw new Error(`Query param "story-id" missing`);
@@ -259,7 +226,7 @@ describe("getResponse method of InfiniteScrollAmp helper function", function ()
259
226
  publisherConfig: dummyPublisherConfig,
260
227
  queryParams: { "story-id": 2222 },
261
228
  });
262
- const jsonResponse = await infiniteScrollAmp.getResponse();
229
+ const jsonResponse = await infiniteScrollAmp.getResponse({ itemsTaken: 2 });
263
230
  assert.strictEqual(jsonResponse instanceof Error, true);
264
231
  });
265
232
  it("should remove current story from response", async function () {
@@ -270,7 +237,7 @@ describe("getResponse method of InfiniteScrollAmp helper function", function ()
270
237
  publisherConfig: dummyPublisherConfig,
271
238
  queryParams: { "story-id": 4444 },
272
239
  });
273
- const jsonResponse = await infiniteScrollAmp.getResponse();
240
+ const jsonResponse = await infiniteScrollAmp.getResponse({ itemsTaken: 2 });
274
241
  assert.strictEqual(false, /sports\/dd/.test(jsonResponse));
275
242
  assert.strictEqual(false, /dd\/d.jpg/.test(jsonResponse));
276
243
  });
@@ -282,7 +249,7 @@ describe("getResponse method of InfiniteScrollAmp helper function", function ()
282
249
  publisherConfig: dummyPublisherConfig,
283
250
  queryParams: { "story-id": 4444 },
284
251
  });
285
- const jsonResponse = await infiniteScrollAmp.getResponse();
252
+ const jsonResponse = await infiniteScrollAmp.getResponse({ itemsTaken: 2 });
286
253
  assert.strictEqual(false, /sports\/bb/.test(jsonResponse));
287
254
  assert.strictEqual(false, /bb\/b.jpg/.test(jsonResponse));
288
255
  });
@@ -295,8 +262,7 @@ describe("getResponse method of InfiniteScrollAmp helper function", function ()
295
262
  publisherConfig: dummyPublisherConfig,
296
263
  queryParams: { "story-id": 4444 },
297
264
  });
298
- const jsonResponse = await infiniteScrollAmp.getResponse();
299
-
265
+ const jsonResponse = await infiniteScrollAmp.getResponse({ itemsTaken: 2 });
300
266
  function isJsonConfigStructureValid(jsonStr) {
301
267
  const parsed = JSON.parse(jsonStr);
302
268
  const stories = parsed.pages;