-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Allow order shipping method to be modified
Closes #978
- Loading branch information
1 parent
0750fb1
commit 400d78a
Showing
10 changed files
with
194 additions
and
87 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -70,18 +70,24 @@ const SHIPPING_OTHER = 750; | |
const testCalculator = new ShippingCalculator({ | ||
code: 'test-calculator', | ||
description: [{ languageCode: LanguageCode.en, value: 'Has metadata' }], | ||
args: {}, | ||
args: { | ||
surcharge: { | ||
type: 'int', | ||
defaultValue: 0, | ||
}, | ||
}, | ||
calculate: (ctx, order, args) => { | ||
let price; | ||
const surcharge = args.surcharge || 0; | ||
switch (order.shippingAddress.countryCode) { | ||
case 'GB': | ||
price = SHIPPING_GB; | ||
price = SHIPPING_GB + surcharge; | ||
break; | ||
case 'US': | ||
price = SHIPPING_US; | ||
price = SHIPPING_US + surcharge; | ||
break; | ||
default: | ||
price = SHIPPING_OTHER; | ||
price = SHIPPING_OTHER + surcharge; | ||
} | ||
return { | ||
price, | ||
|
@@ -113,6 +119,7 @@ describe('Order modification', () => { | |
|
||
let orderId: string; | ||
let testShippingMethodId: string; | ||
let testExpressShippingMethodId: string; | ||
const orderGuard: ErrorResultGuard< | ||
UpdatedOrderFragment | OrderWithModificationsFragment | OrderFragment | ||
> = createErrorResultGuard(input => !!input.id); | ||
|
@@ -186,6 +193,38 @@ describe('Order modification', () => { | |
}); | ||
testShippingMethodId = createShippingMethod.id; | ||
|
||
const { createShippingMethod: shippingMethod2 } = await adminClient.query< | ||
Codegen.CreateShippingMethodMutation, | ||
Codegen.CreateShippingMethodMutationVariables | ||
>(CREATE_SHIPPING_METHOD, { | ||
input: { | ||
code: 'new-method-express', | ||
fulfillmentHandler: manualFulfillmentHandler.code, | ||
checker: { | ||
code: defaultShippingEligibilityChecker.code, | ||
arguments: [ | ||
{ | ||
name: 'orderMinimum', | ||
value: '0', | ||
}, | ||
], | ||
}, | ||
calculator: { | ||
code: testCalculator.code, | ||
arguments: [ | ||
{ | ||
name: 'surcharge', | ||
value: '500', | ||
}, | ||
], | ||
}, | ||
translations: [ | ||
{ languageCode: LanguageCode.en, name: 'test method express', description: '' }, | ||
], | ||
}, | ||
}); | ||
testExpressShippingMethodId = shippingMethod2.id; | ||
|
||
// create an order and check out | ||
await shopClient.asUserWithCredentials('[email protected]', 'test'); | ||
await shopClient.query(gql(ADD_ITEM_TO_ORDER_WITH_CUSTOM_FIELDS), { | ||
|
@@ -663,6 +702,40 @@ describe('Order modification', () => { | |
await assertOrderIsUnchanged(order!); | ||
}); | ||
|
||
it('changing shipping method', async () => { | ||
const { order } = await adminClient.query<Codegen.GetOrderQuery, Codegen.GetOrderQueryVariables>( | ||
GET_ORDER, | ||
{ | ||
id: orderId, | ||
}, | ||
); | ||
const { modifyOrder } = await adminClient.query< | ||
Codegen.ModifyOrderMutation, | ||
Codegen.ModifyOrderMutationVariables | ||
>(MODIFY_ORDER, { | ||
input: { | ||
dryRun: true, | ||
orderId, | ||
shippingMethodIds: [testExpressShippingMethodId], | ||
}, | ||
}); | ||
orderGuard.assertSuccess(modifyOrder); | ||
|
||
const expectedTotal = order!.totalWithTax + 500; | ||
expect(modifyOrder.totalWithTax).toBe(expectedTotal); | ||
expect(modifyOrder.shippingLines).toEqual([ | ||
{ | ||
id: 'T_1', | ||
discountedPriceWithTax: 1500, | ||
shippingMethod: { | ||
id: testExpressShippingMethodId, | ||
name: 'test method express', | ||
}, | ||
}, | ||
]); | ||
await assertOrderIsUnchanged(order!); | ||
}); | ||
|
||
it('does not add a history entry', async () => { | ||
const { order } = await adminClient.query<Codegen.GetOrderQuery, Codegen.GetOrderQueryVariables>( | ||
GET_ORDER, | ||
|
@@ -2511,6 +2584,14 @@ export const ORDER_WITH_MODIFICATION_FRAGMENT = gql` | |
countryCode | ||
country | ||
} | ||
shippingLines { | ||
id | ||
discountedPriceWithTax | ||
shippingMethod { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
`; | ||
|
||
|
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
Oops, something went wrong.