| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- import { createTestEnvironment } from '@vendure/testing';
- import gql from 'graphql-tag';
- import path from 'path';
- import { initialData } from '../../../e2e-common/e2e-initial-data';
- import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
- import { omit } from '../../common/lib/omit';
- import {
- CreateProductOption,
- CreateProductOptionGroup,
- LanguageCode,
- ProductOptionGroupFragment,
- UpdateProductOption,
- UpdateProductOptionGroup,
- } from './graphql/generated-e2e-admin-types';
- import { assertThrowsWithMessage } from './utils/assert-throws-with-message';
- // tslint:disable:no-non-null-assertion
- describe('ProductOption resolver', () => {
- const { server, adminClient } = createTestEnvironment(testConfig);
- let sizeGroup: ProductOptionGroupFragment;
- let mediumOption: CreateProductOption.CreateProductOption;
- beforeAll(async () => {
- await server.init({
- dataDir: path.join(__dirname, '__data__'),
- initialData,
- customerCount: 1,
- productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-minimal.csv'),
- });
- await adminClient.asSuperAdmin();
- }, TEST_SETUP_TIMEOUT_MS);
- afterAll(async () => {
- await server.destroy();
- });
- it('createProductOptionGroup', async () => {
- const { createProductOptionGroup } = await adminClient.query<
- CreateProductOptionGroup.Mutation,
- CreateProductOptionGroup.Variables
- >(CREATE_PRODUCT_OPTION_GROUP, {
- input: {
- code: 'size',
- translations: [
- { languageCode: LanguageCode.en, name: 'Size' },
- { languageCode: LanguageCode.de, name: 'Größe' },
- ],
- options: [
- {
- code: 'small',
- translations: [
- { languageCode: LanguageCode.en, name: 'Small' },
- { languageCode: LanguageCode.de, name: 'Klein' },
- ],
- },
- {
- code: 'large',
- translations: [
- { languageCode: LanguageCode.en, name: 'Large' },
- { languageCode: LanguageCode.de, name: 'Groß' },
- ],
- },
- ],
- },
- });
- expect(omit(createProductOptionGroup, ['options', 'translations'])).toEqual({
- id: 'T_3',
- name: 'Size',
- code: 'size',
- });
- sizeGroup = createProductOptionGroup;
- });
- it('updateProductOptionGroup', async () => {
- const { updateProductOptionGroup } = await adminClient.query<
- UpdateProductOptionGroup.Mutation,
- UpdateProductOptionGroup.Variables
- >(UPDATE_PRODUCT_OPTION_GROUP, {
- input: {
- id: sizeGroup.id,
- translations: [
- { id: sizeGroup.translations[0].id, languageCode: LanguageCode.en, name: 'Bigness' },
- ],
- },
- });
- expect(updateProductOptionGroup.name).toBe('Bigness');
- });
- it(
- 'createProductOption throws with invalid productOptionGroupId',
- assertThrowsWithMessage(async () => {
- const { createProductOption } = await adminClient.query<
- CreateProductOption.Mutation,
- CreateProductOption.Variables
- >(CREATE_PRODUCT_OPTION, {
- input: {
- productOptionGroupId: 'T_999',
- code: 'medium',
- translations: [
- { languageCode: LanguageCode.en, name: 'Medium' },
- { languageCode: LanguageCode.de, name: 'Mittel' },
- ],
- },
- });
- }, "No ProductOptionGroup with the id '999' could be found"),
- );
- it('createProductOption', async () => {
- const { createProductOption } = await adminClient.query<
- CreateProductOption.Mutation,
- CreateProductOption.Variables
- >(CREATE_PRODUCT_OPTION, {
- input: {
- productOptionGroupId: sizeGroup.id,
- code: 'medium',
- translations: [
- { languageCode: LanguageCode.en, name: 'Medium' },
- { languageCode: LanguageCode.de, name: 'Mittel' },
- ],
- },
- });
- expect(omit(createProductOption, ['translations'])).toEqual({
- id: 'T_7',
- groupId: sizeGroup.id,
- code: 'medium',
- name: 'Medium',
- });
- mediumOption = createProductOption;
- });
- it('updateProductOption', async () => {
- const { updateProductOption } = await adminClient.query<
- UpdateProductOption.Mutation,
- UpdateProductOption.Variables
- >(UPDATE_PRODUCT_OPTION, {
- input: {
- id: 'T_7',
- translations: [
- { id: mediumOption.translations[0].id, languageCode: LanguageCode.en, name: 'Middling' },
- ],
- },
- });
- expect(updateProductOption.name).toBe('Middling');
- });
- });
- const PRODUCT_OPTION_GROUP_FRAGMENT = gql`
- fragment ProductOptionGroup on ProductOptionGroup {
- id
- code
- name
- options {
- id
- code
- name
- }
- translations {
- id
- languageCode
- name
- }
- }
- `;
- const CREATE_PRODUCT_OPTION_GROUP = gql`
- mutation CreateProductOptionGroup($input: CreateProductOptionGroupInput!) {
- createProductOptionGroup(input: $input) {
- ...ProductOptionGroup
- }
- }
- ${PRODUCT_OPTION_GROUP_FRAGMENT}
- `;
- const UPDATE_PRODUCT_OPTION_GROUP = gql`
- mutation UpdateProductOptionGroup($input: UpdateProductOptionGroupInput!) {
- updateProductOptionGroup(input: $input) {
- ...ProductOptionGroup
- }
- }
- ${PRODUCT_OPTION_GROUP_FRAGMENT}
- `;
- const CREATE_PRODUCT_OPTION = gql`
- mutation CreateProductOption($input: CreateProductOptionInput!) {
- createProductOption(input: $input) {
- id
- code
- name
- groupId
- translations {
- id
- languageCode
- name
- }
- }
- }
- `;
- const UPDATE_PRODUCT_OPTION = gql`
- mutation UpdateProductOption($input: UpdateProductOptionInput!) {
- updateProductOption(input: $input) {
- id
- code
- name
- groupId
- }
- }
- `;
|