|
|
@@ -2,8 +2,10 @@
|
|
|
import gql from 'graphql-tag';
|
|
|
import path from 'path';
|
|
|
|
|
|
+import { LanguageCode } from '../../common/lib/generated-types';
|
|
|
import { defaultShippingCalculator } from '../src/config/shipping-method/default-shipping-calculator';
|
|
|
import { defaultShippingEligibilityChecker } from '../src/config/shipping-method/default-shipping-eligibility-checker';
|
|
|
+import { ShippingCalculator } from '../src/config/shipping-method/shipping-calculator';
|
|
|
|
|
|
import { TEST_SETUP_TIMEOUT_MS } from './config/test-config';
|
|
|
import {
|
|
|
@@ -27,10 +29,18 @@ describe('ShippingMethod resolver', () => {
|
|
|
const server = new TestServer();
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
- const token = await server.init({
|
|
|
- productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-full.csv'),
|
|
|
- customerCount: 1,
|
|
|
- });
|
|
|
+ const token = await server.init(
|
|
|
+ {
|
|
|
+ productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-full.csv'),
|
|
|
+ customerCount: 1,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ shippingOptions: {
|
|
|
+ shippingEligibilityCheckers: [defaultShippingEligibilityChecker],
|
|
|
+ shippingCalculators: [defaultShippingCalculator, calculatorWithMetadata],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ );
|
|
|
await adminClient.init();
|
|
|
await shopClient.init();
|
|
|
}, TEST_SETUP_TIMEOUT_MS);
|
|
|
@@ -91,6 +101,11 @@ describe('ShippingMethod resolver', () => {
|
|
|
code: 'default-shipping-calculator',
|
|
|
description: 'Default Flat-Rate Shipping Calculator',
|
|
|
},
|
|
|
+ {
|
|
|
+ args: [],
|
|
|
+ code: 'calculator-with-metadata',
|
|
|
+ description: 'Has metadata',
|
|
|
+ },
|
|
|
]);
|
|
|
});
|
|
|
|
|
|
@@ -123,10 +138,16 @@ describe('ShippingMethod resolver', () => {
|
|
|
description: 'new method',
|
|
|
checker: {
|
|
|
code: defaultShippingEligibilityChecker.code,
|
|
|
- arguments: [],
|
|
|
+ arguments: [
|
|
|
+ {
|
|
|
+ name: 'orderMinimum',
|
|
|
+ type: 'int',
|
|
|
+ value: '0',
|
|
|
+ },
|
|
|
+ ],
|
|
|
},
|
|
|
calculator: {
|
|
|
- code: defaultShippingCalculator.code,
|
|
|
+ code: calculatorWithMetadata.code,
|
|
|
arguments: [],
|
|
|
},
|
|
|
},
|
|
|
@@ -137,7 +158,7 @@ describe('ShippingMethod resolver', () => {
|
|
|
code: 'new-method',
|
|
|
description: 'new method',
|
|
|
calculator: {
|
|
|
- code: 'default-shipping-calculator',
|
|
|
+ code: 'calculator-with-metadata',
|
|
|
},
|
|
|
checker: {
|
|
|
code: 'default-shipping-eligibility-checker',
|
|
|
@@ -145,40 +166,6 @@ describe('ShippingMethod resolver', () => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- it('updateShippingMethod', async () => {
|
|
|
- const { updateShippingMethod } = await adminClient.query<
|
|
|
- UpdateShippingMethod.Mutation,
|
|
|
- UpdateShippingMethod.Variables
|
|
|
- >(UPDATE_SHIPPING_METHOD, {
|
|
|
- input: {
|
|
|
- id: 'T_3',
|
|
|
- description: 'changed method',
|
|
|
- },
|
|
|
- });
|
|
|
-
|
|
|
- expect(updateShippingMethod.description).toBe('changed method');
|
|
|
- });
|
|
|
-
|
|
|
- it('deleteShippingMethod', async () => {
|
|
|
- const listResult1 = await adminClient.query<GetShippingMethodList.Query>(GET_SHIPPING_METHOD_LIST);
|
|
|
- expect(listResult1.shippingMethods.items.map(i => i.id)).toEqual(['T_1', 'T_2', 'T_3']);
|
|
|
-
|
|
|
- const { deleteShippingMethod } = await adminClient.query<
|
|
|
- DeleteShippingMethod.Mutation,
|
|
|
- DeleteShippingMethod.Variables
|
|
|
- >(DELETE_SHIPPING_METHOD, {
|
|
|
- id: 'T_3',
|
|
|
- });
|
|
|
-
|
|
|
- expect(deleteShippingMethod).toEqual({
|
|
|
- result: DeletionResult.DELETED,
|
|
|
- message: null,
|
|
|
- });
|
|
|
-
|
|
|
- const listResult2 = await adminClient.query<GetShippingMethodList.Query>(GET_SHIPPING_METHOD_LIST);
|
|
|
- expect(listResult2.shippingMethods.items.map(i => i.id)).toEqual(['T_1', 'T_2']);
|
|
|
- });
|
|
|
-
|
|
|
it('testShippingMethod', async () => {
|
|
|
const { testShippingMethod } = await adminClient.query<
|
|
|
TestShippingMethod.Query,
|
|
|
@@ -186,19 +173,8 @@ describe('ShippingMethod resolver', () => {
|
|
|
>(TEST_SHIPPING_METHOD, {
|
|
|
input: {
|
|
|
calculator: {
|
|
|
- code: defaultShippingCalculator.code,
|
|
|
- arguments: [
|
|
|
- {
|
|
|
- name: 'rate',
|
|
|
- type: 'int',
|
|
|
- value: '1000',
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'taxRate',
|
|
|
- type: 'int',
|
|
|
- value: '20',
|
|
|
- },
|
|
|
- ],
|
|
|
+ code: calculatorWithMetadata.code,
|
|
|
+ arguments: [],
|
|
|
},
|
|
|
checker: {
|
|
|
code: defaultShippingEligibilityChecker.code,
|
|
|
@@ -220,9 +196,10 @@ describe('ShippingMethod resolver', () => {
|
|
|
|
|
|
expect(testShippingMethod).toEqual({
|
|
|
eligible: true,
|
|
|
- price: {
|
|
|
- price: 1000,
|
|
|
- priceWithTax: 1200,
|
|
|
+ quote: {
|
|
|
+ price: 100,
|
|
|
+ priceWithTax: 100,
|
|
|
+ metadata: TEST_METADATA,
|
|
|
},
|
|
|
});
|
|
|
});
|
|
|
@@ -242,20 +219,82 @@ describe('ShippingMethod resolver', () => {
|
|
|
});
|
|
|
|
|
|
expect(testEligibleShippingMethods).toEqual([
|
|
|
+ {
|
|
|
+ id: 'T_3',
|
|
|
+ description: 'new method',
|
|
|
+ price: 100,
|
|
|
+ priceWithTax: 100,
|
|
|
+ metadata: TEST_METADATA,
|
|
|
+ },
|
|
|
+
|
|
|
{
|
|
|
id: 'T_1',
|
|
|
description: 'Standard Shipping',
|
|
|
price: 500,
|
|
|
priceWithTax: 500,
|
|
|
+ metadata: null,
|
|
|
},
|
|
|
{
|
|
|
id: 'T_2',
|
|
|
description: 'Express Shipping',
|
|
|
price: 1000,
|
|
|
priceWithTax: 1000,
|
|
|
+ metadata: null,
|
|
|
},
|
|
|
]);
|
|
|
});
|
|
|
+
|
|
|
+ it('updateShippingMethod', async () => {
|
|
|
+ const { updateShippingMethod } = await adminClient.query<
|
|
|
+ UpdateShippingMethod.Mutation,
|
|
|
+ UpdateShippingMethod.Variables
|
|
|
+ >(UPDATE_SHIPPING_METHOD, {
|
|
|
+ input: {
|
|
|
+ id: 'T_3',
|
|
|
+ description: 'changed method',
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(updateShippingMethod.description).toBe('changed method');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('deleteShippingMethod', async () => {
|
|
|
+ const listResult1 = await adminClient.query<GetShippingMethodList.Query>(GET_SHIPPING_METHOD_LIST);
|
|
|
+ expect(listResult1.shippingMethods.items.map(i => i.id)).toEqual(['T_1', 'T_2', 'T_3']);
|
|
|
+
|
|
|
+ const { deleteShippingMethod } = await adminClient.query<
|
|
|
+ DeleteShippingMethod.Mutation,
|
|
|
+ DeleteShippingMethod.Variables
|
|
|
+ >(DELETE_SHIPPING_METHOD, {
|
|
|
+ id: 'T_3',
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(deleteShippingMethod).toEqual({
|
|
|
+ result: DeletionResult.DELETED,
|
|
|
+ message: null,
|
|
|
+ });
|
|
|
+
|
|
|
+ const listResult2 = await adminClient.query<GetShippingMethodList.Query>(GET_SHIPPING_METHOD_LIST);
|
|
|
+ expect(listResult2.shippingMethods.items.map(i => i.id)).toEqual(['T_1', 'T_2']);
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+const TEST_METADATA = {
|
|
|
+ foo: 'bar',
|
|
|
+ baz: [1, 2, 3],
|
|
|
+};
|
|
|
+
|
|
|
+const calculatorWithMetadata = new ShippingCalculator({
|
|
|
+ code: 'calculator-with-metadata',
|
|
|
+ description: [{ languageCode: LanguageCode.en, value: 'Has metadata' }],
|
|
|
+ args: {},
|
|
|
+ calculate: order => {
|
|
|
+ return {
|
|
|
+ price: 100,
|
|
|
+ priceWithTax: 100,
|
|
|
+ metadata: TEST_METADATA,
|
|
|
+ };
|
|
|
+ },
|
|
|
});
|
|
|
|
|
|
const SHIPPING_METHOD_FRAGMENT = gql`
|
|
|
@@ -356,9 +395,10 @@ const TEST_SHIPPING_METHOD = gql`
|
|
|
query TestShippingMethod($input: TestShippingMethodInput!) {
|
|
|
testShippingMethod(input: $input) {
|
|
|
eligible
|
|
|
- price {
|
|
|
+ quote {
|
|
|
price
|
|
|
priceWithTax
|
|
|
+ metadata
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -371,6 +411,7 @@ export const TEST_ELIGIBLE_SHIPPING_METHODS = gql`
|
|
|
description
|
|
|
price
|
|
|
priceWithTax
|
|
|
+ metadata
|
|
|
}
|
|
|
}
|
|
|
`;
|