-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Correctly calculate refund amount when modifying order
Fixes #890
- Loading branch information
1 parent
70ddb87
commit 56d058d
Showing
4 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import { initialData } from '../../../e2e-common/e2e-initial-data'; | |
import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config'; | ||
import { manualFulfillmentHandler } from '../src/config/fulfillment/manual-fulfillment-handler'; | ||
import { orderFixedDiscount } from '../src/config/promotion/actions/order-fixed-discount-action'; | ||
import { defaultPromotionActions } from '../src/config/promotion/index'; | ||
|
||
import { | ||
failsToSettlePaymentMethod, | ||
|
@@ -104,9 +105,6 @@ describe('Order modification', () => { | |
testFailingPaymentMethod, | ||
], | ||
}, | ||
promotionOptions: { | ||
promotionConditions: [orderFixedDiscount], | ||
}, | ||
shippingOptions: { | ||
shippingCalculators: [defaultShippingCalculator, testCalculator], | ||
}, | ||
|
@@ -1443,6 +1441,72 @@ describe('Order modification', () => { | |
}); | ||
}); | ||
|
||
// https://github.com/vendure-ecommerce/vendure/issues/890 | ||
describe('refund handling when promotions are active on order', () => { | ||
it('refunds correct amount when order-level promotion applied', async () => { | ||
await adminClient.query<CreatePromotion.Mutation, CreatePromotion.Variables>(CREATE_PROMOTION, { | ||
input: { | ||
name: '$5 off', | ||
couponCode: '5OFF2', | ||
enabled: true, | ||
conditions: [], | ||
actions: [ | ||
{ | ||
code: orderFixedDiscount.code, | ||
arguments: [{ name: 'discount', value: '500' }], | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
await shopClient.asUserWithCredentials('[email protected]', 'test'); | ||
await shopClient.query(gql(ADD_ITEM_TO_ORDER_WITH_CUSTOM_FIELDS), { | ||
productVariantId: 'T_1', | ||
quantity: 2, | ||
} as any); | ||
await shopClient.query<ApplyCouponCode.Mutation, ApplyCouponCode.Variables>(APPLY_COUPON_CODE, { | ||
couponCode: '5OFF2', | ||
}); | ||
await proceedToArrangingPayment(shopClient); | ||
const order = await addPaymentToOrder(shopClient, testSuccessfulPaymentMethod); | ||
orderGuard.assertSuccess(order); | ||
|
||
const originalTotalWithTax = order.totalWithTax; | ||
|
||
const { transitionOrderToState } = await adminClient.query< | ||
AdminTransition.Mutation, | ||
AdminTransition.Variables | ||
>(ADMIN_TRANSITION_TO_STATE, { | ||
id: order.id, | ||
state: 'Modifying', | ||
}); | ||
orderGuard.assertSuccess(transitionOrderToState); | ||
|
||
expect(transitionOrderToState.state).toBe('Modifying'); | ||
|
||
const { modifyOrder } = await adminClient.query<ModifyOrder.Mutation, ModifyOrder.Variables>( | ||
MODIFY_ORDER, | ||
{ | ||
input: { | ||
dryRun: false, | ||
orderId: order.id, | ||
adjustOrderLines: [{ orderLineId: order.lines[0].id, quantity: 1 }], | ||
refund: { | ||
paymentId: order.payments![0].id, | ||
reason: 'requested', | ||
}, | ||
}, | ||
}, | ||
); | ||
orderGuard.assertSuccess(modifyOrder); | ||
|
||
expect(modifyOrder.totalWithTax).toBe( | ||
originalTotalWithTax - order.lines[0].proratedUnitPriceWithTax, | ||
); | ||
expect(modifyOrder.payments![0].refunds![0].total).toBe(order.lines[0].proratedUnitPriceWithTax); | ||
}); | ||
}); | ||
|
||
async function assertOrderIsUnchanged(order: OrderWithLinesFragment) { | ||
const { order: order2 } = await adminClient.query<GetOrder.Query, GetOrder.Variables>(GET_ORDER, { | ||
id: order.id, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters