@newskit-render/core 1.34.0 → 1.40.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.
@@ -0,0 +1,137 @@
1
+ describe('Payment Failer', () => {
2
+ it('Should show first notice', () => {
3
+ cy.GetAcsSession('withSub')
4
+ cy.mockConsent()
5
+ cy.visit('/account', {
6
+ onBeforeLoad: (win) => {
7
+ let nextData
8
+
9
+ Object.defineProperty(win, '__NEXT_DATA__', {
10
+ set(o) {
11
+ // eslint-disable-next-line no-param-reassign
12
+ o.props.pageProps.user.paymentFailure = {
13
+ active: true,
14
+ startDate: new Date(Date.now() - 24 * 3600 * 1000).toISOString(),
15
+ }
16
+ nextData = o
17
+ },
18
+ get() {
19
+ return nextData
20
+ },
21
+ })
22
+ },
23
+ })
24
+ cy.get('[data-testid="banner-container"]').should('be.visible')
25
+ cy.contains("We haven't been able to take payment")
26
+ cy.contains(
27
+ 'You may need to update your payment details to keep your subscription.'
28
+ )
29
+ cy.get('[data-testid="buttonLink"]').should('be.visible')
30
+ cy.contains('Update payment details')
31
+ })
32
+
33
+ it('Should show second notice', () => {
34
+ cy.GetAcsSession('withSub')
35
+ cy.mockConsent()
36
+ cy.visit('/account', {
37
+ onBeforeLoad: (win) => {
38
+ let nextData
39
+
40
+ Object.defineProperty(win, '__NEXT_DATA__', {
41
+ set(o) {
42
+ // eslint-disable-next-line no-param-reassign
43
+ o.props.pageProps.user.paymentFailure = {
44
+ active: true,
45
+ startDate: new Date(
46
+ Date.now() - 24 * 27 * 3600 * 1000
47
+ ).toISOString(),
48
+ }
49
+ nextData = o
50
+ },
51
+ get() {
52
+ return nextData
53
+ },
54
+ })
55
+ },
56
+ })
57
+ cy.get('[data-testid="banner-container"]').should('be.visible')
58
+ cy.contains('Act now to keep your subscription')
59
+ cy.contains(
60
+ 'We’ve tried several times, but haven’t been able to take payment. Please update your payment details to keep your subscription.'
61
+ )
62
+ cy.get('[data-testid="buttonLink"]').should('be.visible')
63
+ cy.contains('Update payment details')
64
+ })
65
+
66
+ it('Should show terminated notice', () => {
67
+ cy.GetAcsSession('withSub')
68
+ cy.mockConsent()
69
+ cy.visit('/account', {
70
+ onBeforeLoad: (win) => {
71
+ let nextData
72
+
73
+ Object.defineProperty(win, '__NEXT_DATA__', {
74
+ set(o) {
75
+ // eslint-disable-next-line no-param-reassign
76
+ o.props.pageProps.user.paymentFailure = {
77
+ active: true,
78
+ startDate: new Date(
79
+ Date.now() - 24 * 35 * 3600 * 1000
80
+ ).toISOString(),
81
+ }
82
+ nextData = o
83
+ },
84
+ get() {
85
+ return nextData
86
+ },
87
+ })
88
+ },
89
+ })
90
+ cy.get('[data-testid="banner-container"]').should('be.visible')
91
+ cy.contains('Your subscription has been terminated')
92
+ cy.contains(
93
+ 'We didn’t receive payment for your subscription. To reactivate it, please call XXXX-XXX-XXXX.'
94
+ )
95
+ })
96
+
97
+ it('Should show expired subscription view with terminated notice', () => {
98
+ cy.GetAcsSession('expiredSub')
99
+ cy.mockConsent()
100
+ const date = new Date(Date.now() - 24 * 35 * 3600 * 1000)
101
+ cy.visit('/account/subscription-and-billing', {
102
+ onBeforeLoad: (win) => {
103
+ let nextData
104
+
105
+ Object.defineProperty(win, '__NEXT_DATA__', {
106
+ set(o) {
107
+ // eslint-disable-next-line no-param-reassign
108
+ o.props.pageProps.user.paymentFailure = {
109
+ active: true,
110
+ startDate: date.toISOString(),
111
+ }
112
+ // eslint-disable-next-line no-param-reassign
113
+ o.props.pageProps.user.subscriptions[0].serviceCancellationDate = date.toISOString()
114
+ nextData = o
115
+ },
116
+ get() {
117
+ return nextData
118
+ },
119
+ })
120
+ },
121
+ })
122
+
123
+ cy.contains('You’ve previously had a subscription that has now expired')
124
+
125
+ cy.contains(
126
+ `On ${date.toLocaleDateString(
127
+ 'en-GB'
128
+ )} your Digital subscription expired. You can can re-subscribe by confirming a few details or view other packages that are available.`
129
+ )
130
+ cy.get('[data-testid="primary-button"]')
131
+ .should('have.attr', 'href', '/title-re-subscribe')
132
+ .contains('Re-subscribe')
133
+ cy.get('[data-testid="secondary-button"]')
134
+ .should('have.attr', 'href', '/title-subscription-options')
135
+ .contains('View subscription options')
136
+ })
137
+ })
@@ -4,7 +4,32 @@ Cypress.Commands.add('mockConsentAndVisit', (url) => {
4
4
  cy.visit(url)
5
5
  })
6
6
 
7
- Cypress.Commands.add('GetAcsSession', () => {
7
+ Cypress.Commands.add('mockConsent', () => {
8
+ cy.setCookie('nukt_sp_consent', 'JABCDEFGHI')
9
+ cy.setCookie('consentUUID', '28cfcd1e-6916-4488-9d84-54f2618eaa14')
10
+ })
11
+
12
+ const userMap = {
13
+ default: {
14
+ username: 'temp.account@tempaccount.com',
15
+ password: 'asdasd1A',
16
+ },
17
+ noSub: {
18
+ username: 'render.e2e.no-sub@yopmail.com',
19
+ password: 'Ad45p0-swq151@',
20
+ },
21
+ expiredSub: {
22
+ username: 'tim.newsuk3@yopmail.com',
23
+ password: 'Ad45p0-swq151@',
24
+ },
25
+ withSub: {
26
+ username: 'render.e2e.sub@yopmail.com',
27
+ password: 'Ad45p0-swq151@',
28
+ }
29
+ }
30
+
31
+ Cypress.Commands.add('GetAcsSession', (user = 'default') => {
32
+ const { username, password } = userMap[user]
8
33
  cy.request({
9
34
  method: 'POST',
10
35
  url: 'https://login.staging-thesun.co.uk/services/session',
@@ -16,8 +41,8 @@ Cypress.Commands.add('GetAcsSession', () => {
16
41
  gotoUrl: 'https://login.staging-thesun.co.uk/',
17
42
  sso: false,
18
43
  authCredentials: {
19
- username: 'temp.account@tempaccount.com',
20
- password: 'asdasd1A',
44
+ username,
45
+ password,
21
46
  },
22
47
  },
23
48
  }).then((response) => {
@@ -123,8 +123,8 @@ export type Page = {
123
123
  export type Media = Image | Video
124
124
 
125
125
  export type Image = {
126
- crops?: ImageCrop[]
127
- crop: ImageCrop
126
+ crops: ImageCrop[]
127
+ crop?: ImageCrop
128
128
  }
129
129
 
130
130
  export type Video = {
@@ -80,10 +80,13 @@ const data = {
80
80
  ],
81
81
  },
82
82
  media: {
83
- crop: {
84
- url: 'some-url-to-image',
85
- alt: 'image alt',
86
- },
83
+ crops: [
84
+ {
85
+ url:
86
+ 'https://www.thesun.co.uk/wp-content/uploads/2022/03/SPORT-PREVIEW-Amadou-Onana-to-WHU.jpg?strip=all&w=620&h=413&crop=1',
87
+ alt: 'image alt',
88
+ },
89
+ ],
87
90
  },
88
91
  },
89
92
  },
@@ -106,10 +109,13 @@ const data = {
106
109
  ],
107
110
  },
108
111
  media: {
109
- crop: {
110
- url: 'some-url-to-image',
111
- alt: 'image alt 2',
112
- },
112
+ crops: [
113
+ {
114
+ url:
115
+ 'https://www.thesun.co.uk/wp-content/uploads/2022/03/SPORT-PREVIEW-Amadou-Onana-to-WHU.jpg?strip=all&w=620&h=413&crop=1',
116
+ alt: 'image alt 2',
117
+ },
118
+ ],
113
119
  },
114
120
  },
115
121
  },
@@ -131,12 +137,15 @@ const data = {
131
137
  },
132
138
  ],
133
139
  },
134
- media: {
135
- crop: {
136
- url: 'some-url-to-image',
137
- alt: 'image alt 3',
140
+ media: [
141
+ {
142
+ crops: {
143
+ url:
144
+ 'https://www.thesun.co.uk/wp-content/uploads/2022/03/SPORT-PREVIEW-Amadou-Onana-to-WHU.jpg?strip=all&w=620&h=413&crop=1',
145
+ alt: 'image alt 3',
146
+ },
138
147
  },
139
- },
148
+ ],
140
149
  },
141
150
  },
142
151
  {
@@ -158,10 +167,13 @@ const data = {
158
167
  ],
159
168
  },
160
169
  media: {
161
- crop: {
162
- url: 'some-url-to-image',
163
- alt: 'image alt 3',
164
- },
170
+ crops: [
171
+ {
172
+ url:
173
+ 'https://www.thesun.co.uk/wp-content/uploads/2022/03/SPORT-PREVIEW-Amadou-Onana-to-WHU.jpg?strip=all&w=620&h=413&crop=1',
174
+ alt: 'image alt 3',
175
+ },
176
+ ],
165
177
  },
166
178
  },
167
179
  },
@@ -312,10 +324,13 @@ const data = {
312
324
  ],
313
325
  },
314
326
  media: {
315
- crop: {
316
- url: 'some-url-to-image',
317
- alt: 'image alt',
318
- },
327
+ crops: [
328
+ {
329
+ url:
330
+ 'https://www.thesun.co.uk/wp-content/uploads/2022/03/SPORT-PREVIEW-Amadou-Onana-to-WHU.jpg?strip=all&w=620&h=413&crop=1',
331
+ alt: 'image alt',
332
+ },
333
+ ],
319
334
  },
320
335
  },
321
336
  },
@@ -338,10 +353,13 @@ const data = {
338
353
  ],
339
354
  },
340
355
  media: {
341
- crop: {
342
- url: 'some-url-to-image',
343
- alt: 'image alt 2',
344
- },
356
+ crops: [
357
+ {
358
+ url:
359
+ 'https://www.thesun.co.uk/wp-content/uploads/2022/03/SPORT-PREVIEW-Amadou-Onana-to-WHU.jpg?strip=all&w=620&h=413&crop=1',
360
+ alt: 'image alt 2',
361
+ },
362
+ ],
345
363
  },
346
364
  },
347
365
  },
@@ -364,10 +382,13 @@ const data = {
364
382
  ],
365
383
  },
366
384
  media: {
367
- crop: {
368
- url: 'some-url-to-image',
369
- alt: 'image alt 3',
370
- },
385
+ crops: [
386
+ {
387
+ url:
388
+ 'https://www.thesun.co.uk/wp-content/uploads/2022/03/SPORT-PREVIEW-Amadou-Onana-to-WHU.jpg?strip=all&w=620&h=413&crop=1',
389
+ alt: 'image alt 3',
390
+ },
391
+ ],
371
392
  },
372
393
  },
373
394
  },
@@ -390,10 +411,13 @@ const data = {
390
411
  ],
391
412
  },
392
413
  media: {
393
- crop: {
394
- url: 'some-url-to-image',
395
- alt: 'image alt 3',
396
- },
414
+ crops: [
415
+ {
416
+ url:
417
+ 'https://www.thesun.co.uk/wp-content/uploads/2022/03/SPORT-PREVIEW-Amadou-Onana-to-WHU.jpg?strip=all&w=620&h=413&crop=1',
418
+ alt: 'image alt 3',
419
+ },
420
+ ],
397
421
  },
398
422
  },
399
423
  },
@@ -645,7 +645,7 @@ orbs:
645
645
  source $BASH_ENV
646
646
  CURRENT_VERSION=$(jq -r .version ./package.json)
647
647
 
648
- npm install --no-save release-documentation-cli@5.2.0
648
+ npm install --no-save release-documentation-cli@5.2.4
649
649
 
650
650
  # If your tags are prefixed (i.e. lerna) check the --tagFilter parameter
651
651
  echo "Creating a release request for $CURRENT_VERSION to be deployed to production."
