From d6ab1a8a84ec71fc0d34f1cf1e5dd8355103c447 Mon Sep 17 00:00:00 2001 From: Luke Winship Date: Fri, 1 Nov 2024 17:59:30 +0000 Subject: [PATCH] feat: Use ListenerItemExpectations for customer cancel (#700) --- .../implemented/atomic-cancel-test.js | 34 +++++++++++-------- .../implemented/book-and-cancel-test.js | 32 ++++++++++------- .../helpers/flow-stages/flow-stage-recipes.js | 8 ++++- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/packages/openactive-integration-tests/test/features/cancellation/customer-requested-cancellation/implemented/atomic-cancel-test.js b/packages/openactive-integration-tests/test/features/cancellation/customer-requested-cancellation/implemented/atomic-cancel-test.js index 5607e4f069..d1318f908c 100644 --- a/packages/openactive-integration-tests/test/features/cancellation/customer-requested-cancellation/implemented/atomic-cancel-test.js +++ b/packages/openactive-integration-tests/test/features/cancellation/customer-requested-cancellation/implemented/atomic-cancel-test.js @@ -3,6 +3,7 @@ const { FeatureHelper } = require('../../../../helpers/feature-helper'); const { FlowStageRecipes, FlowStageUtils, CancelOrderFlowStage } = require('../../../../helpers/flow-stages'); const { AssertOpportunityCapacityFlowStage } = require('../../../../helpers/flow-stages/assert-opportunity-capacity'); const { itShouldReturnAnOpenBookingError } = require('../../../../shared-behaviours/errors'); +const { ListenerItemExpectationRecipes } = require('../../../../helpers/listener-item-expectations'); const { IMPLEMENTED_FEATURES } = global; @@ -51,21 +52,26 @@ function (configuration, orderItemCriteriaList, featureIsImplemented, logger, de }); // ### Cancel 1st Order Item which is cancellable - const cancelCancellableOrderItem = FlowStageRecipes.runs.customerCancel.successfulCancelAssertOrderUpdateAndCapacity(cancelNotCancellableOrderItems.getLastStage(), defaultFlowStageParams, { - cancelArgs: { - getOrderItemIdArray: CancelOrderFlowStage.getOrderItemIdsByPositionFromBookStages(bookRecipe.firstStage, [0]), - testName: 'Cancel Order for cancellable item', - }, - assertOpportunityCapacityArgs: { - orderItemCriteriaList, - // Opportunity capacity should have incremented for the Opportunity at Order Item position 0 - getInput: () => ({ - opportunityFeedExtractResponses: bookRecipe.getAssertOpportunityCapacityAfterBook().getOutput().opportunityFeedExtractResponses, - orderItems: fetchOpportunities.getOutput().orderItems, - }), - getOpportunityExpectedCapacity: AssertOpportunityCapacityFlowStage.getOpportunityCapacityIncrementedForOrderItemPositions([0]), + const cancelCancellableOrderItem = FlowStageRecipes.runs.customerCancel.successfulCancelAssertOrderUpdateAndCapacity( + cancelNotCancellableOrderItems.getLastStage(), + defaultFlowStageParams, + { + cancelArgs: { + getOrderItemIdArray: CancelOrderFlowStage.getOrderItemIdsByPositionFromBookStages(bookRecipe.firstStage, [0]), + testName: 'Cancel Order for cancellable item', + }, + assertOpportunityCapacityArgs: { + orderItemCriteriaList, + // Opportunity capacity should have incremented for the Opportunity at Order Item position 0 + getInput: () => ({ + opportunityFeedExtractResponses: bookRecipe.getAssertOpportunityCapacityAfterBook().getOutput().opportunityFeedExtractResponses, + orderItems: fetchOpportunities.getOutput().orderItems, + }), + getOpportunityExpectedCapacity: AssertOpportunityCapacityFlowStage.getOpportunityCapacityIncrementedForOrderItemPositions([0]), + }, + listenerItemExpectations: [ListenerItemExpectationRecipes.nonConfirmedOrderItems(1)], }, - }); + ); // ## Set up tests FlowStageUtils.describeRunAndCheckIsSuccessfulAndValid(fetchOpportunities); diff --git a/packages/openactive-integration-tests/test/features/cancellation/customer-requested-cancellation/implemented/book-and-cancel-test.js b/packages/openactive-integration-tests/test/features/cancellation/customer-requested-cancellation/implemented/book-and-cancel-test.js index 4cb26d13c3..0186dcbbd7 100644 --- a/packages/openactive-integration-tests/test/features/cancellation/customer-requested-cancellation/implemented/book-and-cancel-test.js +++ b/packages/openactive-integration-tests/test/features/cancellation/customer-requested-cancellation/implemented/book-and-cancel-test.js @@ -2,6 +2,7 @@ const { expect } = require('chai'); const { FeatureHelper } = require('../../../../helpers/feature-helper'); const { FlowStageRecipes, FlowStageUtils, CancelOrderFlowStage } = require('../../../../helpers/flow-stages'); const { AssertOpportunityCapacityFlowStage } = require('../../../../helpers/flow-stages/assert-opportunity-capacity'); +const { ListenerItemExpectationRecipes } = require('../../../../helpers/listener-item-expectations'); FeatureHelper.describeFeature(module, { testCategory: 'cancellation', @@ -24,20 +25,25 @@ function (configuration, orderItemCriteriaList, featureIsImplemented, logger, de const getArrayOfAllOrderItemIds = CancelOrderFlowStage.getOrderItemIdsByPositionFromBookStages(bookRecipe.firstStage, allOrderItemPositions); // ### Cancel all order items - const cancelOrderItems = FlowStageRecipes.runs.customerCancel.successfulCancelAssertOrderUpdateAndCapacity(bookRecipe.lastStage, defaultFlowStageParams, { - cancelArgs: { - getOrderItemIdArray: getArrayOfAllOrderItemIds, + const cancelOrderItems = FlowStageRecipes.runs.customerCancel.successfulCancelAssertOrderUpdateAndCapacity( + bookRecipe.lastStage, + defaultFlowStageParams, + { + cancelArgs: { + getOrderItemIdArray: getArrayOfAllOrderItemIds, + }, + assertOpportunityCapacityArgs: { + orderItemCriteriaList, + // Opportunity capacity should have incremented for all Order Items + getInput: () => ({ + opportunityFeedExtractResponses: bookRecipe.getAssertOpportunityCapacityAfterBook().getOutput().opportunityFeedExtractResponses, + orderItems: fetchOpportunities.getOutput().orderItems, + }), + getOpportunityExpectedCapacity: AssertOpportunityCapacityFlowStage.getOpportunityCapacityIncrementedForOrderItemPositions(allOrderItemPositions), + }, + listenerItemExpectations: [ListenerItemExpectationRecipes.allNonConfirmedOrderItems()], }, - assertOpportunityCapacityArgs: { - orderItemCriteriaList, - // Opportunity capacity should have incremented for all Order Items - getInput: () => ({ - opportunityFeedExtractResponses: bookRecipe.getAssertOpportunityCapacityAfterBook().getOutput().opportunityFeedExtractResponses, - orderItems: fetchOpportunities.getOutput().orderItems, - }), - getOpportunityExpectedCapacity: AssertOpportunityCapacityFlowStage.getOpportunityCapacityIncrementedForOrderItemPositions(allOrderItemPositions), - }, - }); + ); // ### Cancel order items again to test for idempotency const cancelOrderItemsAgain = FlowStageRecipes.runs.customerCancel.cancelAndAssertCapacity(bookRecipe.lastStage, defaultFlowStageParams, { diff --git a/packages/openactive-integration-tests/test/helpers/flow-stages/flow-stage-recipes.js b/packages/openactive-integration-tests/test/helpers/flow-stages/flow-stage-recipes.js index 54497fbd89..987bfb7bcc 100644 --- a/packages/openactive-integration-tests/test/helpers/flow-stages/flow-stage-recipes.js +++ b/packages/openactive-integration-tests/test/helpers/flow-stages/flow-stage-recipes.js @@ -618,9 +618,12 @@ const FlowStageRecipes = { * @param {object} args * @param {import('utility-types').Optional[0], 'prerequisite' | 'requestHelper' | 'uuid'>} args.cancelArgs * @param {import('utility-types').Optional[0], 'prerequisite' | 'requestHelper' | 'logger' | 'nameOfPreviousStage' | 'orderItemCriteriaList'>} args.assertOpportunityCapacityArgs + * @param {import('../listener-item-expectations').ListenerItemExpectation[]} args.listenerItemExpectations */ successfulCancelAssertOrderUpdateAndCapacity(prerequisite, defaultFlowStageParams, { - cancelArgs, assertOpportunityCapacityArgs, + cancelArgs, + assertOpportunityCapacityArgs, + listenerItemExpectations, }) { const cancelTestName = cancelArgs.testName ?? 'Cancel'; const [cancel, orderFeedUpdate] = OrderFeedUpdateFlowStageUtils.wrap({ @@ -633,6 +636,9 @@ const FlowStageRecipes = { ...defaultFlowStageParams, prerequisite, testName: `Orders Feed (after ${cancelTestName})`, + /* This allows us to support Booking Systems which update OrderItem + statuses one at a time, rather than all at once. */ + listenerItemExpectations, }, }); const assertOpportunityCapacityAfterCancel = new AssertOpportunityCapacityFlowStage({