@@ -5,12 +5,23 @@ const { administrator } = require('../../../../app/auth/permissions')
5
5
const viewApplicationData = require ( '.././../../data/view-applications.json' )
6
6
const reference = 'AHWR-555A-FD4C'
7
7
8
+ function expectWithdrawLink ( $ , reference , isWithdrawLinkVisible ) {
9
+ if ( isWithdrawLinkVisible ) {
10
+ expect ( $ ( '.govuk-link' ) . hasClass )
11
+ const withdrawLink = $ ( '.govuk-link' )
12
+ expect ( withdrawLink . text ( ) ) . toMatch ( 'Withdraw' )
13
+ expect ( withdrawLink . attr ( 'href' ) ) . toMatch ( `/view-application/${ reference } ?page=1&withdraw=true` )
14
+ } else {
15
+ expect ( $ ( '.govuk-link' ) . not . hasClass )
16
+ }
17
+ }
18
+
8
19
jest . mock ( '../../../../app/api/applications' )
9
20
10
21
describe ( 'View Application test' , ( ) => {
11
22
const url = `/view-application/${ reference } `
12
23
jest . mock ( '../../../../app/auth' )
13
- const auth = { strategy : 'session-auth' , credentials : { scope : [ administrator ] } }
24
+ let auth = { strategy : 'session-auth' , credentials : { scope : [ administrator ] } }
14
25
15
26
beforeEach ( ( ) => {
16
27
jest . clearAllMocks ( )
@@ -38,7 +49,12 @@ describe('View Application test', () => {
38
49
expect ( $ ( 'h1.govuk-heading-l' ) . text ( ) ) . toEqual ( '400 - Bad Request' )
39
50
expectPhaseBanner . ok ( $ )
40
51
} )
41
- test ( 'returns 200 application agreed' , async ( ) => {
52
+ test . each ( [
53
+ [ 'administrator' , true ] ,
54
+ [ 'processor' , false ] ,
55
+ [ 'user' , false ]
56
+ ] ) ( 'returns 200 application agreed - %s role' , async ( authScope , isWithdrawLinkVisible ) => {
57
+ auth = { strategy : 'session-auth' , credentials : { scope : [ authScope ] } }
42
58
applications . getApplication . mockReturnValueOnce ( viewApplicationData . agreed )
43
59
const options = {
44
60
method : 'GET' ,
@@ -75,6 +91,9 @@ describe('View Application test', () => {
75
91
expect ( $ ( 'tbody tr:nth-child(5)' ) . text ( ) ) . toContain ( 'Agreement accepted' )
76
92
expect ( $ ( 'tbody tr:nth-child(5)' ) . text ( ) ) . toContain ( 'Yes' )
77
93
expect ( $ ( '#claim' ) . text ( ) ) . toContain ( 'Not claimed yet' )
94
+
95
+ expectWithdrawLink ( $ , reference , isWithdrawLinkVisible )
96
+
78
97
expectPhaseBanner . ok ( $ )
79
98
} )
80
99
test ( 'returns 200 application applied' , async ( ) => {
@@ -114,6 +133,9 @@ describe('View Application test', () => {
114
133
expect ( $ ( 'tbody tr:nth-child(5)' ) . text ( ) ) . toContain ( 'Agreement accepted' )
115
134
expect ( $ ( 'tbody tr:nth-child(5)' ) . text ( ) ) . toContain ( 'No' )
116
135
expect ( $ ( '#claim' ) . text ( ) ) . toContain ( 'Not eligible to claim' )
136
+
137
+ expectWithdrawLink ( $ , reference , false )
138
+
117
139
expectPhaseBanner . ok ( $ )
118
140
} )
119
141
test ( 'returns 200 application data inputted' , async ( ) => {
@@ -143,6 +165,9 @@ describe('View Application test', () => {
143
165
expect ( $ ( '.govuk-summary-list__value' ) . eq ( 3 ) . text ( ) ) . toMatch ( '[email protected] ' )
144
166
145
167
expect ( $ ( '#claim' ) . text ( ) ) . toContain ( 'Not eligible to claim' )
168
+
169
+ expectWithdrawLink ( $ , reference , false )
170
+
146
171
expectPhaseBanner . ok ( $ )
147
172
} )
148
173
test ( 'returns 200 application claim' , async ( ) => {
@@ -185,6 +210,9 @@ describe('View Application test', () => {
185
210
expect ( $ ( 'tbody:nth-child(1) tr:nth-child(5)' ) . text ( ) ) . toContain ( '1234234' )
186
211
expect ( $ ( 'tbody:nth-child(1) tr:nth-child(6)' ) . text ( ) ) . toContain ( 'Test results unique reference number (URN)' )
187
212
expect ( $ ( 'tbody:nth-child(1) tr:nth-child(6)' ) . text ( ) ) . toContain ( '134242' )
213
+
214
+ expectWithdrawLink ( $ , reference , false )
215
+
188
216
expectPhaseBanner . ok ( $ )
189
217
} )
190
218
test ( 'returns 200 application paid' , async ( ) => {
@@ -214,6 +242,56 @@ describe('View Application test', () => {
214
242
expect ( $ ( '.govuk-summary-list__value' ) . eq ( 3 ) . text ( ) ) . toMatch ( '[email protected] ' )
215
243
216
244
expect ( $ ( '#claim' ) . text ( ) ) . toContain ( 'Claimed' )
245
+
246
+ expectWithdrawLink ( $ , reference , false )
247
+
248
+ expectPhaseBanner . ok ( $ )
249
+ } )
250
+ test . each ( [
251
+ [ 'administrator' , true ] ,
252
+ [ 'processor' , false ] ,
253
+ [ 'user' , false ]
254
+ ] ) ( 'returns 200 application in check - %s role' , async ( authScope , isWithdrawLinkVisible ) => {
255
+ auth = { strategy : 'session-auth' , credentials : { scope : [ authScope ] } }
256
+ applications . getApplication . mockReturnValueOnce ( viewApplicationData . incheck )
257
+ const options = {
258
+ method : 'GET' ,
259
+ url,
260
+ auth
261
+ }
262
+ const res = await global . __SERVER__ . inject ( options )
263
+ expect ( res . statusCode ) . toBe ( 200 )
264
+ const $ = cheerio . load ( res . payload )
265
+ expect ( $ ( 'h1.govuk-caption-l' ) . text ( ) ) . toContain ( `Agreement number: ${ reference } ` )
266
+ expect ( $ ( 'h2.govuk-heading-l' ) . text ( ) ) . toContain ( 'In check' )
267
+ expect ( $ ( 'title' ) . text ( ) ) . toContain ( 'Administration: User Application' )
268
+ expect ( $ ( '.govuk-summary-list__row' ) . length ) . toEqual ( 4 )
269
+ expect ( $ ( '.govuk-summary-list__key' ) . eq ( 0 ) . text ( ) ) . toMatch ( 'Name:' )
270
+ expect ( $ ( '.govuk-summary-list__value' ) . eq ( 0 ) . text ( ) ) . toMatch ( 'Farmer name' )
271
+
272
+ expect ( $ ( '.govuk-summary-list__key' ) . eq ( 1 ) . text ( ) ) . toMatch ( 'SBI number:' )
273
+ expect ( $ ( '.govuk-summary-list__value' ) . eq ( 1 ) . text ( ) ) . toMatch ( '333333333' )
274
+
275
+ expect ( $ ( '.govuk-summary-list__key' ) . eq ( 2 ) . text ( ) ) . toMatch ( 'Address:' )
276
+ expect ( $ ( '.govuk-summary-list__value' ) . eq ( 2 ) . text ( ) ) . toMatch ( 'Long dusty road, Middle-of-knowhere, In the countryside, CC33 3CC' )
277
+
278
+ expect ( $ ( '.govuk-summary-list__key' ) . eq ( 3 ) . text ( ) ) . toMatch ( 'Email address:' )
279
+ expect ( $ ( '.govuk-summary-list__value' ) . eq ( 3 ) . text ( ) ) . toMatch ( '[email protected] ' )
280
+
281
+ expect ( $ ( 'tbody tr:nth-child(1)' ) . text ( ) ) . toContain ( 'Date of agreement' )
282
+ expect ( $ ( 'tbody tr:nth-child(1)' ) . text ( ) ) . toContain ( '06/06/2022' )
283
+ expect ( $ ( 'tbody tr:nth-child(2)' ) . text ( ) ) . toContain ( 'Business details correct' )
284
+ expect ( $ ( 'tbody tr:nth-child(2)' ) . text ( ) ) . toContain ( 'Yes' )
285
+ expect ( $ ( 'tbody tr:nth-child(3)' ) . text ( ) ) . toContain ( 'Type of review' )
286
+ expect ( $ ( 'tbody tr:nth-child(3)' ) . text ( ) ) . toContain ( 'Sheep' )
287
+ expect ( $ ( 'tbody tr:nth-child(4)' ) . text ( ) ) . toContain ( 'Number of livestock' )
288
+ expect ( $ ( 'tbody tr:nth-child(4)' ) . text ( ) ) . toContain ( 'Minimum 21' )
289
+ expect ( $ ( 'tbody tr:nth-child(5)' ) . text ( ) ) . toContain ( 'Agreement accepted' )
290
+ expect ( $ ( 'tbody tr:nth-child(5)' ) . text ( ) ) . toContain ( 'Yes' )
291
+ expect ( $ ( '#claim' ) . text ( ) ) . toContain ( 'Not claimed yet' )
292
+
293
+ expectWithdrawLink ( $ , reference , isWithdrawLinkVisible )
294
+
217
295
expectPhaseBanner . ok ( $ )
218
296
} )
219
297
} )
0 commit comments