|
|
@@ -76,6 +76,7 @@ import {
|
|
|
} from './graphql/shared-definitions';
|
|
|
import {
|
|
|
ADD_ITEM_TO_ORDER,
|
|
|
+ ADD_MULTIPLE_ITEMS_TO_ORDER,
|
|
|
ADD_PAYMENT,
|
|
|
APPLY_COUPON_CODE,
|
|
|
GET_ACTIVE_CUSTOMER_WITH_ORDERS_PRODUCT_PRICE,
|
|
|
@@ -2805,6 +2806,59 @@ describe('Orders resolver', () => {
|
|
|
expect(order2?.state).toBe('PartiallyShipped');
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+ describe('multiple items to order', () => {
|
|
|
+ it('adds multiple items to a new active order', async () => {
|
|
|
+ await shopClient.asAnonymousUser();
|
|
|
+ const { addItemsToOrder } = await shopClient.query<
|
|
|
+ CodegenShop.AddItemsToOrderMutation,
|
|
|
+ CodegenShop.AddItemsToOrderMutationVariables
|
|
|
+ >(ADD_MULTIPLE_ITEMS_TO_ORDER, {
|
|
|
+ inputs: [
|
|
|
+ {
|
|
|
+ productVariantId: 'T_1',
|
|
|
+ quantity: 5,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ productVariantId: 'T_2',
|
|
|
+ quantity: 3,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ });
|
|
|
+ expect(addItemsToOrder.order.lines.length).toBe(2);
|
|
|
+ expect(addItemsToOrder.order.lines[0].quantity).toBe(5);
|
|
|
+ expect(addItemsToOrder.order.lines[1].quantity).toBe(3);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('adds successful items and returns error results for failed items', async () => {
|
|
|
+ await shopClient.asAnonymousUser();
|
|
|
+ const { addItemsToOrder } = await shopClient.query<
|
|
|
+ CodegenShop.AddItemsToOrderMutation,
|
|
|
+ CodegenShop.AddItemsToOrderMutationVariables
|
|
|
+ >(ADD_MULTIPLE_ITEMS_TO_ORDER, {
|
|
|
+ inputs: [
|
|
|
+ {
|
|
|
+ productVariantId: 'T_1',
|
|
|
+ quantity: 1,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ productVariantId: 'T_2',
|
|
|
+ quantity: 999999, // Exceeds limit
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ });
|
|
|
+ const t1 = addItemsToOrder.order.lines.find(l => l.productVariant.id === 'T_1')
|
|
|
+ // Should have added 1 of T_1
|
|
|
+ expect(t1?.quantity).toBe(1);
|
|
|
+ // Should not have added T_2
|
|
|
+ const t2 = addItemsToOrder.order.lines.find(l => l.productVariant.id === 'T_2')
|
|
|
+ expect(t2).toBeUndefined();
|
|
|
+ // Should have errors
|
|
|
+ expect(addItemsToOrder.errorResults.length).toBe(1);
|
|
|
+ expect(addItemsToOrder.errorResults[0].errorCode).toBe('ORDER_LIMIT_ERROR')
|
|
|
+ expect(addItemsToOrder.errorResults[0].message).toBe('ORDER_LIMIT_ERROR')
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
async function createTestOrder(
|