|
|
@@ -10,11 +10,10 @@ import {
|
|
|
import { createErrorResultGuard, createTestEnvironment, ErrorResultGuard } from '@vendure/testing';
|
|
|
import gql from 'graphql-tag';
|
|
|
import path from 'path';
|
|
|
-import { vi } from 'vitest';
|
|
|
-import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
|
+import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
|
|
|
|
|
|
import { initialData } from '../../../e2e-common/e2e-initial-data';
|
|
|
-import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
|
|
|
+import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
|
|
|
|
|
|
import {
|
|
|
testErrorPaymentMethod,
|
|
|
@@ -25,15 +24,16 @@ import {
|
|
|
countryCodeShippingEligibilityChecker,
|
|
|
hydratingShippingEligibilityChecker,
|
|
|
} from './fixtures/test-shipping-eligibility-checkers';
|
|
|
+import * as Codegen from './graphql/generated-e2e-admin-types';
|
|
|
import {
|
|
|
CreateAddressInput,
|
|
|
CreateShippingMethodDocument,
|
|
|
CreateShippingMethodInput,
|
|
|
+ GlobalFlag,
|
|
|
LanguageCode,
|
|
|
} from './graphql/generated-e2e-admin-types';
|
|
|
-import * as Codegen from './graphql/generated-e2e-admin-types';
|
|
|
-import { ErrorCode, RemoveItemFromOrderDocument } from './graphql/generated-e2e-shop-types';
|
|
|
import * as CodegenShop from './graphql/generated-e2e-shop-types';
|
|
|
+import { ErrorCode, RemoveItemFromOrderDocument } from './graphql/generated-e2e-shop-types';
|
|
|
import {
|
|
|
ATTEMPT_LOGIN,
|
|
|
CANCEL_ORDER,
|
|
|
@@ -692,6 +692,7 @@ describe('Shop orders', () => {
|
|
|
const order = await shopClient.query<CodegenShop.GetActiveOrderQuery>(GET_ACTIVE_ORDER);
|
|
|
expect(order.activeOrder?.lines[1].quantity).toBe(100);
|
|
|
|
|
|
+ // clean up
|
|
|
const { adjustOrderLine: adjustLine2 } = await shopClient.query<
|
|
|
CodegenShop.AdjustItemQuantityMutation,
|
|
|
CodegenShop.AdjustItemQuantityMutationVariables
|
|
|
@@ -704,6 +705,81 @@ describe('Shop orders', () => {
|
|
|
expect(adjustLine2.lines.map(i => i.productVariant.id)).toEqual(['T_1']);
|
|
|
});
|
|
|
|
|
|
+ // https://github.com/vendure-ecommerce/vendure/issues/2702
|
|
|
+ it('stockOnHand check works with multiple order lines with different custom fields', async () => {
|
|
|
+ const variantId = 'T_27';
|
|
|
+ const { updateProductVariants } = await adminClient.query<
|
|
|
+ Codegen.UpdateProductVariantsMutation,
|
|
|
+ Codegen.UpdateProductVariantsMutationVariables
|
|
|
+ >(UPDATE_PRODUCT_VARIANTS, {
|
|
|
+ input: [
|
|
|
+ {
|
|
|
+ id: variantId,
|
|
|
+ stockOnHand: 10,
|
|
|
+ outOfStockThreshold: 0,
|
|
|
+ useGlobalOutOfStockThreshold: false,
|
|
|
+ trackInventory: GlobalFlag.TRUE,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(updateProductVariants[0]?.stockOnHand).toBe(10);
|
|
|
+ expect(updateProductVariants[0]?.id).toBe('T_27');
|
|
|
+ expect(updateProductVariants[0]?.trackInventory).toBe(GlobalFlag.TRUE);
|
|
|
+
|
|
|
+ const { addItemToOrder: add1 } = await shopClient.query<CodegenShop.AddItemToOrderMutation, any>(
|
|
|
+ ADD_ITEM_TO_ORDER_WITH_CUSTOM_FIELDS,
|
|
|
+ {
|
|
|
+ productVariantId: variantId,
|
|
|
+ quantity: 9,
|
|
|
+ customFields: {
|
|
|
+ notes: 'abc',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ );
|
|
|
+
|
|
|
+ orderResultGuard.assertSuccess(add1);
|
|
|
+
|
|
|
+ expect(add1.lines.length).toBe(2);
|
|
|
+ expect(add1.lines[1].quantity).toBe(9);
|
|
|
+ expect(add1.lines[1].productVariant.id).toBe(variantId);
|
|
|
+
|
|
|
+ const { addItemToOrder: add2 } = await shopClient.query<CodegenShop.AddItemToOrderMutation, any>(
|
|
|
+ ADD_ITEM_TO_ORDER_WITH_CUSTOM_FIELDS,
|
|
|
+ {
|
|
|
+ productVariantId: variantId,
|
|
|
+ quantity: 2,
|
|
|
+ customFields: {
|
|
|
+ notes: 'def',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ );
|
|
|
+
|
|
|
+ orderResultGuard.assertErrorResult(add2);
|
|
|
+
|
|
|
+ expect(add2.errorCode).toBe('INSUFFICIENT_STOCK_ERROR');
|
|
|
+ expect(add2.message).toBe('Only 1 item was added to the order due to insufficient stock');
|
|
|
+
|
|
|
+ const { activeOrder } = await shopClient.query<CodegenShop.GetActiveOrderQuery>(GET_ACTIVE_ORDER);
|
|
|
+ expect(activeOrder?.lines.length).toBe(3);
|
|
|
+ expect(activeOrder?.lines[1].quantity).toBe(9);
|
|
|
+ expect(activeOrder?.lines[2].quantity).toBe(1);
|
|
|
+
|
|
|
+ // clean up
|
|
|
+ await shopClient.query<
|
|
|
+ CodegenShop.RemoveItemFromOrderMutation,
|
|
|
+ CodegenShop.RemoveItemFromOrderMutationVariables
|
|
|
+ >(REMOVE_ITEM_FROM_ORDER, {
|
|
|
+ orderLineId: activeOrder!.lines[1].id,
|
|
|
+ });
|
|
|
+ await shopClient.query<
|
|
|
+ CodegenShop.RemoveItemFromOrderMutation,
|
|
|
+ CodegenShop.RemoveItemFromOrderMutationVariables
|
|
|
+ >(REMOVE_ITEM_FROM_ORDER, {
|
|
|
+ orderLineId: activeOrder!.lines[2].id,
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
it('adjustOrderLine errors when going beyond orderItemsLimit', async () => {
|
|
|
const { adjustOrderLine } = await shopClient.query<
|
|
|
CodegenShop.AdjustItemQuantityMutation,
|