|
|
@@ -1,15 +1,19 @@
|
|
|
import { pick } from '@vendure/common/lib/pick';
|
|
|
-import { createTestEnvironment } from '@vendure/testing';
|
|
|
+import { createTestEnvironment, E2E_DEFAULT_CHANNEL_TOKEN } 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 { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
|
|
|
|
|
|
import { FACET_VALUE_FRAGMENT, FACET_WITH_VALUES_FRAGMENT } from './graphql/fragments';
|
|
|
import {
|
|
|
+ AssignProductsToChannel,
|
|
|
+ ChannelFragment,
|
|
|
+ CreateChannel,
|
|
|
CreateFacet,
|
|
|
CreateFacetValues,
|
|
|
+ CurrencyCode,
|
|
|
DeleteFacet,
|
|
|
DeleteFacetValues,
|
|
|
DeletionResult,
|
|
|
@@ -25,6 +29,8 @@ import {
|
|
|
UpdateProductVariants,
|
|
|
} from './graphql/generated-e2e-admin-types';
|
|
|
import {
|
|
|
+ ASSIGN_PRODUCT_TO_CHANNEL,
|
|
|
+ CREATE_CHANNEL,
|
|
|
CREATE_FACET,
|
|
|
GET_FACET_LIST,
|
|
|
GET_PRODUCT_WITH_VARIANTS,
|
|
|
@@ -32,6 +38,7 @@ import {
|
|
|
UPDATE_PRODUCT,
|
|
|
UPDATE_PRODUCT_VARIANTS,
|
|
|
} from './graphql/shared-definitions';
|
|
|
+import { assertThrowsWithMessage } from './utils/assert-throws-with-message';
|
|
|
|
|
|
// tslint:disable:no-non-null-assertion
|
|
|
|
|
|
@@ -363,6 +370,211 @@ describe('Facet resolver', () => {
|
|
|
expect(result.deleteFacet.result).toBe(DeletionResult.DELETED);
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+ describe('channels', () => {
|
|
|
+ const SECOND_CHANNEL_TOKEN = 'second_channel_token';
|
|
|
+ let createdFacet: CreateFacet.CreateFacet;
|
|
|
+
|
|
|
+ beforeAll(async () => {
|
|
|
+ const { createChannel } = await adminClient.query<
|
|
|
+ CreateChannel.Mutation,
|
|
|
+ CreateChannel.Variables
|
|
|
+ >(CREATE_CHANNEL, {
|
|
|
+ input: {
|
|
|
+ code: 'second-channel',
|
|
|
+ token: SECOND_CHANNEL_TOKEN,
|
|
|
+ defaultLanguageCode: LanguageCode.en,
|
|
|
+ currencyCode: CurrencyCode.USD,
|
|
|
+ pricesIncludeTax: true,
|
|
|
+ defaultShippingZoneId: 'T_1',
|
|
|
+ defaultTaxZoneId: 'T_1',
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ const { assignProductsToChannel } = await adminClient.query<
|
|
|
+ AssignProductsToChannel.Mutation,
|
|
|
+ AssignProductsToChannel.Variables
|
|
|
+ >(ASSIGN_PRODUCT_TO_CHANNEL, {
|
|
|
+ input: {
|
|
|
+ channelId: (createChannel as ChannelFragment).id,
|
|
|
+ productIds: ['T_1'],
|
|
|
+ priceFactor: 0.5,
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('create Facet in channel', async () => {
|
|
|
+ const { createFacet } = await adminClient.query<CreateFacet.Mutation, CreateFacet.Variables>(
|
|
|
+ CREATE_FACET,
|
|
|
+ {
|
|
|
+ input: {
|
|
|
+ isPrivate: false,
|
|
|
+ code: 'channel-facet',
|
|
|
+ translations: [{ languageCode: LanguageCode.en, name: 'Channel Facet' }],
|
|
|
+ values: [
|
|
|
+ {
|
|
|
+ code: 'channel-value-1',
|
|
|
+ translations: [{ languageCode: LanguageCode.en, name: 'Channel Value 1' }],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ code: 'channel-value-2',
|
|
|
+ translations: [{ languageCode: LanguageCode.en, name: 'Channel Value 2' }],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ );
|
|
|
+
|
|
|
+ expect(createFacet.code).toBe('channel-facet');
|
|
|
+
|
|
|
+ createdFacet = createFacet;
|
|
|
+ });
|
|
|
+
|
|
|
+ it('facets list in channel', async () => {
|
|
|
+ const result = await adminClient.query<GetFacetList.Query>(GET_FACET_LIST);
|
|
|
+
|
|
|
+ const { items } = result.facets;
|
|
|
+ expect(items.length).toBe(1);
|
|
|
+ expect(items.map(i => i.code)).toEqual(['channel-facet']);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('Product.facetValues in channel', async () => {
|
|
|
+ adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);
|
|
|
+ await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(UPDATE_PRODUCT, {
|
|
|
+ input: {
|
|
|
+ id: 'T_1',
|
|
|
+ facetValueIds: [brandFacet.values[0].id, ...createdFacet.values.map(v => v.id)],
|
|
|
+ },
|
|
|
+ });
|
|
|
+ await adminClient.query<UpdateProductVariants.Mutation, UpdateProductVariants.Variables>(
|
|
|
+ UPDATE_PRODUCT_VARIANTS,
|
|
|
+ {
|
|
|
+ input: [
|
|
|
+ {
|
|
|
+ id: 'T_1',
|
|
|
+ facetValueIds: [brandFacet.values[0].id, ...createdFacet.values.map(v => v.id)],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ );
|
|
|
+
|
|
|
+ adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
+ const { product } = await adminClient.query<
|
|
|
+ GetProductWithVariants.Query,
|
|
|
+ GetProductWithVariants.Variables
|
|
|
+ >(GET_PRODUCT_WITH_VARIANTS, {
|
|
|
+ id: 'T_1',
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(product?.facetValues.map(fv => fv.code)).toEqual(['channel-value-1', 'channel-value-2']);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('ProductVariant.facetValues in channel', async () => {
|
|
|
+ const { product } = await adminClient.query<
|
|
|
+ GetProductWithVariants.Query,
|
|
|
+ GetProductWithVariants.Variables
|
|
|
+ >(GET_PRODUCT_WITH_VARIANTS, {
|
|
|
+ id: 'T_1',
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(product?.variants[0].facetValues.map(fv => fv.code)).toEqual([
|
|
|
+ 'channel-value-1',
|
|
|
+ 'channel-value-2',
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('updating Product facetValuesIds in channel only affects that channel', async () => {
|
|
|
+ adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
+ await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(UPDATE_PRODUCT, {
|
|
|
+ input: {
|
|
|
+ id: 'T_1',
|
|
|
+ facetValueIds: [createdFacet.values[0].id],
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ const { product: productC2 } = await adminClient.query<
|
|
|
+ GetProductWithVariants.Query,
|
|
|
+ GetProductWithVariants.Variables
|
|
|
+ >(GET_PRODUCT_WITH_VARIANTS, {
|
|
|
+ id: 'T_1',
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(productC2?.facetValues.map(fv => fv.code)).toEqual([createdFacet.values[0].code]);
|
|
|
+
|
|
|
+ adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);
|
|
|
+ const { product: productCD } = await adminClient.query<
|
|
|
+ GetProductWithVariants.Query,
|
|
|
+ GetProductWithVariants.Variables
|
|
|
+ >(GET_PRODUCT_WITH_VARIANTS, {
|
|
|
+ id: 'T_1',
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(productCD?.facetValues.map(fv => fv.code)).toEqual([
|
|
|
+ brandFacet.values[0].code,
|
|
|
+ createdFacet.values[0].code,
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('updating ProductVariant facetValuesIds in channel only affects that channel', async () => {
|
|
|
+ adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
+ await adminClient.query<UpdateProductVariants.Mutation, UpdateProductVariants.Variables>(
|
|
|
+ UPDATE_PRODUCT_VARIANTS,
|
|
|
+ {
|
|
|
+ input: [
|
|
|
+ {
|
|
|
+ id: 'T_1',
|
|
|
+ facetValueIds: [createdFacet.values[0].id],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ );
|
|
|
+
|
|
|
+ const { product: productC2 } = await adminClient.query<
|
|
|
+ GetProductWithVariants.Query,
|
|
|
+ GetProductWithVariants.Variables
|
|
|
+ >(GET_PRODUCT_WITH_VARIANTS, {
|
|
|
+ id: 'T_1',
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(productC2?.variants.find(v => v.id === 'T_1')?.facetValues.map(fv => fv.code)).toEqual([
|
|
|
+ createdFacet.values[0].code,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);
|
|
|
+ const { product: productCD } = await adminClient.query<
|
|
|
+ GetProductWithVariants.Query,
|
|
|
+ GetProductWithVariants.Variables
|
|
|
+ >(GET_PRODUCT_WITH_VARIANTS, {
|
|
|
+ id: 'T_1',
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(productCD?.variants.find(v => v.id === 'T_1')?.facetValues.map(fv => fv.code)).toEqual([
|
|
|
+ brandFacet.values[0].code,
|
|
|
+ createdFacet.values[0].code,
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it(
|
|
|
+ 'attempting to create FacetValue in Facet from another Channel throws',
|
|
|
+ assertThrowsWithMessage(async () => {
|
|
|
+ adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
+ await adminClient.query<CreateFacetValues.Mutation, CreateFacetValues.Variables>(
|
|
|
+ CREATE_FACET_VALUES,
|
|
|
+ {
|
|
|
+ input: [
|
|
|
+ {
|
|
|
+ facetId: brandFacet.id,
|
|
|
+ code: 'channel-brand',
|
|
|
+ translations: [{ languageCode: LanguageCode.en, name: 'Channel Brand' }],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ );
|
|
|
+ }, `No Facet with the id '1' could be found`),
|
|
|
+ );
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
export const GET_FACET_WITH_VALUES = gql`
|