-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbill_run_steps.js
307 lines (266 loc) · 10.5 KB
/
bill_run_steps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
// We disable this rule to prevent chai matchers like `to.be.empty` causing linting errors:
/* eslint-disable no-unused-expressions */
import { And, When, Then } from 'cypress-cucumber-preprocessor/steps'
import BillRunEndpoints from '../../endpoints/bill_run_endpoints'
When('I request a valid new {word} bill run', (ruleset) => {
BillRunEndpoints.create({ region: 'A', ruleset: ruleset }).then((response) => {
expect(response.status).to.equal(201)
cy.wrap(response.body.billRun).as('billRun')
})
})
And('I request another valid new {word} bill run', (ruleset) => {
BillRunEndpoints.create({ region: 'A', ruleset: ruleset }).then((response) => {
expect(response.status).to.equal(201)
cy.wrap(response.body.billRun).as('billRun1')
})
})
When('I request an invalid new bill run', () => {
BillRunEndpoints.createInvalid({ region: ' ' }).then((response) => {
expect(response.status).to.equal(422)
cy.wrap(response.body).as('error')
})
})
When('I request a valid new {word} bill run for {word}', (rulesetType, regionCode) => {
BillRunEndpoints.create({ region: `${regionCode}`, ruleset: `${rulesetType}` }).then((response) => {
expect(response.status).to.equal(201)
cy.wrap(response.body.billRun).as('billRun')
})
})
When('I request a valid new {word} bill run for region {word}', (rulesetType, regionCode) => {
BillRunEndpoints.create({ region: `${regionCode}`, ruleset: `${rulesetType}` }).then((response) => {
expect(response.status).to.equal(201)
cy.wrap(`${regionCode}`).as('billRunRegion')
cy.wrap(`${rulesetType}`).as('rulesetType')
cy.wrap(response.body.billRun).as('billRun')
})
})
When('I request an invalid new {word} bill run for {word}', (rulesetType, regionCode) => {
BillRunEndpoints.createInvalid({ region: `${regionCode}`, ruleset: `${rulesetType}` }).then((response) => {
expect(response.status).to.equal(422)
cy.wrap(response.body).as('error')
})
})
Then('I am told that acceptable values are presroc or sroc', () => {
cy.get('@error').then((error) => {
expect(error.message).to.equal('"ruleset" must be one of [presroc, sroc]')
})
})
Then('I am told that region must be one of A, B, E, N, S, T, W, Y', () => {
cy.get('@error').then((error) => {
expect(error.message).to.equal('"region" must be one of [A, B, E, N, S, T, W, Y]')
})
})
Then('I am told that region is required', () => {
cy.get('@error').then((error) => {
expect(error.message).to.equal('"region" is required')
})
})
Then('the bill run ID and number are returned', () => {
cy.get('@billRun').then((billRun) => {
expect(billRun.id).not.to.equal(null)
expect(billRun.billRunNumber).not.to.equal(null)
})
})
Then('the bill run numbers are issued in ascending order', () => {
cy.get('@billRun').then((billRun) => {
cy.get('@billRun1').then((billRun1) => {
expect(billRun1.billRunNumber).to.equal(billRun.billRunNumber + 1)
})
})
})
When('I request to view the bill run', () => {
cy.get('@billRun').then((billRun) => {
BillRunEndpoints.view(billRun.id).then((response) => {
expect(response.status).to.be.equal(200)
cy.wrap(response.body.billRun).as('viewBillRun')
})
})
})
Then('details of the bill run are returned', () => {
cy.get('@billRun').then((billRun) => {
BillRunEndpoints.view(billRun.id).then((response) => {
expect(response.status).to.equal(200)
expect(response.body).to.have.property('billRun')
expect(response.body.billRun.id).to.equal(billRun.id)
expect(response.body.billRun.billRunNumber).to.equal(billRun.billRunNumber)
expect(response.body.billRun.region).to.equal('A')
expect(response.body.billRun.status).to.equal('initialised')
})
})
})
Then('the bill run does not contain any transactions', () => {
cy.get('@billRun').then((billRun) => {
BillRunEndpoints.view(billRun.id).then((response) => {
expect(response.status).to.equal(200)
expect(response.body.billRun.invoices).to.be.empty
})
})
})
Then('the bill run does contain transactions', () => {
cy.get('@billRun').then((billRun) => {
BillRunEndpoints.view(billRun.id).then((response) => {
expect(response.status).to.equal(200)
expect(response.body.billRun.invoices).to.not.be.empty
})
})
})
Then('the bill run summary items are correct', () => {
cy.log('Testing Bill run summary items')
cy.get('@billRunRegion').then((billRunRegion) => {
const region = billRunRegion
cy.get('@rulesetType').then((rulesetType) => {
const ruleset = rulesetType
cy.get('@billRun').then((billRun) => {
const billRunId = billRun.id
const billRunNumber = billRun.billRunNumber
cy.get('@viewBillRun').then((billRun) => {
expect(billRun.id).to.equal(billRunId)
expect(billRun.billRunNumber).to.equal(billRunNumber)
expect(billRun.ruleset).to.equal(ruleset)
expect(billRun.region).to.equal(region)
expect(billRun.transactionFileReference).to.equal(null)
})
})
})
})
})
Then('the bill run summary includes the expected items', (dataTable) => {
cy.wrap(dataTable.rawTable).each(row => {
const status = row[0]
const expectedCreditNoteCount = Number(row[1])
const expectedCreditNoteValue = Number(row[2])
const expectedInvoiceCount = Number(row[3])
const expectedInvoiceValue = Number(row[4])
const expectedNetTotal = Number(row[5])
cy.log('Testing Bill run summary items')
cy.get('@viewBillRun').then((billRun) => {
expect(billRun.status).to.equal(status)
expect(billRun.creditNoteCount).to.equal(expectedCreditNoteCount)
expect(billRun.creditNoteValue).to.equal(expectedCreditNoteValue)
expect(billRun.invoiceCount).to.equal(expectedInvoiceCount)
expect(billRun.invoiceValue).to.equal(expectedInvoiceValue)
expect(billRun.netTotal).to.equal(expectedNetTotal)
})
})
})
And('I request to generate the bill run', () => {
cy.get('@billRun').then((billRun) => {
BillRunEndpoints.generate(billRun.id, false).then((response) => {
expect(response.status).to.be.equal(204)
})
})
})
And('I request to approve the bill run', () => {
cy.get('@billRun').then((billRun) => {
BillRunEndpoints.approve(billRun.id).then((response) => {
expect(response.status).to.be.equal(204)
})
})
})
And('I request to send the bill run', () => {
cy.get('@billRun').then((billRun) => {
BillRunEndpoints.send(billRun.id).then((response) => {
expect(response.status).to.be.equal(204)
})
})
})
And('I request to delete the bill run', () => {
cy.get('@billRun').then((billRun) => {
BillRunEndpoints.delete(billRun.id).then((response) => {
expect(response.status).to.be.equal(204)
})
})
})
And('I try to delete the bill run', () => {
cy.get('@billRun').then((billRun) => {
BillRunEndpoints.delete(billRun.id, false).then((response) => {
cy.wrap(response).as('response')
})
})
})
Then('I am told the bill run cannot be deleted because its billed', () => {
cy.get('@billRun').then((billRun) => {
cy.get('@response').then((response) => {
expect(response.status).to.equal(409)
expect(response.body).to.have.property('error')
expect(response.body.message).to.equal(`Bill run ${billRun.id} cannot be edited because its status is billed.`)
})
})
})
Then('I am told the bill run cannot be deleted because its approved', () => {
cy.get('@billRun').then((billRun) => {
cy.get('@response').then((response) => {
expect(response.status).to.equal(409)
expect(response.body).to.have.property('error')
expect(response.body.message).to.equal(`Bill run ${billRun.id} cannot be edited because its status is approved.`)
})
})
})
Then('I am told the bill run cannot be deleted because its billing not required', () => {
cy.get('@billRun').then((billRun) => {
cy.get('@response').then((response) => {
expect(response.status).to.equal(409)
expect(response.body).to.have.property('error')
expect(response.body.message).to.equal(`Bill run ${billRun.id} cannot be edited because its status is billing_not_required.`)
})
})
})
Then('bill run is not found', () => {
cy.get('@billRun').then((billRun) => {
BillRunEndpoints.view(billRun.id, false).then((response) => {
expect(response.status).to.equal(404)
expect(response.body.error).to.equal('Not Found')
expect(response.body.message).to.equal('Bill run ' + billRun.id + ' is unknown.')
})
})
})
Then('bill run status is updated to {string}', (status) => {
cy.get('@billRun').then((billRun) => {
BillRunEndpoints.pollForStatus(billRun.id, status).then((response) => {
expect(response.status).to.equal(200)
expect(response.body.status).to.equal(status)
})
})
})
Then('I am told the bill run status must be {string}', (status) => {
cy.get('@billRun').then((billRun) => {
const billRunId = billRun.id
cy.get('@response').then((response) => {
expect(response.body.error).to.equal('Conflict')
expect(response.body.message).to.equal(`Bill run ${billRunId} does not have a status of '${status}'.`)
})
})
})
And('I attempt to request to approve the bill run', () => {
cy.get('@billRun').then((billRun) => {
BillRunEndpoints.approve(billRun.id, false).then((response) => {
expect(response.status).to.be.equal(409)
cy.wrap(response).as('response')
})
})
})
And('I request to send an unapproved bill run I am told the bill run does not have status of approved', () => {
cy.get('@billRun').then((billRun) => {
BillRunEndpoints.send(billRun.id, false).then((response) => {
expect(response.status).to.be.equal(409)
expect(response.body.error).to.equal('Conflict')
expect(response.body.message).to.equal(`Bill run ${billRun.id} does not have a status of 'approved'.`)
})
})
})
And('I request to send the bill run and I am told it cannot be updated because its billed', () => {
cy.get('@billRun').then((billRun) => {
BillRunEndpoints.send(billRun.id, false).then((response) => {
expect(response.status).to.be.equal(409)
expect(response.body.error).to.equal('Conflict')
expect(response.body.message).to.equal(`Bill run ${billRun.id} cannot be patched because its status is billed.`)
})
})
})
Then('a transaction reference is not generated for {word}', (customerRef) => {
cy.log('Checking transaction reference is NOT generated')
cy.get('@viewBillRun').then((billRun) => {
const invoice = billRun.invoices.find(element => element.customerReference === customerRef)
expect(invoice.transactionReference).to.equal(null)
})
})