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

feat: Use ListenerItemExpectations for customer cancel #700

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading