Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/upgrade-puppeteer' into …
Browse files Browse the repository at this point in the history
…feature/docker-and-package-upgrades-new
  • Loading branch information
lukehesluke committed Oct 9, 2023
2 parents d3c7d5e + 198942a commit 405d66d
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,17 @@ export function getRemainingCapacity(opportunity: Opportunity): number | null |
*
* @param {Offer} offer
* @param {Opportunity} opportunity
* @returns {DateTime | null} null if there is no booking window defined.
* @returns {DateTime | null} null if there is no booking window lower limit defined.
*/
export function getDateAfterWhichBookingsCanBeMade(offer: Offer, opportunity: Opportunity): DateTime | null;
/**
* Get the date that the startDate - validThroughBeforeStartDate window starts
*
* @param {Offer} offer
* @param {Opportunity} opportunity
* @returns {DateTime | null} null if there is no booking window upper limit defined.
*/
export function getDateBeforeWhichBookingsCanBeMade(offer: Offer, opportunity: Opportunity): DateTime | null;
/**
* @param {Offer} offer
* @param {Opportunity} opportunity
Expand All @@ -72,7 +80,7 @@ export function startDateMustBe2HrsInAdvance(opportunity: import("../types/Oppor
export function endDateMustBeInThePast(opportunity: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
export function eventStatusMustNotBeCancelledOrPostponed(opportunity: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
export function mustNotBeOpenBookingInAdvanceUnavailable(offer: import("../types/Offer").Offer, opportunity?: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
export function mustHaveBeInsideValidFromBeforeStartDateWindow(offer: import("../types/Offer").Offer, opportunity?: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
export function mustBeInsideBookingWindowIfOneExists(offer: import("../types/Offer").Offer, opportunity?: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
/**
* For a session, get `organizer`. For a facility, get `provider`.
* These can be used interchangeably as `organizer` is either a Person or an Organization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {
createCriteria,
remainingCapacityMustBeAtLeastTwo,
mustNotBeOpenBookingInAdvanceUnavailable,
mustHaveBeInsideValidFromBeforeStartDateWindow,
mustBeInsideBookingWindowIfOneExists,
sellerMustAllowOpenBooking,
} = require('./criteriaUtils');
const {
Expand Down Expand Up @@ -31,8 +31,8 @@ const TestOpportunityBookable = createCriteria({
mustNotBeOpenBookingInAdvanceUnavailable,
],
[
'Must be within validFromBeforeStartDate window',
mustHaveBeInsideValidFromBeforeStartDateWindow,
'Must be within the booking window (`validFromBeforeStartDate` and/or `validThroughBeforeStartDate`) if one exists',
mustBeInsideBookingWindowIfOneExists,
],
],
testDataShape: (options) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
mustRequireAdditionalDetails,
remainingCapacityMustBeAtLeastTwo,
mustNotBeOpenBookingInAdvanceUnavailable,
mustHaveBeInsideValidFromBeforeStartDateWindow,
mustBeInsideBookingWindowIfOneExists,
mustNotRequireAttendeeDetails,
sellerMustAllowOpenBooking,
} = require('./criteriaUtils');
Expand All @@ -31,8 +31,8 @@ const TestOpportunityBookableAdditionalDetails = createCriteria({
mustNotBeOpenBookingInAdvanceUnavailable,
],
[
'Must be within validFromBeforeStartDate window',
mustHaveBeInsideValidFromBeforeStartDateWindow,
'Must be within the booking window (`validFromBeforeStartDate` and/or `validThroughBeforeStartDate`) if one exists',
mustBeInsideBookingWindowIfOneExists,
],
[
'Must require additional details',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
mustRequireAttendeeDetails,
remainingCapacityMustBeAtLeastTwo,
mustNotBeOpenBookingInAdvanceUnavailable,
mustHaveBeInsideValidFromBeforeStartDateWindow,
mustBeInsideBookingWindowIfOneExists,
mustNotRequireAdditionalDetails,
sellerMustAllowOpenBooking,
} = require('./criteriaUtils');
Expand All @@ -28,8 +28,8 @@ const TestOpportunityBookableAttendeeDetails = createCriteria({
mustNotBeOpenBookingInAdvanceUnavailable,
],
[
'Must be within validFromBeforeStartDate window',
mustHaveBeInsideValidFromBeforeStartDateWindow,
'Must be within the booking window (`validFromBeforeStartDate` and/or `validThroughBeforeStartDate`) if one exists',
mustBeInsideBookingWindowIfOneExists,
],
[
'Must require attendee details',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const {
createCriteria,
remainingCapacityMustBeAtLeastTwo,
mustNotBeOpenBookingInAdvanceUnavailable,
mustHaveBeInsideValidFromBeforeStartDateWindow,
sellerMustAllowOpenBooking,
endDateMustBeInThePast,
eventStatusMustNotBeCancelledOrPostponed,
Expand Down Expand Up @@ -43,10 +42,6 @@ const TestOpportunityBookableInPast = createCriteria({
'openBookingInAdvance of offer must not be `https://openactive.io/Unavailable`',
mustNotBeOpenBookingInAdvanceUnavailable,
],
[
'Must be within validFromBeforeStartDate window',
mustHaveBeInsideValidFromBeforeStartDateWindow,
],
[
'Must not require attendee details',
mustNotRequireAttendeeDetails,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { createCriteria, getRemainingCapacity, mustNotBeOpenBookingInAdvanceUnavailable, mustHaveBeInsideValidFromBeforeStartDateWindow } = require('./criteriaUtils');
const { createCriteria, getRemainingCapacity, mustNotBeOpenBookingInAdvanceUnavailable, mustBeInsideBookingWindowIfOneExists } = require('./criteriaUtils');
const { quantitativeValue, shapeConstraintRecipes } = require('../testDataShape');
const { InternalCriteriaFutureScheduledAndDoesNotRequireDetails } = require('./internal/InternalCriteriaFutureScheduledAndDoesNotRequireDetails');

Expand Down Expand Up @@ -30,8 +30,8 @@ const TestOpportunityBookableNoSpaces = createCriteria({
mustNotBeOpenBookingInAdvanceUnavailable,
],
[
'Must be within validFromBeforeStartDate window',
mustHaveBeInsideValidFromBeforeStartDateWindow,
'Must be within the booking window (`validFromBeforeStartDate` and/or `validThroughBeforeStartDate`) if one exists',
mustBeInsideBookingWindowIfOneExists,
],
],
testDataShape: (options) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {
createCriteria,
remainingCapacityMustBeAtLeastTwo,
mustNotBeOpenBookingInAdvanceUnavailable,
mustHaveBeInsideValidFromBeforeStartDateWindow,
mustBeInsideBookingWindowIfOneExists,
sellerMustAllowOpenBooking,
mustNotRequireAttendeeDetails,
mustNotRequireAdditionalDetails,
Expand Down Expand Up @@ -50,8 +50,8 @@ const TestOpportunityBookableNonFreePrepaymentUnavailable = createCriteria({
mustNotBeOpenBookingInAdvanceUnavailable,
],
[
'Must be within validFromBeforeStartDate window',
mustHaveBeInsideValidFromBeforeStartDateWindow,
'Must be within the booking window (`validFromBeforeStartDate` and/or `validThroughBeforeStartDate`) if one exists',
mustBeInsideBookingWindowIfOneExists,
],
[
'Only paid bookable offers with openBookingPrepayment unavailable',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {
createCriteria,
getRemainingCapacity,
mustNotBeOpenBookingInAdvanceUnavailable,
mustHaveBeInsideValidFromBeforeStartDateWindow,
mustBeInsideBookingWindowIfOneExists,
sellerMustAllowOpenBooking,
} = require('./criteriaUtils');
const {
Expand Down Expand Up @@ -42,8 +42,8 @@ const TestOpportunityBookableOneSpace = createCriteria({
mustNotBeOpenBookingInAdvanceUnavailable,
],
[
'Must be within validFromBeforeStartDate window',
mustHaveBeInsideValidFromBeforeStartDateWindow,
'Must be within the booking window (`validFromBeforeStartDate` and/or `validThroughBeforeStartDate`) if one exists',
mustBeInsideBookingWindowIfOneExists,
],
],
testDataShape: (options) => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getDateAfterWhichBookingsCanBeMade, remainingCapacityMustBeAtLeastTwo, createCriteria, mustNotBeOpenBookingInAdvanceUnavailable } = require('./criteriaUtils');
const { getDateAfterWhichBookingsCanBeMade, getDateBeforeWhichBookingsCanBeMade, remainingCapacityMustBeAtLeastTwo, createCriteria, mustNotBeOpenBookingInAdvanceUnavailable } = require('./criteriaUtils');
const { dateRange, shapeConstraintRecipes } = require('../testDataShape');
const { InternalCriteriaFutureScheduledAndDoesNotRequireDetails } = require('./internal/InternalCriteriaFutureScheduledAndDoesNotRequireDetails');

Expand All @@ -11,13 +11,12 @@ const { InternalCriteriaFutureScheduledAndDoesNotRequireDetails } = require('./i
*/
function mustHaveBookingWindowAndBeOutsideOfIt(offer, opportunity, options) {
const dateAfterWhichBookingsCanBeMade = getDateAfterWhichBookingsCanBeMade(offer, opportunity);
if (dateAfterWhichBookingsCanBeMade == null) {
return false; // has no booking window
}
const dateBeforeWhichBookingsCanBeMade = getDateBeforeWhichBookingsCanBeMade(offer, opportunity);
/* If, within 2 hours, the booking window would be reached, it may be possible for this to happen
during the test run. So, to be on the safe side, we only accept Opportunities whose booking window
starts at least 2 hours in the future. */
return options.harvestStartTimeTwoHoursLater < dateAfterWhichBookingsCanBeMade;
return (dateAfterWhichBookingsCanBeMade !== null && options.harvestStartTimeTwoHoursLater < dateAfterWhichBookingsCanBeMade)
|| (dateBeforeWhichBookingsCanBeMade !== null && options.harvestStartTime > dateBeforeWhichBookingsCanBeMade);
}

