-
-
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.
test(core): Add e2e tests for PR #1029
- Loading branch information
1 parent
a3aa3e2
commit bd32a6c
Showing
1 changed file
with
105 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ import { | |
} from './graphql/shared-definitions'; | ||
import { | ||
ADD_ITEM_TO_ORDER, | ||
ADD_ITEM_TO_ORDER_WITH_CUSTOM_FIELDS, | ||
ADD_PAYMENT, | ||
GET_PRODUCT_WITH_STOCK_LEVEL, | ||
SET_SHIPPING_ADDRESS, | ||
|
@@ -63,6 +64,9 @@ describe('Stock control', () => { | |
paymentOptions: { | ||
paymentMethodHandlers: [testSuccessfulPaymentMethod, twoStagePaymentMethod], | ||
}, | ||
customFields: { | ||
OrderLine: [{ name: 'customization', type: 'string', nullable: true }], | ||
}, | ||
}), | ||
); | ||
|
||
|
@@ -924,6 +928,107 @@ describe('Stock control', () => { | |
}); | ||
}); | ||
}); | ||
|
||
// https://github.com/vendure-ecommerce/vendure/issues/1028 | ||
describe('OrderLines with same variant but different custom fields', () => { | ||
let orderId: string; | ||
|
||
it('correctly allocates stock', async () => { | ||
await shopClient.asUserWithCredentials('[email protected]', 'test'); | ||
|
||
const product = await getProductWithStockMovement('T_2'); | ||
const [variant1, variant2, variant3] = product!.variants; | ||
|
||
expect(variant2.stockAllocated).toBe(0); | ||
|
||
await shopClient.query<AddItemToOrder.Mutation, any>(ADD_ITEM_TO_ORDER_WITH_CUSTOM_FIELDS, { | ||
productVariantId: variant2.id, | ||
quantity: 1, | ||
customFields: { | ||
customization: 'foo', | ||
}, | ||
}); | ||
const { addItemToOrder } = await shopClient.query<AddItemToOrder.Mutation, any>( | ||
ADD_ITEM_TO_ORDER_WITH_CUSTOM_FIELDS, | ||
{ | ||
productVariantId: variant2.id, | ||
quantity: 1, | ||
customFields: { | ||
customization: 'bar', | ||
}, | ||
}, | ||
); | ||
|
||
orderGuard.assertSuccess(addItemToOrder); | ||
orderId = addItemToOrder.id; | ||
// Assert that separate order lines have been created | ||
expect(addItemToOrder.lines.length).toBe(2); | ||
|
||
await shopClient.query<SetShippingAddress.Mutation, SetShippingAddress.Variables>( | ||
SET_SHIPPING_ADDRESS, | ||
{ | ||
input: { | ||
streetLine1: '1 Test Street', | ||
countryCode: 'GB', | ||
} as CreateAddressInput, | ||
}, | ||
); | ||
await shopClient.query<TransitionToState.Mutation, TransitionToState.Variables>( | ||
TRANSITION_TO_STATE, | ||
{ | ||
state: 'ArrangingPayment', | ||
}, | ||
); | ||
const { addPaymentToOrder: order } = await shopClient.query< | ||
AddPaymentToOrder.Mutation, | ||
AddPaymentToOrder.Variables | ||
>(ADD_PAYMENT, { | ||
input: { | ||
method: testSuccessfulPaymentMethod.code, | ||
metadata: {}, | ||
} as PaymentInput, | ||
}); | ||
orderGuard.assertSuccess(order); | ||
|
||
const product2 = await getProductWithStockMovement('T_2'); | ||
const [variant1_2, variant2_2, variant3_2] = product2!.variants; | ||
|
||
expect(variant2_2.stockAllocated).toBe(2); | ||
}); | ||
|
||
it('correctly creates Sales', async () => { | ||
const product = await getProductWithStockMovement('T_2'); | ||
const [variant1, variant2, variant3] = product!.variants; | ||
|
||
expect(variant2.stockOnHand).toBe(3); | ||
|
||
const { order } = await adminClient.query<GetOrder.Query, GetOrder.Variables>(GET_ORDER, { | ||
id: orderId, | ||
}); | ||
|
||
await adminClient.query<CreateFulfillment.Mutation, CreateFulfillment.Variables>( | ||
CREATE_FULFILLMENT, | ||
{ | ||
input: { | ||
lines: order?.lines.map(l => ({ orderLineId: l.id, quantity: l.quantity })) ?? [], | ||
handler: { | ||
code: manualFulfillmentHandler.code, | ||
arguments: [ | ||
{ name: 'method', value: 'test method' }, | ||
{ name: 'trackingCode', value: 'ABC123' }, | ||
], | ||
}, | ||
}, | ||
}, | ||
); | ||
|
||
const product2 = await getProductWithStockMovement('T_2'); | ||
const [variant1_2, variant2_2, variant3_2] = product2!.variants; | ||
|
||
expect(variant2_2.stockAllocated).toBe(0); | ||
expect(variant2_2.stockOnHand).toBe(1); | ||
}); | ||
}); | ||
}); | ||
|
||
const UPDATE_STOCK_ON_HAND = gql` | ||
|