-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/common error conditions order already exists #183
base: master
Are you sure you want to change the base?
Changes from all commits
4f09498
4095ccc
79265c1
80cdb76
09f4927
55036f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
const { FeatureHelper } = require('../../../../helpers/feature-helper'); | ||
const { GetMatch, C1, C2, B } = require('../../../../shared-behaviours'); | ||
const { itShouldReturnAnOpenBookingError } = require('../../../../shared-behaviours/errors'); | ||
const { RequestState } = require('../../../../helpers/request-state'); | ||
const { FlowHelper } = require('../../../../helpers/flow-helper'); | ||
const { generateUuid } = require('../../../../helpers/generate-uuid'); | ||
|
||
FeatureHelper.describeFeature(module, { | ||
testCategory: 'core', | ||
testFeature: 'common-error-conditions', | ||
testFeatureImplemented: true, | ||
testIdentifier: 'order-already-exists', | ||
testName: 'Expect an OrderAlreadyExistsError if an Order UUID exists but with different OrderItems', | ||
testDescription: 'Do a successful C1, C2, B run. Then, run B again for the same Order UUID, but with different OrderItems. Expect an OrderAlreadyExistsError.', | ||
// The primary opportunity criteria to use for the primary OrderItem under test | ||
testOpportunityCriteria: 'TestOpportunityBookablePaid', | ||
// The secondary opportunity criteria to use for multiple OrderItem tests | ||
controlOpportunityCriteria: 'TestOpportunityBookablePaid', | ||
numOpportunitiesUsedPerCriteria: 1, | ||
}, | ||
(configuration, orderItemCriteria, featureIsImplemented, logger) => { | ||
describe('OrderAlreadyExistsError at B', () => { | ||
const uuid = generateUuid(); | ||
|
||
/** | ||
* @param {Set<import('../../../../helpers/flow-helper').StageIdentifier>} [stagesToSkip] | ||
*/ | ||
function getMatchWithNewState(stagesToSkip) { | ||
const state = new RequestState(logger, { uuid }); | ||
const flow = new FlowHelper(state, { stagesToSkip }); | ||
|
||
// Get All Opportunities | ||
beforeAll(async () => { | ||
await state.fetchOpportunities(orderItemCriteria); | ||
}); | ||
|
||
describe('Get Opportunity Feed Items', () => { | ||
(new GetMatch({ | ||
state, flow, logger, orderItemCriteria, | ||
})) | ||
.beforeSetup() | ||
.successChecks() | ||
.validationTests(); | ||
}); | ||
|
||
return { state, flow }; | ||
} | ||
|
||
describe('First Run', () => { | ||
const { state, flow } = getMatchWithNewState(); | ||
|
||
describe('C1', () => { | ||
(new C1({ | ||
state, flow, logger, | ||
})) | ||
.beforeSetup() | ||
.successChecks() | ||
.validationTests(); | ||
}); | ||
|
||
describe('C2', () => { | ||
(new C2({ | ||
state, flow, logger, | ||
})) | ||
.beforeSetup() | ||
.successChecks() | ||
.validationTests(); | ||
}); | ||
|
||
describe('B first time', function () { | ||
(new B({ | ||
state, flow, logger, | ||
})) | ||
.beforeSetup() | ||
.successChecks() | ||
.validationTests(); | ||
}); | ||
}); | ||
|
||
|
||
describe('Second Run', async () => { | ||
const { state, flow } = getMatchWithNewState(new Set(['C1', 'C2'])); | ||
|
||
// Try B again with same UUID specified in state | ||
describe('B second time', function () { | ||
(new B({ | ||
state, flow, logger, | ||
})) | ||
.beforeSetup() | ||
.validationTests(); | ||
|
||
itShouldReturnAnOpenBookingError('OrderAlreadyExistsError', 500, () => state.bResponse); | ||
}); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,14 +207,33 @@ class RequestState { | |
return isResponse(this.c1Response); | ||
} | ||
|
||
/** | ||
* As leasing is optional, getting the totalPaymentDue should not be dependent on C1 or C2 being completed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although Leasing is optional C1 and C2 are not (ref: https://openactive.io/open-booking-api/EditorsDraft/#broker-contract-with-booking-system) So There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok, in that case the RefImpl needs to be changed as it returns a PaymentMismatchError when it shouldn't |
||
* However if they have been, they should be used as they will be more accurate. | ||
* | ||
* @readonly | ||
* @memberof RequestState | ||
* @returns {number | null} | ||
*/ | ||
get totalPaymentDue() { | ||
// Check if C1 or C2 have successfully happened | ||
const response = this.c2Response || this.c1Response; | ||
if (response) { | ||
if (!response.body.totalPaymentDue) return 0; | ||
|
||
if (!response) return; | ||
return response.body.totalPaymentDue.price; | ||
} | ||
|
||
// If C1 or C2 have not been successfully completed, work out the totalPriceDue from the orderItems | ||
if (this.orderItems) { | ||
const totalPriceDue = this.orderItems | ||
.map(orderItem => orderItem.acceptedOffer.price) | ||
.reduce((accumulator, currentValue) => accumulator + currentValue); | ||
|
||
if (!response.body.totalPaymentDue) return; | ||
return totalPriceDue; | ||
} | ||
|
||
return response.body.totalPaymentDue.price; | ||
return null; | ||
} | ||
|
||
async putOrderQuote() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,12 @@ const { expect } = require('chakram'); | |
const sharedValidationTests = require('./validation'); | ||
|
||
class B { | ||
/** | ||
* @param {object} args | ||
* @param {InstanceType<import('../helpers/request-state')['RequestState']>} args.state | ||
* @param {import('../helpers/flow-helper').FlowHelperType} args.flow | ||
* @param {import('../helpers/logger').BaseLoggerType} args.logger | ||
*/ | ||
Comment on lines
+5
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yasss |
||
constructor({ state, flow, logger }) { | ||
this.state = state; | ||
this.flow = flow; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should fix this #184 next time we change this, so we don't need to update this in each PR