Skip to content

Commit 2195037

Browse files
authored
Fix failing local unit tests (#1675)
It appears that following the merge into main of PR #1484 that some unit tests are now failing locally. The tests all seem to be failing because the return link URL in some of the bill run review tests now appears to be incorrect when this feature flag is set to `true` locally `ENABLE_SYSTEM_RETURNS_VIEW`. It looks like some tests just need this feature flag stubbing in them and some extra tests added to check the URL with the flag set to both `true` and `false` so I will do that in this PR.
1 parent 882ce82 commit 2195037

File tree

4 files changed

+91
-9
lines changed

4 files changed

+91
-9
lines changed

test/presenters/bill-runs/review/review-charge-element.presenter.test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
// Test framework dependencies
44
const Lab = require('@hapi/lab')
55
const Code = require('@hapi/code')
6+
const Sinon = require('sinon')
67

78
const { describe, it, beforeEach } = (exports.lab = Lab.script())
89
const { expect } = Code
910

1011
// Test helpers
1112
const BillRunsReviewFixture = require('../../../fixtures/bill-runs-review.fixture.js')
1213

14+
// Things we need to stub
15+
const FeatureFlagsConfig = require('../../../../config/feature-flags.config.js')
16+
1317
// Thing under test
1418
const ReviewChargeElementPresenter = require('../../../../app/presenters/bill-runs/review/review-charge-element.presenter.js')
1519

@@ -20,6 +24,8 @@ describe('Bill Runs Review - Review Charge Element presenter', () => {
2024

2125
beforeEach(() => {
2226
reviewChargeElement = BillRunsReviewFixture.reviewChargeElement()
27+
28+
Sinon.stub(FeatureFlagsConfig, 'enableSystemReturnsView').value(true)
2329
})
2430

2531
describe('when provided with a ReviewChargeElement', () => {
@@ -45,7 +51,7 @@ describe('Bill Runs Review - Review Charge Element presenter', () => {
4551
purpose: 'Spray Irrigation - Direct',
4652
reference: '11142960',
4753
returnId: 'v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
48-
returnLink: '/returns/return?id=v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
54+
returnLink: '/system/return-logs?id=v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
4955
returnPeriod: '1 November 2022 to 31 October 2023',
5056
returnStatus: 'completed',
5157
returnTotal: '0 ML / 0 ML'
@@ -68,4 +74,18 @@ describe('Bill Runs Review - Review Charge Element presenter', () => {
6874
})
6975
})
7076
})
77+
78+
describe('when enableSystemReturnsView is set to false', () => {
79+
beforeEach(() => {
80+
Sinon.stub(FeatureFlagsConfig, 'enableSystemReturnsView').value(false)
81+
})
82+
83+
it('returns the "returnLink" URL to the legacy page', async () => {
84+
const result = ReviewChargeElementPresenter.go(reviewChargeElement, elementIndex)
85+
86+
expect(result.matchedReturns[0].returnLink).to.equal(
87+
'/returns/return?id=v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31'
88+
)
89+
})
90+
})
7191
})

test/presenters/bill-runs/review/review-licence.presenter.test.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
// Test framework dependencies
44
const Lab = require('@hapi/lab')
55
const Code = require('@hapi/code')
6+
const Sinon = require('sinon')
67

78
const { describe, it, beforeEach } = (exports.lab = Lab.script())
89
const { expect } = Code
910

1011
// Test helpers
1112
const BillRunsReviewFixture = require('../../../fixtures/bill-runs-review.fixture.js')
1213

14+
// Things we need to stub
15+
const FeatureFlagsConfig = require('../../../../config/feature-flags.config.js')
16+
1317
// Thing under test
1418
const ReviewLicencePresenter = require('../../../../app/presenters/bill-runs/review/review-licence.presenter.js')
1519

@@ -18,6 +22,8 @@ describe('Bill Runs Review - Review Licence presenter', () => {
1822

1923
beforeEach(() => {
2024
reviewLicence = BillRunsReviewFixture.reviewLicence()
25+
26+
Sinon.stub(FeatureFlagsConfig, 'enableSystemReturnsView').value(true)
2127
})
2228

2329
describe('when provided with the result of fetch review licence service', () => {
@@ -84,7 +90,7 @@ describe('Bill Runs Review - Review Licence presenter', () => {
8490
purpose: 'Spray Irrigation - Direct',
8591
reference: '11142960',
8692
returnId: 'v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
87-
returnLink: '/returns/return?id=v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
93+
returnLink: '/system/return-logs?id=v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
8894
returnPeriod: '1 November 2022 to 31 October 2023',
8995
returnStatus: 'completed',
9096
returnTotal: '0 ML / 0 ML'
@@ -102,7 +108,7 @@ describe('Bill Runs Review - Review Licence presenter', () => {
102108
purpose: 'Spray Irrigation - Storage',
103109
reference: '11142961',
104110
returnId: 'v1:5:1/11/11/*11/1111:11142961:2022-11-01:2023-10-31',
105-
returnLink: '/returns/return?id=v1:5:1/11/11/*11/1111:11142961:2022-11-01:2023-10-31',
111+
returnLink: '/system/return-logs?id=v1:5:1/11/11/*11/1111:11142961:2022-11-01:2023-10-31',
106112
returnPeriod: '1 November 2022 to 31 October 2023',
107113
returnStatus: 'completed',
108114
returnTotal: '0 ML / 0 ML'
@@ -111,6 +117,23 @@ describe('Bill Runs Review - Review Licence presenter', () => {
111117
})
112118
})
113119

120+
describe('and the "enableSystemReturnsView" flag is set to false', () => {
121+
beforeEach(() => {
122+
Sinon.stub(FeatureFlagsConfig, 'enableSystemReturnsView').value(false)
123+
})
124+
125+
it('returns the "returnLink" URL to the legacy page', async () => {
126+
const result = ReviewLicencePresenter.go(reviewLicence)
127+
128+
expect(result.matchedReturns[0].returnLink).to.equal(
129+
'/returns/return?id=v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31'
130+
)
131+
expect(result.unmatchedReturns[0].returnLink).to.equal(
132+
'/returns/return?id=v1:5:1/11/11/*11/1111:11142961:2022-11-01:2023-10-31'
133+
)
134+
})
135+
})
136+
114137
describe('the "chargeVersions" property', () => {
115138
describe('the "chargeReferences" property', () => {
116139
describe('the "chargeReferenceLinkTitle" property', () => {

test/services/bill-runs/review/review-charge-element.service.test.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const { expect } = Code
1212
const BillRunsReviewFixture = require('../../../fixtures/bill-runs-review.fixture.js')
1313

1414
// Things we need to stub
15+
const FeatureFlagsConfig = require('../../../../config/feature-flags.config.js')
1516
const FetchReviewChargeElementService = require('../../../../app/services/bill-runs/review/fetch-review-charge-element.service.js')
1617

1718
// Thing under test
@@ -26,6 +27,7 @@ describe('Bill Runs Review - Review Charge Element Service', () => {
2627
beforeEach(() => {
2728
reviewChargeElement = BillRunsReviewFixture.reviewChargeElement()
2829

30+
Sinon.stub(FeatureFlagsConfig, 'enableSystemReturnsView').value(true)
2931
Sinon.stub(FetchReviewChargeElementService, 'go').resolves(reviewChargeElement)
3032
})
3133

@@ -66,7 +68,7 @@ describe('Bill Runs Review - Review Charge Element Service', () => {
6668
purpose: 'Spray Irrigation - Direct',
6769
reference: '11142960',
6870
returnId: 'v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
69-
returnLink: '/returns/return?id=v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
71+
returnLink: '/system/return-logs?id=v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
7072
returnPeriod: '1 November 2022 to 31 October 2023',
7173
returnStatus: 'completed',
7274
returnTotal: '0 ML / 0 ML'
@@ -109,7 +111,7 @@ describe('Bill Runs Review - Review Charge Element Service', () => {
109111
purpose: 'Spray Irrigation - Direct',
110112
reference: '11142960',
111113
returnId: 'v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
112-
returnLink: '/returns/return?id=v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
114+
returnLink: '/system/return-logs?id=v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
113115
returnPeriod: '1 November 2022 to 31 October 2023',
114116
returnStatus: 'completed',
115117
returnTotal: '0 ML / 0 ML'
@@ -121,5 +123,21 @@ describe('Bill Runs Review - Review Charge Element Service', () => {
121123
})
122124
})
123125
})
126+
127+
describe('and the "enableSystemReturnsView" flag is set to false', () => {
128+
beforeEach(() => {
129+
yarStub = { flash: Sinon.stub().withArgs('banner').returns([undefined]) }
130+
131+
Sinon.stub(FeatureFlagsConfig, 'enableSystemReturnsView').value(false)
132+
})
133+
134+
it('returns the "returnLink" URL to the legacy page', async () => {
135+
const result = await ReviewChargeElementService.go(reviewChargeElement.id, elementIndex, yarStub)
136+
137+
expect(result.matchedReturns[0].returnLink).to.equal(
138+
'/returns/return?id=v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31'
139+
)
140+
})
141+
})
124142
})
125143
})

test/services/bill-runs/review/review-licence.service.test.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const { expect } = Code
1212
const BillRunsReviewFixture = require('../../../fixtures/bill-runs-review.fixture.js')
1313

1414
// Things we need to stub
15+
const FeatureFlagsConfig = require('../../../../config/feature-flags.config.js')
1516
const FetchReviewLicenceService = require('../../../../app/services/bill-runs/review/fetch-review-licence.service.js')
1617

1718
// Thing under test
@@ -25,6 +26,7 @@ describe('Bill Runs Review - Review Licence Service', () => {
2526
beforeEach(() => {
2627
reviewLicence = BillRunsReviewFixture.reviewLicence()
2728

29+
Sinon.stub(FeatureFlagsConfig, 'enableSystemReturnsView').value(true)
2830
Sinon.stub(FetchReviewLicenceService, 'go').resolves(reviewLicence)
2931
})
3032

@@ -104,7 +106,7 @@ describe('Bill Runs Review - Review Licence Service', () => {
104106
purpose: 'Spray Irrigation - Direct',
105107
reference: '11142960',
106108
returnId: 'v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
107-
returnLink: '/returns/return?id=v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
109+
returnLink: '/system/return-logs?id=v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
108110
returnPeriod: '1 November 2022 to 31 October 2023',
109111
returnStatus: 'completed',
110112
returnTotal: '0 ML / 0 ML'
@@ -122,7 +124,7 @@ describe('Bill Runs Review - Review Licence Service', () => {
122124
purpose: 'Spray Irrigation - Storage',
123125
reference: '11142961',
124126
returnId: 'v1:5:1/11/11/*11/1111:11142961:2022-11-01:2023-10-31',
125-
returnLink: '/returns/return?id=v1:5:1/11/11/*11/1111:11142961:2022-11-01:2023-10-31',
127+
returnLink: '/system/return-logs?id=v1:5:1/11/11/*11/1111:11142961:2022-11-01:2023-10-31',
126128
returnPeriod: '1 November 2022 to 31 October 2023',
127129
returnStatus: 'completed',
128130
returnTotal: '0 ML / 0 ML'
@@ -203,7 +205,7 @@ describe('Bill Runs Review - Review Licence Service', () => {
203205
purpose: 'Spray Irrigation - Direct',
204206
reference: '11142960',
205207
returnId: 'v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
206-
returnLink: '/returns/return?id=v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
208+
returnLink: '/system/return-logs?id=v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31',
207209
returnPeriod: '1 November 2022 to 31 October 2023',
208210
returnStatus: 'completed',
209211
returnTotal: '0 ML / 0 ML'
@@ -221,7 +223,7 @@ describe('Bill Runs Review - Review Licence Service', () => {
221223
purpose: 'Spray Irrigation - Storage',
222224
reference: '11142961',
223225
returnId: 'v1:5:1/11/11/*11/1111:11142961:2022-11-01:2023-10-31',
224-
returnLink: '/returns/return?id=v1:5:1/11/11/*11/1111:11142961:2022-11-01:2023-10-31',
226+
returnLink: '/system/return-logs?id=v1:5:1/11/11/*11/1111:11142961:2022-11-01:2023-10-31',
225227
returnPeriod: '1 November 2022 to 31 October 2023',
226228
returnStatus: 'completed',
227229
returnTotal: '0 ML / 0 ML'
@@ -230,5 +232,24 @@ describe('Bill Runs Review - Review Licence Service', () => {
230232
})
231233
})
232234
})
235+
236+
describe('and the "enableSystemReturnsView" flag is set to false', () => {
237+
beforeEach(() => {
238+
yarStub = { flash: Sinon.stub().withArgs('banner').returns([undefined]) }
239+
240+
Sinon.stub(FeatureFlagsConfig, 'enableSystemReturnsView').value(false)
241+
})
242+
243+
it('returns the "returnLink" URL to the legacy page', async () => {
244+
const result = await ReviewLicenceService.go(reviewLicence.id, yarStub)
245+
246+
expect(result.matchedReturns[0].returnLink).to.equal(
247+
'/returns/return?id=v1:5:1/11/11/*11/1111:11142960:2022-11-01:2023-10-31'
248+
)
249+
expect(result.unmatchedReturns[0].returnLink).to.equal(
250+
'/returns/return?id=v1:5:1/11/11/*11/1111:11142961:2022-11-01:2023-10-31'
251+
)
252+
})
253+
})
233254
})
234255
})

0 commit comments

Comments
 (0)