|
@@ -8,6 +8,8 @@ import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-conf
|
|
|
|
|
|
|
|
import { FACET_VALUE_FRAGMENT, FACET_WITH_VALUES_FRAGMENT } from './graphql/fragments';
|
|
import { FACET_VALUE_FRAGMENT, FACET_WITH_VALUES_FRAGMENT } from './graphql/fragments';
|
|
|
import {
|
|
import {
|
|
|
|
|
+ AssignFacetsToChannelMutation,
|
|
|
|
|
+ AssignFacetsToChannelMutationVariables,
|
|
|
AssignProductsToChannel,
|
|
AssignProductsToChannel,
|
|
|
ChannelFragment,
|
|
ChannelFragment,
|
|
|
CreateChannel,
|
|
CreateChannel,
|
|
@@ -19,11 +21,16 @@ import {
|
|
|
DeletionResult,
|
|
DeletionResult,
|
|
|
FacetWithValues,
|
|
FacetWithValues,
|
|
|
GetFacetList,
|
|
GetFacetList,
|
|
|
|
|
+ GetFacetListSimple,
|
|
|
|
|
+ GetFacetListSimpleQuery,
|
|
|
GetFacetWithValues,
|
|
GetFacetWithValues,
|
|
|
GetProductListWithVariants,
|
|
GetProductListWithVariants,
|
|
|
GetProductWithFacetValues,
|
|
GetProductWithFacetValues,
|
|
|
GetProductWithVariants,
|
|
GetProductWithVariants,
|
|
|
LanguageCode,
|
|
LanguageCode,
|
|
|
|
|
+ RemoveCollectionsFromChannelMutationVariables,
|
|
|
|
|
+ RemoveFacetsFromChannelMutation,
|
|
|
|
|
+ RemoveFacetsFromChannelMutationVariables,
|
|
|
UpdateFacet,
|
|
UpdateFacet,
|
|
|
UpdateFacetValues,
|
|
UpdateFacetValues,
|
|
|
UpdateProduct,
|
|
UpdateProduct,
|
|
@@ -430,6 +437,7 @@ describe('Facet resolver', () => {
|
|
|
|
|
|
|
|
describe('channels', () => {
|
|
describe('channels', () => {
|
|
|
const SECOND_CHANNEL_TOKEN = 'second_channel_token';
|
|
const SECOND_CHANNEL_TOKEN = 'second_channel_token';
|
|
|
|
|
+ let secondChannel: ChannelFragment;
|
|
|
let createdFacet: CreateFacet.CreateFacet;
|
|
let createdFacet: CreateFacet.CreateFacet;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
beforeAll(async () => {
|
|
@@ -448,12 +456,14 @@ describe('Facet resolver', () => {
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ secondChannel = createChannel as ChannelFragment;
|
|
|
|
|
+
|
|
|
const { assignProductsToChannel } = await adminClient.query<
|
|
const { assignProductsToChannel } = await adminClient.query<
|
|
|
AssignProductsToChannel.Mutation,
|
|
AssignProductsToChannel.Mutation,
|
|
|
AssignProductsToChannel.Variables
|
|
AssignProductsToChannel.Variables
|
|
|
>(ASSIGN_PRODUCT_TO_CHANNEL, {
|
|
>(ASSIGN_PRODUCT_TO_CHANNEL, {
|
|
|
input: {
|
|
input: {
|
|
|
- channelId: (createChannel as ChannelFragment).id,
|
|
|
|
|
|
|
+ channelId: secondChannel.id,
|
|
|
productIds: ['T_1'],
|
|
productIds: ['T_1'],
|
|
|
priceFactor: 0.5,
|
|
priceFactor: 0.5,
|
|
|
},
|
|
},
|
|
@@ -634,6 +644,91 @@ describe('Facet resolver', () => {
|
|
|
);
|
|
);
|
|
|
}, `No Facet with the id '1' could be found`),
|
|
}, `No Facet with the id '1' could be found`),
|
|
|
);
|
|
);
|
|
|
|
|
+
|
|
|
|
|
+ it('removing from channel with error', async () => {
|
|
|
|
|
+ adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
|
|
+ const { facets: before } = await adminClient.query<GetFacetListSimpleQuery>(
|
|
|
|
|
+ GET_FACET_LIST_SIMPLE,
|
|
|
|
|
+ );
|
|
|
|
|
+ expect(before.items).toEqual([{ id: 'T_4', name: 'Channel Facet' }]);
|
|
|
|
|
+
|
|
|
|
|
+ adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);
|
|
|
|
|
+ const { removeFacetsFromChannel } = await adminClient.query<
|
|
|
|
|
+ RemoveFacetsFromChannelMutation,
|
|
|
|
|
+ RemoveFacetsFromChannelMutationVariables
|
|
|
|
|
+ >(REMOVE_FACETS_FROM_CHANNEL, {
|
|
|
|
|
+ input: {
|
|
|
|
|
+ channelId: secondChannel.id,
|
|
|
|
|
+ facetIds: [createdFacet.id],
|
|
|
|
|
+ force: false,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ expect(removeFacetsFromChannel).toEqual([
|
|
|
|
|
+ {
|
|
|
|
|
+ errorCode: 'FACET_IN_USE_ERROR',
|
|
|
|
|
+ message:
|
|
|
|
|
+ 'The selected Facet includes FacetValues which are assigned to 1 Product 1 ProductVariant',
|
|
|
|
|
+ productCount: 1,
|
|
|
|
|
+ variantCount: 1,
|
|
|
|
|
+ },
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
|
|
+ const { facets: after } = await adminClient.query<GetFacetListSimpleQuery>(GET_FACET_LIST_SIMPLE);
|
|
|
|
|
+ expect(after.items).toEqual([{ id: 'T_4', name: 'Channel Facet' }]);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('force removing from channel', async () => {
|
|
|
|
|
+ adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
|
|
+ const { facets: before } = await adminClient.query<GetFacetListSimpleQuery>(
|
|
|
|
|
+ GET_FACET_LIST_SIMPLE,
|
|
|
|
|
+ );
|
|
|
|
|
+ expect(before.items).toEqual([{ id: 'T_4', name: 'Channel Facet' }]);
|
|
|
|
|
+
|
|
|
|
|
+ adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);
|
|
|
|
|
+ const { removeFacetsFromChannel } = await adminClient.query<
|
|
|
|
|
+ RemoveFacetsFromChannelMutation,
|
|
|
|
|
+ RemoveFacetsFromChannelMutationVariables
|
|
|
|
|
+ >(REMOVE_FACETS_FROM_CHANNEL, {
|
|
|
|
|
+ input: {
|
|
|
|
|
+ channelId: secondChannel.id,
|
|
|
|
|
+ facetIds: [createdFacet.id],
|
|
|
|
|
+ force: true,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ expect(removeFacetsFromChannel).toEqual([{ id: 'T_4', name: 'Channel Facet' }]);
|
|
|
|
|
+
|
|
|
|
|
+ adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
|
|
+ const { facets: after } = await adminClient.query<GetFacetListSimpleQuery>(GET_FACET_LIST_SIMPLE);
|
|
|
|
|
+ expect(after.items).toEqual([]);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('assigning to channel', async () => {
|
|
|
|
|
+ adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
|
|
+ const { facets: before } = await adminClient.query<GetFacetListSimpleQuery>(
|
|
|
|
|
+ GET_FACET_LIST_SIMPLE,
|
|
|
|
|
+ );
|
|
|
|
|
+ expect(before.items).toEqual([]);
|
|
|
|
|
+
|
|
|
|
|
+ adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);
|
|
|
|
|
+ const { assignFacetsToChannel } = await adminClient.query<
|
|
|
|
|
+ AssignFacetsToChannelMutation,
|
|
|
|
|
+ AssignFacetsToChannelMutationVariables
|
|
|
|
|
+ >(ASSIGN_FACETS_TO_CHANNEL, {
|
|
|
|
|
+ input: {
|
|
|
|
|
+ channelId: secondChannel.id,
|
|
|
|
|
+ facetIds: [createdFacet.id],
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ expect(assignFacetsToChannel).toEqual([{ id: 'T_4', name: 'Channel Facet' }]);
|
|
|
|
|
+
|
|
|
|
|
+ adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
|
|
+ const { facets: after } = await adminClient.query<GetFacetListSimpleQuery>(GET_FACET_LIST_SIMPLE);
|
|
|
|
|
+ expect(after.items).toEqual([{ id: 'T_4', name: 'Channel Facet' }]);
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// https://github.com/vendure-ecommerce/vendure/issues/715
|
|
// https://github.com/vendure-ecommerce/vendure/issues/715
|
|
@@ -773,3 +868,29 @@ export const UPDATE_FACET_VALUES = gql`
|
|
|
}
|
|
}
|
|
|
${FACET_VALUE_FRAGMENT}
|
|
${FACET_VALUE_FRAGMENT}
|
|
|
`;
|
|
`;
|
|
|
|
|
+
|
|
|
|
|
+export const ASSIGN_FACETS_TO_CHANNEL = gql`
|
|
|
|
|
+ mutation AssignFacetsToChannel($input: AssignFacetsToChannelInput!) {
|
|
|
|
|
+ assignFacetsToChannel(input: $input) {
|
|
|
|
|
+ id
|
|
|
|
|
+ name
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+`;
|
|
|
|
|
+
|
|
|
|
|
+export const REMOVE_FACETS_FROM_CHANNEL = gql`
|
|
|
|
|
+ mutation RemoveFacetsFromChannel($input: RemoveFacetsFromChannelInput!) {
|
|
|
|
|
+ removeFacetsFromChannel(input: $input) {
|
|
|
|
|
+ ... on Facet {
|
|
|
|
|
+ id
|
|
|
|
|
+ name
|
|
|
|
|
+ }
|
|
|
|
|
+ ... on FacetInUseError {
|
|
|
|
|
+ errorCode
|
|
|
|
|
+ message
|
|
|
|
|
+ productCount
|
|
|
|
|
+ variantCount
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+`;
|