Skip to content

Commit

Permalink
feat: Use ListenerItemExpectations for customer cancel (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehesluke authored Nov 1, 2024
1 parent 265b102 commit d6ab1a8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,12 @@ const FlowStageRecipes = {
* @param {object} args
* @param {import('utility-types').Optional<ConstructorParameters<typeof CancelOrderFlowStage>[0], 'prerequisite' | 'requestHelper' | 'uuid'>} args.cancelArgs
* @param {import('utility-types').Optional<ConstructorParameters<typeof AssertOpportunityCapacityFlowStage>[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({
Expand All @@ -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({
Expand Down

0 comments on commit d6ab1a8

Please sign in to comment.