@@ -670,7 +670,7 @@ orbs:
670
670
  export CURRENT_VERSION=$(jq -r .version ./package.json)
671
671
  echo "export CURRENT_VERSION=$CURRENT_VERSION" >> $BASH_ENV
672
672
 
673
- npm install --no-save release-documentation-cli@5.2.0
673
+ npm install --no-save release-documentation-cli@5.2.4
674
674
 
675
675
  # If your tags are prefixed (i.e. lerna) check the --tagFilter parameter
676
676
  $(npm bin)/release promote
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newskit-render/core",
3
- "version": "1.34.0",
3
+ "version": "1.40.0",
4
4
  "description": "Newskit Render - Core package",
5
5
  "author": "",
6
6
  "license": "UNLICENSED",
@@ -33,13 +33,13 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@apollo/client": "3.4.16",
36
- "@newskit-render/api": "^0.16.0",
36
+ "@newskit-render/api": "^0.17.0",
37
37
  "@newskit-render/auth": "^0.30.0",
38
- "@newskit-render/checkout": "^0.25.0",
38
+ "@newskit-render/checkout": "^0.25.4",
39
39
  "@newskit-render/feature-flags": "^0.11.0",
40
- "@newskit-render/feed": "^0.4.0",
41
- "@newskit-render/my-account": "^0.145.0",
42
- "@newskit-render/shared-components": "^0.39.0",
40
+ "@newskit-render/feed": "^0.4.1",
41
+ "@newskit-render/my-account": "^0.149.0",
42
+ "@newskit-render/shared-components": "^0.42.0",
43
43
  "@newskit-render/validation": "^0.38.0",
44
44
  "cross-fetch": "3.1.5",
45
45
  "graphql": "15.6.0",
@@ -22,13 +22,24 @@ export async function getServerSideProps(context) {
22
22
  : ''
23
23
 
24
24
  newrelic.setTransactionName(`Section: ${section}`)
25
- const [{ data }, user] = await Promise.all([
26
- apolloClient.query({
27
- query: GET_PAGE,
28
- variables: { channel: section, publisher: 'DEMO' },
29
- }),
30
- await fetchUser(acsCookie, ACCOUNT_QUERY_URL),
31
- ])
25
+
26
+ let data
27
+ let user
28
+ try {
29
+ const [{ data: pageData }, pageUser] = await Promise.all([
30
+ apolloClient.query({
31
+ query: GET_PAGE,
32
+ variables: { channel: section, publisher: 'DEMO' },
33
+ }),
34
+ await fetchUser(acsCookie, ACCOUNT_QUERY_URL),
35
+ ])
36
+ data = pageData
37
+ user = pageUser
38
+ } catch (e) {
39
+ return {
40
+ notFound: true,
41
+ }
42
+ }
32
43
 
33
44
  addCacheHeaders(context.res)
34
45
  return {
package/pages/_error.tsx CHANGED
@@ -1,8 +1,8 @@
1
1
  import React from 'react'
2
2
  import { NotFound, GenericError } from '@newskit-render/my-account'
3
3
  import Error from 'next/error'
4
- import FourOhFour from '../components/404/404'
5
4
  import { getCircularReplacer } from '../helpers/getCircularReplacer'
5
+ import ErrorPage from '../components/ErrorPage/ErrorPage'
6
6
 
7
7
  CustomError.getInitialProps = ({ res, err, asPath }) => {
8
8
  let statusCode = 404
@@ -33,8 +33,24 @@ function CustomError({ statusCode, asPath }) {
33
33
  return <GenericError />
34
34
  }
35
35
  if (statusCode === 404) {
36
- return <FourOhFour />
36
+ return (
37
+ <ErrorPage
38
+ title="Page not found"
39
+ errorMassage={`
40
+ We can't seem to find what you're looking for. If you typed a URL
41
+ into your browser, it might be worth checking and trying again.`}
42
+ />
43
+ )
37
44
  }
45
+ if (statusCode === 500 || statusCode === 502) {
46
+ return (
47
+ <ErrorPage
48
+ title="Server-side error occurred"
49
+ errorMassage="We could not fetch the data from the server"
50
+ />
51
+ )
52
+ }
53
+
38
54
  return <Error statusCode={statusCode} />
39
55
  }
40
56