Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Wilson committed Oct 16, 2020
1 parent 1a73970 commit 2009a79
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
Expand Up @@ -2,6 +2,7 @@ const chai = require('chai');
const chakram = require('chakram');
const { FeatureHelper } = require('../../../../helpers/feature-helper');
const { GetMatch, C1, C2 } = require('../../../../shared-behaviours');
const { Common } = require('../../../../shared-behaviours/common');

/**
* @typedef {import('chakram').ChakramResponse} ChakramResponse
Expand All @@ -20,23 +21,6 @@ function itShouldReturn409Conflict(stage, responseAccessor) {
});
}

/**
* @param {C1|C2} stage
* @param {() => ChakramResponse} responseAccessor This is wrapped in a
* function because the actual response won't be available until the
* asynchronous before() block has completed.
*/
function itShouldReturnOpportunityOfferPairNotBookableError(stage, responseAccessor) {
it('should return OpportunityOfferPairNotBookableError', () => {
stage.expectResponseReceived();

const response = responseAccessor();
const errors = response.body.orderedItem.map(oi => oi.error && oi.error[0] && oi.error[0]['@type']).filter(e => !!e);

chai.expect(errors.every(e => e === 'OpportunityOfferPairNotBookableError')).to.equal(true);
});
}

FeatureHelper.describeFeature(module, {
testCategory: 'restrictions',
testFeature: 'booking-window',
Expand Down Expand Up @@ -78,6 +62,14 @@ FeatureHelper.describeFeature(module, {
.validationTests();

itShouldReturn409Conflict(c2, () => state.c2Response);
itShouldReturnOpportunityOfferPairNotBookableError(c2, () => state.c2Response);
Common.itForOrderItemByControl(orderItemCriteria, state, c2, () => state.c2Response.body,
'should include an OpportunityOfferPairNotBookableError',
(feedOrderItem, responseOrderItem, responseOrderItemErrorTypes) => {
chai.expect(responseOrderItemErrorTypes).to.include('OpportunityOfferPairNotBookableError');
},
'should not include an OpportunityOfferPairNotBookableError',
(feedOrderItem, responseOrderItem, responseOrderItemErrorTypes) => {
chai.expect(responseOrderItemErrorTypes).not.to.include('OpportunityOfferPairNotBookableError');
});
});
});
Expand Up @@ -10,10 +10,10 @@ const { remainingCapacityMustBeAtLeastTwo, createCriteria } = require('../criter
/**
* @type {OfferConstraint}
*/
function mustHaveBookableOffer(offer, opportunity) {
function mustHaveBookableOffer(offer, opportunity, options) {
return (Array.isArray(offer.availableChannel) && offer.availableChannel.includes('https://openactive.io/OpenBookingPrepayment'))
&& offer.advanceBooking !== 'https://openactive.io/Unavailable'
&& (!offer.validFromBeforeStartDate || moment(opportunity.startDate).subtract(moment.duration(offer.validFromBeforeStartDate)).isBefore());
&& (!offer.validFromBeforeStartDate || moment(opportunity.startDate).subtract(moment.duration(offer.validFromBeforeStartDate)).isBefore(options.harvestStartTime));
}

/**
Expand Down

0 comments on commit 2009a79

Please sign in to comment.