@apolitical/content 0.2.1 → 0.3.0-beta.2
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 +14 -0
- package/README.md +1 -1
- package/build/index.js +1 -1
- package/package.json +49 -51
- package/.gitlab-ci.yml +0 -81
- package/default.env +0 -1
- package/lib/config.js +0 -27
- package/lib/helper/context.js +0 -79
- package/lib/helper/index.js +0 -8
- package/lib/index.js +0 -35
- package/lib/parser/asset.js +0 -19
- package/lib/parser/entry.js +0 -34
- package/lib/parser/fields.js +0 -12
- package/lib/parser/index.js +0 -31
- package/lib/parser/locale.js +0 -24
- package/test/unit/__snapshots__/lib.spec.js.snap +0 -492
- package/test/unit/lib.spec.js +0 -130
- package/test/unit/mocks/microcourse.mock.js +0 -819
- package/test/unit/mocks/microcourses.mock.js +0 -11
- package/webpack.config.js +0 -28
|
@@ -1,492 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`Apolitical Content Global context Get Entry should read entry 1`] = `
|
|
4
|
-
Object {
|
|
5
|
-
"banner": "//images.ctfassets.net/some-image-1.jpg",
|
|
6
|
-
"curriculum": "some-curriculum",
|
|
7
|
-
"editions": Array [
|
|
8
|
-
Object {
|
|
9
|
-
"endDate": "2020-12-11T12:00:00.000Z",
|
|
10
|
-
"id": 1,
|
|
11
|
-
"startDate": "2020-11-09T00:00:00.000Z",
|
|
12
|
-
"title": "some-slug_edition_1",
|
|
13
|
-
"workshopDate": "2019-10-07T19:30:00.000Z",
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
"experts": Array [
|
|
17
|
-
Object {
|
|
18
|
-
"country": "Some Country 1",
|
|
19
|
-
"fullName": "Some Full Name 1",
|
|
20
|
-
"jobTitle": "Some Job Title 1",
|
|
21
|
-
"organisation": "Some Organization 1",
|
|
22
|
-
"photo": "//images.ctfassets.net/some-image-2.jpeg",
|
|
23
|
-
},
|
|
24
|
-
Object {
|
|
25
|
-
"country": "Some Country 2",
|
|
26
|
-
"fullName": "Some Full Name 2",
|
|
27
|
-
"jobTitle": "Some Job Title 2",
|
|
28
|
-
"organisation": "Some Organization 2",
|
|
29
|
-
"photo": "//images.ctfassets.net/some-photo-3",
|
|
30
|
-
},
|
|
31
|
-
Object {
|
|
32
|
-
"country": "Some Country 3",
|
|
33
|
-
"fullName": "Some Full Name 3",
|
|
34
|
-
"jobTitle": "Some Job Title 3",
|
|
35
|
-
"organisation": "Some Organization 3",
|
|
36
|
-
"photo": null,
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
"hideTimes": true,
|
|
40
|
-
"id": 3662,
|
|
41
|
-
"manager": Object {
|
|
42
|
-
"id": 63564,
|
|
43
|
-
"slug": "some-manager-slug",
|
|
44
|
-
},
|
|
45
|
-
"reviewers": Array [
|
|
46
|
-
Object {
|
|
47
|
-
"country": "Some Country 4",
|
|
48
|
-
"fullName": "Some Full Name 4",
|
|
49
|
-
"jobTitle": "Some Job Title 4",
|
|
50
|
-
"organisation": "Some Organization 4",
|
|
51
|
-
"photo": "//images.ctfassets.net/some-image-4.jpg",
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
"sections": Array [
|
|
55
|
-
Object {
|
|
56
|
-
"articles": Array [
|
|
57
|
-
Object {
|
|
58
|
-
"completionTime": 4,
|
|
59
|
-
"content": Object {
|
|
60
|
-
"sys": Object {
|
|
61
|
-
"id": "2HtwNA3ULFzOXo3yf3U7Ur",
|
|
62
|
-
"linkType": "Entry",
|
|
63
|
-
"type": "Link",
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
"icon": "introduction-icon",
|
|
67
|
-
"id": 8395927,
|
|
68
|
-
"image": "//images.ctfassets.net/some-image-5.jpg",
|
|
69
|
-
"slug": "some-article-slug-1",
|
|
70
|
-
"subsectionId": 1,
|
|
71
|
-
"title": "Some Article Title 1",
|
|
72
|
-
"type": "read-introduction",
|
|
73
|
-
},
|
|
74
|
-
Object {
|
|
75
|
-
"completionTime": 10,
|
|
76
|
-
"content": Object {
|
|
77
|
-
"sys": Object {
|
|
78
|
-
"id": "5pSlwsTJttKalLpfkoafIn",
|
|
79
|
-
"linkType": "Entry",
|
|
80
|
-
"type": "Link",
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
"icon": "government-building-icon",
|
|
84
|
-
"id": 8399969,
|
|
85
|
-
"image": "//images.ctfassets.net/some-image-6.jpg",
|
|
86
|
-
"slug": "some-article-slug-2",
|
|
87
|
-
"subsectionId": 2,
|
|
88
|
-
"title": "Some Article Title 2",
|
|
89
|
-
"type": "read-article-by-public-servant",
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
"description": "Some Description 1",
|
|
93
|
-
"sectionId": 1,
|
|
94
|
-
"title": "Some Section Title 1",
|
|
95
|
-
},
|
|
96
|
-
Object {
|
|
97
|
-
"articles": Array [
|
|
98
|
-
Object {
|
|
99
|
-
"completionTime": 14,
|
|
100
|
-
"content": Object {
|
|
101
|
-
"sys": Object {
|
|
102
|
-
"id": "7uDTXlpSKy7fltFELPyMQy",
|
|
103
|
-
"linkType": "Entry",
|
|
104
|
-
"type": "Link",
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
"icon": "person-icon",
|
|
108
|
-
"id": 8399146,
|
|
109
|
-
"image": "//images.ctfassets.net/some-image-7.jpg",
|
|
110
|
-
"slug": "some-article-2",
|
|
111
|
-
"subsectionId": 1,
|
|
112
|
-
"title": "Some Article Title 2",
|
|
113
|
-
"type": "read-article-by-expert",
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
"description": "Some Description 2",
|
|
117
|
-
"sectionId": 2,
|
|
118
|
-
"title": "Some Section Title 1",
|
|
119
|
-
},
|
|
120
|
-
],
|
|
121
|
-
"slug": "some-slug",
|
|
122
|
-
"summary": Object {
|
|
123
|
-
"description": "Some Summary Description",
|
|
124
|
-
"discussionLink": "https://teams.microsoft.com/l/team/some-link",
|
|
125
|
-
"learningObjectives": Array [
|
|
126
|
-
Object {
|
|
127
|
-
"key": "some-slug_learning-objectives_1",
|
|
128
|
-
"value": "Some Learning Objectives 1",
|
|
129
|
-
},
|
|
130
|
-
Object {
|
|
131
|
-
"key": "some-slug_learning-objectives_2",
|
|
132
|
-
"value": "Some Learning Objectives 2",
|
|
133
|
-
},
|
|
134
|
-
Object {
|
|
135
|
-
"key": "some-slug_learning-objectives_3",
|
|
136
|
-
"value": "Some Learning Objectives 3",
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
|
-
"targetAudiences": Array [
|
|
140
|
-
Object {
|
|
141
|
-
"key": "some-slug_target-audiences_1",
|
|
142
|
-
"value": "Some Target Audience 1",
|
|
143
|
-
},
|
|
144
|
-
Object {
|
|
145
|
-
"key": "some-slug_target-audiences_2",
|
|
146
|
-
"value": "Some Target Audience 2",
|
|
147
|
-
},
|
|
148
|
-
],
|
|
149
|
-
"title": "Some Title",
|
|
150
|
-
},
|
|
151
|
-
"title": "Some Title",
|
|
152
|
-
}
|
|
153
|
-
`;
|
|
154
|
-
|
|
155
|
-
exports[`Apolitical Content Global context Get Entry should use default context 1`] = `
|
|
156
|
-
Object {
|
|
157
|
-
"accessToken": "some-access-token",
|
|
158
|
-
"environment": "some-environment",
|
|
159
|
-
"host": "cdn.contentful.com",
|
|
160
|
-
"space": "some-space",
|
|
161
|
-
}
|
|
162
|
-
`;
|
|
163
|
-
|
|
164
|
-
exports[`Apolitical Content Global context Get Entry should use preview context 1`] = `
|
|
165
|
-
Object {
|
|
166
|
-
"accessToken": "some-preview-token",
|
|
167
|
-
"environment": "some-environment",
|
|
168
|
-
"host": "preview.contentful.com",
|
|
169
|
-
"space": "some-space",
|
|
170
|
-
}
|
|
171
|
-
`;
|
|
172
|
-
|
|
173
|
-
exports[`Apolitical Content Global context Read Entries should get entries 1`] = `
|
|
174
|
-
Array [
|
|
175
|
-
Object {
|
|
176
|
-
"banner": "//images.ctfassets.net/some-image-1.jpg",
|
|
177
|
-
"curriculum": "some-curriculum",
|
|
178
|
-
"editions": Array [
|
|
179
|
-
Object {
|
|
180
|
-
"endDate": "2020-12-11T12:00:00.000Z",
|
|
181
|
-
"id": 1,
|
|
182
|
-
"startDate": "2020-11-09T00:00:00.000Z",
|
|
183
|
-
"title": "some-slug_edition_1",
|
|
184
|
-
"workshopDate": "2019-10-07T19:30:00.000Z",
|
|
185
|
-
},
|
|
186
|
-
],
|
|
187
|
-
"experts": Array [
|
|
188
|
-
Object {
|
|
189
|
-
"country": "Some Country 1",
|
|
190
|
-
"fullName": "Some Full Name 1",
|
|
191
|
-
"jobTitle": "Some Job Title 1",
|
|
192
|
-
"organisation": "Some Organization 1",
|
|
193
|
-
"photo": "//images.ctfassets.net/some-image-2.jpeg",
|
|
194
|
-
},
|
|
195
|
-
Object {
|
|
196
|
-
"country": "Some Country 2",
|
|
197
|
-
"fullName": "Some Full Name 2",
|
|
198
|
-
"jobTitle": "Some Job Title 2",
|
|
199
|
-
"organisation": "Some Organization 2",
|
|
200
|
-
"photo": "//images.ctfassets.net/some-photo-3",
|
|
201
|
-
},
|
|
202
|
-
Object {
|
|
203
|
-
"country": "Some Country 3",
|
|
204
|
-
"fullName": "Some Full Name 3",
|
|
205
|
-
"jobTitle": "Some Job Title 3",
|
|
206
|
-
"organisation": "Some Organization 3",
|
|
207
|
-
"photo": null,
|
|
208
|
-
},
|
|
209
|
-
],
|
|
210
|
-
"hideTimes": true,
|
|
211
|
-
"id": 3662,
|
|
212
|
-
"manager": Object {
|
|
213
|
-
"id": 63564,
|
|
214
|
-
"slug": "some-manager-slug",
|
|
215
|
-
},
|
|
216
|
-
"reviewers": Array [
|
|
217
|
-
Object {
|
|
218
|
-
"country": "Some Country 4",
|
|
219
|
-
"fullName": "Some Full Name 4",
|
|
220
|
-
"jobTitle": "Some Job Title 4",
|
|
221
|
-
"organisation": "Some Organization 4",
|
|
222
|
-
"photo": "//images.ctfassets.net/some-image-4.jpg",
|
|
223
|
-
},
|
|
224
|
-
],
|
|
225
|
-
"sections": Array [
|
|
226
|
-
Object {
|
|
227
|
-
"articles": Array [
|
|
228
|
-
Object {
|
|
229
|
-
"completionTime": 4,
|
|
230
|
-
"content": Object {
|
|
231
|
-
"sys": Object {
|
|
232
|
-
"id": "2HtwNA3ULFzOXo3yf3U7Ur",
|
|
233
|
-
"linkType": "Entry",
|
|
234
|
-
"type": "Link",
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
"icon": "introduction-icon",
|
|
238
|
-
"id": 8395927,
|
|
239
|
-
"image": "//images.ctfassets.net/some-image-5.jpg",
|
|
240
|
-
"slug": "some-article-slug-1",
|
|
241
|
-
"subsectionId": 1,
|
|
242
|
-
"title": "Some Article Title 1",
|
|
243
|
-
"type": "read-introduction",
|
|
244
|
-
},
|
|
245
|
-
Object {
|
|
246
|
-
"completionTime": 10,
|
|
247
|
-
"content": Object {
|
|
248
|
-
"sys": Object {
|
|
249
|
-
"id": "5pSlwsTJttKalLpfkoafIn",
|
|
250
|
-
"linkType": "Entry",
|
|
251
|
-
"type": "Link",
|
|
252
|
-
},
|
|
253
|
-
},
|
|
254
|
-
"icon": "government-building-icon",
|
|
255
|
-
"id": 8399969,
|
|
256
|
-
"image": "//images.ctfassets.net/some-image-6.jpg",
|
|
257
|
-
"slug": "some-article-slug-2",
|
|
258
|
-
"subsectionId": 2,
|
|
259
|
-
"title": "Some Article Title 2",
|
|
260
|
-
"type": "read-article-by-public-servant",
|
|
261
|
-
},
|
|
262
|
-
],
|
|
263
|
-
"description": "Some Description 1",
|
|
264
|
-
"sectionId": 1,
|
|
265
|
-
"title": "Some Section Title 1",
|
|
266
|
-
},
|
|
267
|
-
Object {
|
|
268
|
-
"articles": Array [
|
|
269
|
-
Object {
|
|
270
|
-
"completionTime": 14,
|
|
271
|
-
"content": Object {
|
|
272
|
-
"sys": Object {
|
|
273
|
-
"id": "7uDTXlpSKy7fltFELPyMQy",
|
|
274
|
-
"linkType": "Entry",
|
|
275
|
-
"type": "Link",
|
|
276
|
-
},
|
|
277
|
-
},
|
|
278
|
-
"icon": "person-icon",
|
|
279
|
-
"id": 8399146,
|
|
280
|
-
"image": "//images.ctfassets.net/some-image-7.jpg",
|
|
281
|
-
"slug": "some-article-2",
|
|
282
|
-
"subsectionId": 1,
|
|
283
|
-
"title": "Some Article Title 2",
|
|
284
|
-
"type": "read-article-by-expert",
|
|
285
|
-
},
|
|
286
|
-
],
|
|
287
|
-
"description": "Some Description 2",
|
|
288
|
-
"sectionId": 2,
|
|
289
|
-
"title": "Some Section Title 1",
|
|
290
|
-
},
|
|
291
|
-
],
|
|
292
|
-
"slug": "some-slug",
|
|
293
|
-
"summary": Object {
|
|
294
|
-
"description": "Some Summary Description",
|
|
295
|
-
"discussionLink": "https://teams.microsoft.com/l/team/some-link",
|
|
296
|
-
"learningObjectives": Array [
|
|
297
|
-
Object {
|
|
298
|
-
"key": "some-slug_learning-objectives_1",
|
|
299
|
-
"value": "Some Learning Objectives 1",
|
|
300
|
-
},
|
|
301
|
-
Object {
|
|
302
|
-
"key": "some-slug_learning-objectives_2",
|
|
303
|
-
"value": "Some Learning Objectives 2",
|
|
304
|
-
},
|
|
305
|
-
Object {
|
|
306
|
-
"key": "some-slug_learning-objectives_3",
|
|
307
|
-
"value": "Some Learning Objectives 3",
|
|
308
|
-
},
|
|
309
|
-
],
|
|
310
|
-
"targetAudiences": Array [
|
|
311
|
-
Object {
|
|
312
|
-
"key": "some-slug_target-audiences_1",
|
|
313
|
-
"value": "Some Target Audience 1",
|
|
314
|
-
},
|
|
315
|
-
Object {
|
|
316
|
-
"key": "some-slug_target-audiences_2",
|
|
317
|
-
"value": "Some Target Audience 2",
|
|
318
|
-
},
|
|
319
|
-
],
|
|
320
|
-
"title": "Some Title",
|
|
321
|
-
},
|
|
322
|
-
"title": "Some Title",
|
|
323
|
-
},
|
|
324
|
-
Object {
|
|
325
|
-
"banner": "//images.ctfassets.net/some-image-1.jpg",
|
|
326
|
-
"curriculum": "some-curriculum",
|
|
327
|
-
"editions": Array [
|
|
328
|
-
Object {
|
|
329
|
-
"endDate": "2020-12-11T12:00:00.000Z",
|
|
330
|
-
"id": 1,
|
|
331
|
-
"startDate": "2020-11-09T00:00:00.000Z",
|
|
332
|
-
"title": "some-slug_edition_1",
|
|
333
|
-
"workshopDate": "2019-10-07T19:30:00.000Z",
|
|
334
|
-
},
|
|
335
|
-
],
|
|
336
|
-
"experts": Array [
|
|
337
|
-
Object {
|
|
338
|
-
"country": "Some Country 1",
|
|
339
|
-
"fullName": "Some Full Name 1",
|
|
340
|
-
"jobTitle": "Some Job Title 1",
|
|
341
|
-
"organisation": "Some Organization 1",
|
|
342
|
-
"photo": "//images.ctfassets.net/some-image-2.jpeg",
|
|
343
|
-
},
|
|
344
|
-
Object {
|
|
345
|
-
"country": "Some Country 2",
|
|
346
|
-
"fullName": "Some Full Name 2",
|
|
347
|
-
"jobTitle": "Some Job Title 2",
|
|
348
|
-
"organisation": "Some Organization 2",
|
|
349
|
-
"photo": "//images.ctfassets.net/some-photo-3",
|
|
350
|
-
},
|
|
351
|
-
Object {
|
|
352
|
-
"country": "Some Country 3",
|
|
353
|
-
"fullName": "Some Full Name 3",
|
|
354
|
-
"jobTitle": "Some Job Title 3",
|
|
355
|
-
"organisation": "Some Organization 3",
|
|
356
|
-
"photo": null,
|
|
357
|
-
},
|
|
358
|
-
],
|
|
359
|
-
"hideTimes": true,
|
|
360
|
-
"id": 3662,
|
|
361
|
-
"manager": Object {
|
|
362
|
-
"id": 63564,
|
|
363
|
-
"slug": "some-manager-slug",
|
|
364
|
-
},
|
|
365
|
-
"reviewers": Array [
|
|
366
|
-
Object {
|
|
367
|
-
"country": "Some Country 4",
|
|
368
|
-
"fullName": "Some Full Name 4",
|
|
369
|
-
"jobTitle": "Some Job Title 4",
|
|
370
|
-
"organisation": "Some Organization 4",
|
|
371
|
-
"photo": "//images.ctfassets.net/some-image-4.jpg",
|
|
372
|
-
},
|
|
373
|
-
],
|
|
374
|
-
"sections": Array [
|
|
375
|
-
Object {
|
|
376
|
-
"articles": Array [
|
|
377
|
-
Object {
|
|
378
|
-
"completionTime": 4,
|
|
379
|
-
"content": Object {
|
|
380
|
-
"sys": Object {
|
|
381
|
-
"id": "2HtwNA3ULFzOXo3yf3U7Ur",
|
|
382
|
-
"linkType": "Entry",
|
|
383
|
-
"type": "Link",
|
|
384
|
-
},
|
|
385
|
-
},
|
|
386
|
-
"icon": "introduction-icon",
|
|
387
|
-
"id": 8395927,
|
|
388
|
-
"image": "//images.ctfassets.net/some-image-5.jpg",
|
|
389
|
-
"slug": "some-article-slug-1",
|
|
390
|
-
"subsectionId": 1,
|
|
391
|
-
"title": "Some Article Title 1",
|
|
392
|
-
"type": "read-introduction",
|
|
393
|
-
},
|
|
394
|
-
Object {
|
|
395
|
-
"completionTime": 10,
|
|
396
|
-
"content": Object {
|
|
397
|
-
"sys": Object {
|
|
398
|
-
"id": "5pSlwsTJttKalLpfkoafIn",
|
|
399
|
-
"linkType": "Entry",
|
|
400
|
-
"type": "Link",
|
|
401
|
-
},
|
|
402
|
-
},
|
|
403
|
-
"icon": "government-building-icon",
|
|
404
|
-
"id": 8399969,
|
|
405
|
-
"image": "//images.ctfassets.net/some-image-6.jpg",
|
|
406
|
-
"slug": "some-article-slug-2",
|
|
407
|
-
"subsectionId": 2,
|
|
408
|
-
"title": "Some Article Title 2",
|
|
409
|
-
"type": "read-article-by-public-servant",
|
|
410
|
-
},
|
|
411
|
-
],
|
|
412
|
-
"description": "Some Description 1",
|
|
413
|
-
"sectionId": 1,
|
|
414
|
-
"title": "Some Section Title 1",
|
|
415
|
-
},
|
|
416
|
-
Object {
|
|
417
|
-
"articles": Array [
|
|
418
|
-
Object {
|
|
419
|
-
"completionTime": 14,
|
|
420
|
-
"content": Object {
|
|
421
|
-
"sys": Object {
|
|
422
|
-
"id": "7uDTXlpSKy7fltFELPyMQy",
|
|
423
|
-
"linkType": "Entry",
|
|
424
|
-
"type": "Link",
|
|
425
|
-
},
|
|
426
|
-
},
|
|
427
|
-
"icon": "person-icon",
|
|
428
|
-
"id": 8399146,
|
|
429
|
-
"image": "//images.ctfassets.net/some-image-7.jpg",
|
|
430
|
-
"slug": "some-article-2",
|
|
431
|
-
"subsectionId": 1,
|
|
432
|
-
"title": "Some Article Title 2",
|
|
433
|
-
"type": "read-article-by-expert",
|
|
434
|
-
},
|
|
435
|
-
],
|
|
436
|
-
"description": "Some Description 2",
|
|
437
|
-
"sectionId": 2,
|
|
438
|
-
"title": "Some Section Title 1",
|
|
439
|
-
},
|
|
440
|
-
],
|
|
441
|
-
"slug": "some-slug",
|
|
442
|
-
"summary": Object {
|
|
443
|
-
"description": "Some Summary Description",
|
|
444
|
-
"discussionLink": "https://teams.microsoft.com/l/team/some-link",
|
|
445
|
-
"learningObjectives": Array [
|
|
446
|
-
Object {
|
|
447
|
-
"key": "some-slug_learning-objectives_1",
|
|
448
|
-
"value": "Some Learning Objectives 1",
|
|
449
|
-
},
|
|
450
|
-
Object {
|
|
451
|
-
"key": "some-slug_learning-objectives_2",
|
|
452
|
-
"value": "Some Learning Objectives 2",
|
|
453
|
-
},
|
|
454
|
-
Object {
|
|
455
|
-
"key": "some-slug_learning-objectives_3",
|
|
456
|
-
"value": "Some Learning Objectives 3",
|
|
457
|
-
},
|
|
458
|
-
],
|
|
459
|
-
"targetAudiences": Array [
|
|
460
|
-
Object {
|
|
461
|
-
"key": "some-slug_target-audiences_1",
|
|
462
|
-
"value": "Some Target Audience 1",
|
|
463
|
-
},
|
|
464
|
-
Object {
|
|
465
|
-
"key": "some-slug_target-audiences_2",
|
|
466
|
-
"value": "Some Target Audience 2",
|
|
467
|
-
},
|
|
468
|
-
],
|
|
469
|
-
"title": "Some Title",
|
|
470
|
-
},
|
|
471
|
-
"title": "Some Title",
|
|
472
|
-
},
|
|
473
|
-
]
|
|
474
|
-
`;
|
|
475
|
-
|
|
476
|
-
exports[`Apolitical Content Global context Read Entries should use default context 1`] = `
|
|
477
|
-
Object {
|
|
478
|
-
"accessToken": "some-access-token",
|
|
479
|
-
"environment": "some-environment",
|
|
480
|
-
"host": "cdn.contentful.com",
|
|
481
|
-
"space": "some-space",
|
|
482
|
-
}
|
|
483
|
-
`;
|
|
484
|
-
|
|
485
|
-
exports[`Apolitical Content Global context Read Entries should use preview context 1`] = `
|
|
486
|
-
Object {
|
|
487
|
-
"accessToken": "some-preview-token",
|
|
488
|
-
"environment": "some-environment",
|
|
489
|
-
"host": "preview.contentful.com",
|
|
490
|
-
"space": "some-space",
|
|
491
|
-
}
|
|
492
|
-
`;
|
package/test/unit/lib.spec.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { createClient } from 'contentful';
|
|
2
|
-
import { setContext, getEntry, getEntries } from '../../lib';
|
|
3
|
-
import { getContext } from '../../lib/helper/context';
|
|
4
|
-
|
|
5
|
-
import { entryMock } from './mocks/microcourse.mock';
|
|
6
|
-
import { entriesMock } from './mocks/microcourses.mock';
|
|
7
|
-
|
|
8
|
-
// const mockCreateClient = jest.fn();
|
|
9
|
-
|
|
10
|
-
jest.mock('contentful', () => {
|
|
11
|
-
const actual = jest.requireActual('contentful');
|
|
12
|
-
return {
|
|
13
|
-
...actual,
|
|
14
|
-
createClient: jest.fn(),
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
jest.mock('contentful');
|
|
19
|
-
|
|
20
|
-
describe('Apolitical Content', () => {
|
|
21
|
-
const getEntriesStub = jest.fn();
|
|
22
|
-
const context = {
|
|
23
|
-
space: 'some-space',
|
|
24
|
-
accessToken: 'c29tZS1hY2Nlc3MtdG9rZW4=',
|
|
25
|
-
previewToken: 'c29tZS1wcmV2aWV3LXRva2Vu',
|
|
26
|
-
environment: 'some-environment',
|
|
27
|
-
origin: 'https://beta.apolitical.co',
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
describe('Global context', () => {
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
setContext(Object.assign({}, context, { isPreview: false }));
|
|
33
|
-
createClient.mockResolvedValue({ getEntries: getEntriesStub });
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('Context', () => {
|
|
37
|
-
test('should return cdn as default host', async () => {
|
|
38
|
-
const testContext = getContext();
|
|
39
|
-
expect(testContext.host).toBe('cdn.contentful.com');
|
|
40
|
-
});
|
|
41
|
-
test('should return access token', async () => {
|
|
42
|
-
const testContext = getContext();
|
|
43
|
-
expect(testContext.accessToken).toBe('some-access-token');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe('Preview', () => {
|
|
47
|
-
beforeEach(() => {
|
|
48
|
-
setContext(Object.assign({}, context, { isPreview: true }));
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('should return preview host', async () => {
|
|
52
|
-
const testContext2 = getContext();
|
|
53
|
-
expect(testContext2.host).toBe('preview.contentful.com');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('should return preview token', async () => {
|
|
57
|
-
const testContext2 = getContext();
|
|
58
|
-
expect(testContext2.accessToken).toBe('some-preview-token');
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('Get Entry', () => {
|
|
64
|
-
const query = {
|
|
65
|
-
content_type: 'microcourse',
|
|
66
|
-
'fields.slug[in]': 'some-slug',
|
|
67
|
-
include: 2,
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
test('should use default context', async () => {
|
|
71
|
-
getEntriesStub.mockReturnValueOnce(entryMock);
|
|
72
|
-
await getEntry(query);
|
|
73
|
-
expect(createClient).toHaveBeenCalledTimes(1);
|
|
74
|
-
expect(createClient.mock.calls[0][0]).toMatchSnapshot();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test('should use preview context', async () => {
|
|
78
|
-
getEntriesStub.mockReturnValueOnce(entryMock);
|
|
79
|
-
await getEntry(query, {}, true);
|
|
80
|
-
expect(createClient).toHaveBeenCalledTimes(1);
|
|
81
|
-
expect(createClient.mock.calls[0][0]).toMatchSnapshot();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('should read entry', async () => {
|
|
85
|
-
getEntriesStub.mockReturnValueOnce(entryMock);
|
|
86
|
-
const entry = await getEntry(query);
|
|
87
|
-
expect(entry).toMatchSnapshot();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test('should read raw entry', async () => {
|
|
91
|
-
getEntriesStub.mockReturnValueOnce(entryMock);
|
|
92
|
-
const entry = await getEntry(query, { flatten: false });
|
|
93
|
-
expect(entry).toEqual(entryMock.items[0]);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe('Read Entries', () => {
|
|
98
|
-
const query = {
|
|
99
|
-
content_type: 'microcourse',
|
|
100
|
-
limit: 2,
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
test('should use default context', async () => {
|
|
104
|
-
getEntriesStub.mockReturnValueOnce(entriesMock);
|
|
105
|
-
await getEntries(query);
|
|
106
|
-
expect(createClient).toHaveBeenCalledTimes(1);
|
|
107
|
-
expect(createClient.mock.calls[0][0]).toMatchSnapshot();
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test('should use preview context', async () => {
|
|
111
|
-
getEntriesStub.mockReturnValueOnce(entriesMock);
|
|
112
|
-
await getEntries(query, {}, true);
|
|
113
|
-
expect(createClient).toHaveBeenCalledTimes(1);
|
|
114
|
-
expect(createClient.mock.calls[0][0]).toMatchSnapshot();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test('should get entries', async () => {
|
|
118
|
-
getEntriesStub.mockReturnValueOnce(entriesMock);
|
|
119
|
-
const entries = await getEntries(query);
|
|
120
|
-
expect(entries).toMatchSnapshot();
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test('should read raw entries', async () => {
|
|
124
|
-
getEntriesStub.mockReturnValueOnce(entriesMock);
|
|
125
|
-
const entries = await getEntries(query, { flatten: false });
|
|
126
|
-
expect(entries).toEqual(entriesMock.items);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
});
|