| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import { pick } from '@vendure/common/lib/pick';
- import {
- defaultShippingEligibilityChecker,
- LanguageCode,
- mergeConfig,
- ShippingEligibilityChecker,
- } from '@vendure/core';
- import { createTestEnvironment } from '@vendure/testing';
- import gql from 'graphql-tag';
- import path from 'path';
- import { initialData } from '../../../e2e-common/e2e-initial-data';
- import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
- import { GetCheckers, UpdateShippingMethod } from './graphql/generated-e2e-admin-types';
- import { UPDATE_SHIPPING_METHOD } from './graphql/shared-definitions';
- import { assertThrowsWithMessage } from './utils/assert-throws-with-message';
- const testShippingEligibilityChecker = new ShippingEligibilityChecker({
- code: 'test-checker',
- description: [{ languageCode: LanguageCode.en, value: 'test checker' }],
- args: {
- optional: {
- label: [
- { languageCode: LanguageCode.en, value: 'Optional argument' },
- { languageCode: LanguageCode.de, value: 'Optional eingabe' },
- ],
- description: [
- { languageCode: LanguageCode.en, value: 'This is an optional argument' },
- { languageCode: LanguageCode.de, value: 'Das ist eine optionale eingabe' },
- ],
- required: false,
- type: 'string',
- },
- required: {
- required: true,
- type: 'string',
- defaultValue: 'hello',
- },
- },
- check: ctx => true,
- });
- describe('Configurable operations', () => {
- const { server, adminClient, shopClient } = createTestEnvironment(
- mergeConfig(testConfig(), {
- shippingOptions: {
- shippingEligibilityCheckers: [
- defaultShippingEligibilityChecker,
- testShippingEligibilityChecker,
- ],
- },
- }),
- );
- beforeAll(async () => {
- await server.init({
- initialData,
- productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-full.csv'),
- customerCount: 1,
- });
- await adminClient.asSuperAdmin();
- }, TEST_SETUP_TIMEOUT_MS);
- afterAll(async () => {
- await server.destroy();
- });
- describe('required args', () => {
- it('allows empty optional arg', async () => {
- const { updateShippingMethod } = await adminClient.query<
- UpdateShippingMethod.Mutation,
- UpdateShippingMethod.Variables
- >(UPDATE_SHIPPING_METHOD, {
- input: {
- id: 'T_1',
- checker: {
- code: testShippingEligibilityChecker.code,
- arguments: [
- { name: 'optional', value: '' },
- { name: 'required', value: 'foo' },
- ],
- },
- translations: [],
- },
- });
- expect(updateShippingMethod.checker.args).toEqual([
- {
- name: 'optional',
- value: '',
- },
- {
- name: 'required',
- value: 'foo',
- },
- ]);
- });
- it(
- 'throws if a required arg is null',
- assertThrowsWithMessage(async () => {
- await adminClient.query<UpdateShippingMethod.Mutation, UpdateShippingMethod.Variables>(
- UPDATE_SHIPPING_METHOD,
- {
- input: {
- id: 'T_1',
- checker: {
- code: testShippingEligibilityChecker.code,
- arguments: [
- { name: 'optional', value: 'null' },
- { name: 'required', value: '' },
- ],
- },
- translations: [],
- },
- },
- );
- }, "The argument 'required' is required"),
- );
- });
- it('defaultValue', async () => {
- const { shippingEligibilityCheckers } = await adminClient.query<GetCheckers.Query>(GET_CHECKERS);
- expect(shippingEligibilityCheckers[1].args.map(pick(['name', 'defaultValue']))).toEqual([
- { name: 'optional', defaultValue: null },
- { name: 'required', defaultValue: 'hello' },
- ]);
- });
- });
- export const GET_CHECKERS = gql`
- query GetCheckers {
- shippingEligibilityCheckers {
- code
- args {
- defaultValue
- description
- label
- list
- name
- required
- type
- }
- }
- }
- `;
|