Skip to content
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

chore(criteria): Unit test that criteria ShEx constraints match non-ShEx constraints #628

Merged
merged 29 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b6e0588
partially able to generate opportunity data. WIP
lukehesluke Feb 19, 2024
7df7d16
Merge remote-tracking branch 'origin/master' into feature/shape-expre…
lukehesluke Feb 19, 2024
5696e70
much progress. Still not there
lukehesluke Feb 19, 2024
5dee3d4
test passes in some instances, though found an issue with validFromBe…
lukehesluke Feb 19, 2024
c593527
weve got a consistent pass for TestOpportunityBookable
lukehesluke Feb 19, 2024
34224bd
about half of the test space passes
lukehesluke Feb 19, 2024
3697046
fix(criteria): Move termsOfService to opportunityConstraints in TestO…
lukehesluke Feb 19, 2024
4f705c0
fix negative prices being set for free offers
lukehesluke Feb 19, 2024
5630cf8
feat(criteria) Add testDataShape for TestOpportunityBookableNonFreePr…
lukehesluke Feb 19, 2024
bc31993
feat(criteria) Add testDataShape for TestOpportunityBookableInPast
lukehesluke Feb 19, 2024
542686a
fix TestOpportunityBookableAttendeeDetails issue
lukehesluke Feb 19, 2024
5e9dafb
fix latestCancellationBeforeStartDate issue
lukehesluke Feb 19, 2024
ee540ef
fix TestOpportunityBookableOutsideValidFromBeforeStartDate
lukehesluke Feb 19, 2024
3b60279
fix(criteria): disallow >1 spaces for TestOpportunityBookableOneSpace…
lukehesluke Feb 19, 2024
85f1283
fix(criteria): include IFU Slot ShEx for TestOpportunityBookableNoSpaces
lukehesluke Feb 19, 2024
e57e327
fix(criteria): Fix testDataShape merging logic to prefer extension pr…
lukehesluke Feb 19, 2024
3b9e604
fix some >=/> issues
lukehesluke Feb 19, 2024
0400772
fix remainingUses not being properly checked against IFUness
lukehesluke Feb 19, 2024
007eac2
tests all consistently pass!
lukehesluke Feb 19, 2024
352135a
complete
lukehesluke Feb 20, 2024
0449916
remove faker-js
lukehesluke Feb 20, 2024
ff057ab
minor fixes
lukehesluke Feb 20, 2024
8d680bf
move TODO into an issue
lukehesluke Feb 20, 2024
4378331
add validThroughBeforeStartDate to type and apply +/-1s corrections t…
lukehesluke Feb 20, 2024
5a3d0b3
fix lint issues
lukehesluke Feb 20, 2024
a7f6efe
minor fix
lukehesluke Feb 20, 2024
6ac3eee
minor fix
lukehesluke Feb 20, 2024
0acc385
remove obsolete built types
lukehesluke Feb 20, 2024
944269e
Merge remote-tracking branch 'origin/master' into feature/shape-expre…
lukehesluke Feb 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@
"NODE_APP_INSTANCE": "dev"
},
},
{
"name": "test-interface-criteria - unit tests",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}/packages/test-interface-criteria/",
"runtimeArgs": [
"--inspect-brk",
"node_modules/.bin/jest",
"--runInBand"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"name": "validate-feeds",
"type": "node",
Expand Down
1 change: 1 addition & 0 deletions packages/openactive-integration-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/test-interface-criteria/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
extends: 'airbnb-base',
env: {
node: true,
'jest/globals': true,
},
globals: {
expectAsync: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookable.
*/
export const TestOpportunityBookable: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TestOpportunityBookableAdditionalDetails: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TestOpportunityBookableAttendeeDetails: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type OfferConstraint = import('../types/Criteria').OfferConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableCancellable
*/
export const TestOpportunityBookableCancellable: import("../types/Criteria").Criteria;
export const mustBeWithinCancellationWindowOrHaveNoWindowOfferConstraint: [string, import("../types/Criteria").OfferConstraint];
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type OfferConstraint = import('../types/Criteria').OfferConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableCancellableNoWindow
*/
export const TestOpportunityBookableCancellableNoWindow: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type OfferConstraint = import('../types/Criteria').OfferConstraint;
/**
* @typedef {import('../types/Criteria').OfferConstraint} OfferConstraint
*/
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableCancellableOutsideWindow
*/
export const TestOpportunityBookableCancellableOutsideWindow: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Note that this criteria will ALWAYS reject any event whose latestCancellationBeforeStartDate
* duration is less than 2 hours. This is because this will conflict with the
* `startDateMustBe2HrsInAdvance` constraint (from `InternalCriteriaFutureScheduledOpportunity`).
*
* Implements https://openactive.io/test-interface#TestOpportunityBookableCancellableWithinWindow
*/
export const TestOpportunityBookableCancellableWithinWindow: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type OpportunityConstraint = import('../types/Criteria').OpportunityConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableFiveSpaces
*/
export const TestOpportunityBookableFiveSpaces: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type OfferConstraint = import('../types/Criteria').OfferConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableFree
*/
export const TestOpportunityBookableFree: import("../types/Criteria").Criteria;
export const onlyFreeBookableOffersWithUnavailablePrepaymentOfferConstraint: [string, import("../types/Criteria").OfferConstraint];
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableFreeCancellable
*/
export const TestOpportunityBookableFreeCancellable: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type OfferConstraint = import('../types/Criteria').OfferConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableFreePrepaymentOptional
*/
export const TestOpportunityBookableFreePrepaymentOptional: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type OfferConstraint = import('../types/Criteria').OfferConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableFreePrepaymentRequired
*/
export const TestOpportunityBookableFreePrepaymentRequired: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type OfferConstraint = import('../types/Criteria').OfferConstraint;
/**
* @typedef {import('../types/Criteria').OfferConstraint} OfferConstraint
*/
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableInPast
*/
export const TestOpportunityBookableInPast: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type OpportunityConstraint = import('../types/Criteria').OpportunityConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableNoSpaces
*/
export const TestOpportunityBookableNoSpaces: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type OfferConstraint = import('../types/Criteria').OfferConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableNonFree
*/
export const TestOpportunityBookableNonFree: import("../types/Criteria").Criteria;
export const onlyNonFreeBookableOfferConstraint: [string, import("../types/Criteria").OfferConstraint];
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableNonFreeCancellable
*/
export const TestOpportunityBookableNonFreeCancellable: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type OfferConstraint = import('../types/Criteria').OfferConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableNonFreePrepaymentOptional
*/
export const TestOpportunityBookableNonFreePrepaymentOptional: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type OfferConstraint = import('../types/Criteria').OfferConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableNonFreePrepaymentRequired
*/
export const TestOpportunityBookableNonFreePrepaymentRequired: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type OfferConstraint = import('../types/Criteria').OfferConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableNonFreePrepaymentUnavailable
*/
export const TestOpportunityBookableNonFreePrepaymentUnavailable: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type OpportunityConstraint = import('../types/Criteria').OpportunityConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableNonFreeTaxGross.
*/
export const TestOpportunityBookableNonFreeTaxGross: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type OpportunityConstraint = import('../types/Criteria').OpportunityConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableNonFreeTaxNet.
*/
export const TestOpportunityBookableNonFreeTaxNet: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableNotCancellable
*/
export const TestOpportunityBookableNotCancellable: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type OpportunityConstraint = import('../types/Criteria').OpportunityConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableOneSpace
*/
export const TestOpportunityBookableOneSpace: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type OfferConstraint = import('../types/Criteria').OfferConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableOutsideValidFromBeforeStartDate
*/
export const TestOpportunityBookableOutsideValidFromBeforeStartDate: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type OpportunityConstraint = import('../types/Criteria').OpportunityConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableSellerTermsOfService
*/
export const TestOpportunityBookableSellerTermsOfService: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type OfferConstraint = import('../types/Criteria').OfferConstraint;
/**
* Implements https://openactive.io/test-interface#TestOpportunityBookableUsingPayment
*/
export const TestOpportunityBookableUsingPayment: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TestOpportunityBookableWithNegotiation: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type OfferConstraint = import('../types/Criteria').OfferConstraint;
export const TestOpportunityBookableWithinValidFromBeforeStartDate: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TestOpportunityOfflineBookable: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TestOpportunityOnlineBookable: import("../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
export type Opportunity = import('../types/Opportunity').Opportunity;
export type Offer = import('../types/Offer').Offer;
export type Options = import('../types/Options').Options;
export type OpportunityConstraint = import('../types/Criteria').OpportunityConstraint;
export type OfferConstraint = import('../types/Criteria').OfferConstraint;
export type Criteria = import('../types/Criteria').Criteria;
export type TestDataShapeFactory = import('../types/Criteria').TestDataShapeFactory;
export type TestDataShape = import('../types/TestDataShape').TestDataShape;
export type TestDataNodeConstraint = import('../types/TestDataShape').TestDataNodeConstraint;
export type DateRangeNodeConstraint = import('../types/TestDataShape').DateRangeNodeConstraint;
export type NumericNodeConstraint = import('../types/TestDataShape').NumericNodeConstraint;
export type ArrayConstraint = import("../types/TestDataShape").ArrayConstraint<any, any>;
/**
* @param {object} args
* @param {string} args.name
* @param {Criteria['opportunityConstraints']} args.opportunityConstraints
* @param {Criteria['offerConstraints']} args.offerConstraints
* @param {Criteria['testDataShape']} args.testDataShape
* @param {Criteria | null} [args.includeConstraintsFromCriteria] If provided,
* opportunity and offer constraints will be included from this criteria.
* @returns {Criteria}
*/
export function createCriteria({ name, opportunityConstraints, offerConstraints, testDataShape: testDataShapeFactory, includeConstraintsFromCriteria, }: {
name: string;
opportunityConstraints: Criteria['opportunityConstraints'];
offerConstraints: Criteria['offerConstraints'];
testDataShape: Criteria['testDataShape'];
includeConstraintsFromCriteria?: Criteria | null;
}): Criteria;
/**
* @param {Opportunity} opportunity
* @returns {string}
*/
export function getId(opportunity: Opportunity): string;
/**
* @param {Opportunity} opportunity
* @returns {string}
*/
export function getType(opportunity: Opportunity): string;
/**
* @param {Opportunity} opportunity
* @returns {number | null | undefined} Not all opportunities have
* remainingAttendeeCapacity (which is optional in ScheduledSessions) or
* remainingUses, therefore the return value may be null-ish.
*/
export function getRemainingCapacity(opportunity: Opportunity): number | null | undefined;
/**
* Get the date that the startDate - validFromBeforeStartDate window starts
*
* @param {Offer} offer
* @param {Opportunity} opportunity
* @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
* @returns {DateTime | null} null if there is no cancellation window defined.
*/
export function getDateBeforeWhichCancellationsCanBeMade(offer: Offer, opportunity: Opportunity): DateTime | null;
/**
* @param {Opportunity} opportunity
* @returns {boolean}
*/
export function hasCapacityLimitOfOne(opportunity: Opportunity): boolean;
export function remainingCapacityMustBeAtLeastTwo(opportunity: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
export function mustRequireAttendeeDetails(offer: import("../types/Offer").Offer, opportunity?: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
export function mustNotRequireAttendeeDetails(offer: import("../types/Offer").Offer, opportunity?: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
export function mustAllowProposalAmendment(offer: import("../types/Offer").Offer, opportunity?: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
export function startDateMustBeOver2HrsInAdvance(opportunity: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
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 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
* and `provider` is an Organization.
*
* @param {Opportunity} opportunity
*/
export function getOrganizerOrProvider(opportunity: Opportunity): any;
export function mustBeOutsideCancellationWindow(offer: import("../types/Offer").Offer, opportunity?: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
export function mustNotAllowFullRefund(offer: import("../types/Offer").Offer, opportunity?: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
export function mustAllowFullRefund(offer: import("../types/Offer").Offer, opportunity?: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
export const mustAllowFullRefundOfferConstraint: [string, import("../types/Criteria").OfferConstraint];
export function mustRequireAdditionalDetails(offer: import("../types/Offer").Offer, opportunity?: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
export function mustNotRequireAdditionalDetails(offer: import("../types/Offer").Offer, opportunity?: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
export function sellerMustAllowOpenBooking(opportunity: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
export function excludePaidBookableOffersWithPrepaymentUnavailable(offer: import("../types/Offer").Offer, opportunity?: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
/**
* Merge constraints so that the result has the simplest representation of the combination of all constraints.
*
* @param {TestDataShape} baseTestDataShape
* @param {TestDataShape} extraTestDataShape
* @param {string} criteriaName
* @return {TestDataShape}
*/
export function extendTestDataShape(baseTestDataShape: TestDataShape, extraTestDataShape: TestDataShape, criteriaName: string): TestDataShape;
/**
* @param {string} name
* @param {OfferConstraint} constraint
* @returns {Criteria['offerConstraints'][number]}
*/
export function createCriteriaOfferConstraint(name: string, constraint: OfferConstraint): Criteria['offerConstraints'][number];
import { DateTime } from "luxon/src/datetime";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export let allCriteria: import("../types/Criteria").Criteria[];
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* An opportunity which occurs in the future and does not require additional/attendee details
*
* This shouldn't be used for any tests, as it is not an [official criteria](https://openactive.io/test-interface/).
* It's just a useful basis for other criteria to include constraints from.
*/
export const InternalCriteriaFutureScheduledAndDoesNotRequireDetails: import("../../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type Criteria = import('../../types/Criteria').Criteria;
export type OpportunityConstraint = import('../../types/Criteria').OpportunityConstraint;
/**
* Useful base constraints for future opportunities.
*
* This shouldn't be used for any tests, as it is not an [official criteria](https://openactive.io/test-interface/).
* It's just a useful basis for other criteria to include constraints from.
*/
export const InternalCriteriaFutureScheduledOpportunity: import("../../types/Criteria").Criteria;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type OfferConstraint = import('../types/Criteria').OfferConstraint;
export function supportsMinimalProposalFlow(offer: import("../types/Offer").Offer, opportunity?: import("../types/Opportunity").Opportunity, options?: import("../types/Options").Options): boolean;
Loading
Loading