/**
Expand All @@ -37,7 +36,7 @@ const TestOpportunityBookableOutsideValidFromBeforeStartDate = createCriteria({
mustNotBeOpenBookingInAdvanceUnavailable,
],
[
'Must be outside booking window (`validFromBeforeStartDate`)',
'Must have a booking window (`validFromBeforeStartDate` and/or `validThroughBeforeStartDate`) and be outside of it',
mustHaveBookingWindowAndBeOutsideOfIt,
],
],
Expand All @@ -51,6 +50,9 @@ const TestOpportunityBookableOutsideValidFromBeforeStartDate = createCriteria({
'oa:validFromBeforeStartDate': dateRange({
minDate: options.harvestStartTimeTwoHoursLater.toISO(),
}),
'oa:validThroughBeforeStartDate': dateRange({
maxDate: options.harvestStartTime.toISO(),
}),
},
}),
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { TestOpportunityBookable } = require('./TestOpportunityBookable');
const { createCriteria, getDateAfterWhichBookingsCanBeMade } = require('./criteriaUtils');
const { createCriteria, getDateAfterWhichBookingsCanBeMade, getDateBeforeWhichBookingsCanBeMade } = require('./criteriaUtils');
const { dateRange } = require('../testDataShape');

/**
Expand All @@ -11,18 +11,23 @@ const { dateRange } = require('../testDataShape');
*/
function mustHaveBookingWindowAndBeWithinIt(offer, opportunity, options) {
const dateAfterWhichBookingsCanBeMade = getDateAfterWhichBookingsCanBeMade(offer, opportunity);
if (dateAfterWhichBookingsCanBeMade == null) {
const dateBeforeWhichBookingsCanBeMade = getDateBeforeWhichBookingsCanBeMade(offer, opportunity);
if (dateAfterWhichBookingsCanBeMade == null && dateBeforeWhichBookingsCanBeMade == null) {
return false; // has no booking window
}
return options.harvestStartTime > dateAfterWhichBookingsCanBeMade;
/* If, within 2 hours, the end of the booking window would be reached, it may be possible for this to happen
during the test run. So, to be on the safe side, we only accept Opportunities whose booking window
ends at least 2 hours in the future. */
return (dateAfterWhichBookingsCanBeMade == null || options.harvestStartTime > dateAfterWhichBookingsCanBeMade)
&& (dateBeforeWhichBookingsCanBeMade == null || options.harvestStartTimeTwoHoursLater < dateBeforeWhichBookingsCanBeMade);
}

const TestOpportunityBookableWithinValidFromBeforeStartDate = createCriteria({
name: 'TestOpportunityBookableWithinValidFromBeforeStartDate',
opportunityConstraints: [],
offerConstraints: [
[
'Must have booking window (`validFromBeforeStartDate`) and be within it',
'Must have a booking window (`validFromBeforeStartDate` and/or `validThroughBeforeStartDate`) and be within it',
mustHaveBookingWindowAndBeWithinIt,
],
],
Expand All @@ -34,6 +39,10 @@ const TestOpportunityBookableWithinValidFromBeforeStartDate = createCriteria({
maxDate: options.harvestStartTime.toISO(),
// This differs from TestOpportunityBookable as it does not allow null values
}),
'oa:validThroughBeforeStartDate': dateRange({
minDate: options.harvestStartTimeTwoHoursLater.toISO(),
// This differs from TestOpportunityBookable as it does not allow null values
}),
},
}),
});
Expand Down
30 changes: 25 additions & 5 deletions packages/test-interface-criteria/src/criteria/criteriaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function dateMinusDuration(datetimeIso, durationIso) {
*
* @param {Offer} offer
* @param {Opportunity} opportunity
* @returns {DateTime | null} null if there is no booking window defined.
* @returns {DateTime | null} null if there is no booking window lower limit defined.
*/
function getDateAfterWhichBookingsCanBeMade(offer, opportunity) {
if (!offer || !offer.validFromBeforeStartDate) {
Expand All @@ -288,6 +288,21 @@ function getDateAfterWhichBookingsCanBeMade(offer, opportunity) {
return dateMinusDuration(opportunity.startDate, offer.validFromBeforeStartDate);
}

/**
* Get the date that the startDate - validThroughBeforeStartDate window starts
*
* @param {Offer} offer
* @param {Opportunity} opportunity
* @returns {DateTime | null} null if there is no booking window upper limit defined.
*/
function getDateBeforeWhichBookingsCanBeMade(offer, opportunity) {
if (!offer || !offer.validThroughBeforeStartDate) {
return null; // has no booking window
}

return dateMinusDuration(opportunity.startDate, offer.validThroughBeforeStartDate);
}

/**
* @type {OfferConstraint}
*/
Expand Down Expand Up @@ -375,10 +390,14 @@ function mustNotBeOpenBookingInAdvanceUnavailable(offer) {
/**
* @type {OfferConstraint}
*/
function mustHaveBeInsideValidFromBeforeStartDateWindow(offer, opportunity, options) {
function mustBeInsideBookingWindowIfOneExists(offer, opportunity, options) {
const dateAfterWhichBookingsCanBeMade = getDateAfterWhichBookingsCanBeMade(offer, opportunity);
if (dateAfterWhichBookingsCanBeMade == null) { return true; } // no booking window - therefore bookable at any time
return options.harvestStartTime > dateAfterWhichBookingsCanBeMade;
const dateBeforeWhichBookingsCanBeMade = getDateBeforeWhichBookingsCanBeMade(offer, opportunity);
/* If, within 2 hours, the end of the booking window would be reached, it may be possible for this to happen
during the test run. So, to be on the safe side, we only accept Opportunities whose booking window
ends at least 2 hours in the future. */
return (dateAfterWhichBookingsCanBeMade == null || options.harvestStartTime > dateAfterWhichBookingsCanBeMade)
&& (dateBeforeWhichBookingsCanBeMade == null || options.harvestStartTimeTwoHoursLater < dateBeforeWhichBookingsCanBeMade);
}

/**
Expand Down Expand Up @@ -477,6 +496,7 @@ module.exports = {
getType,
getRemainingCapacity,
getDateAfterWhichBookingsCanBeMade,
getDateBeforeWhichBookingsCanBeMade,
getDateBeforeWhichCancellationsCanBeMade,
hasCapacityLimitOfOne,
remainingCapacityMustBeAtLeastTwo,
Expand All @@ -487,7 +507,7 @@ module.exports = {
endDateMustBeInThePast,
eventStatusMustNotBeCancelledOrPostponed,
mustNotBeOpenBookingInAdvanceUnavailable,
mustHaveBeInsideValidFromBeforeStartDateWindow,
mustBeInsideBookingWindowIfOneExists,
getOrganizerOrProvider,
mustBeOutsideCancellationWindow,
mustNotAllowFullRefund,
Expand Down

0 comments on commit 405d66d

Please sign in to comment.