Skip to content

Commit

Permalink
fix(core): Assign assets when assigning Collection to channel
Browse files Browse the repository at this point in the history
Fixes #2122, relates to #2478
  • Loading branch information
michaelbromley committed Oct 27, 2023
1 parent 82535c9 commit a8481bf
Show file tree
Hide file tree
Showing 12 changed files with 27,962 additions and 67,481 deletions.
8,329 changes: 4,179 additions & 4,150 deletions packages/asset-server-plugin/e2e/graphql/generated-e2e-asset-server-plugin-types.ts

Large diffs are not rendered by default.

4,948 changes: 2,459 additions & 2,489 deletions packages/common/src/generated-shop-types.ts

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions packages/core/e2e/asset-channel.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import { CurrencyCode, LanguageCode } from './graphql/generated-e2e-admin-types'
import * as Codegen from './graphql/generated-e2e-admin-types';
import { DeletionResult } from './graphql/generated-e2e-shop-types';
import {
ASSIGN_COLLECTIONS_TO_CHANNEL,
ASSIGN_PRODUCT_TO_CHANNEL,
CREATE_ASSETS,
CREATE_CHANNEL,
DELETE_ASSET,
GET_ASSET,
GET_PRODUCT_WITH_VARIANTS,
UPDATE_COLLECTION,
UPDATE_PRODUCT,
} from './graphql/shared-definitions';
import { assertThrowsWithMessage } from './utils/assert-throws-with-message';
Expand Down Expand Up @@ -299,6 +301,94 @@ describe('Product related assets', () => {
});
});

describe('Collection related assets', () => {
let collectionFeaturedAssetId: string;
it('Featured asset is available in default channel', async () => {
adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);

await adminClient.query<Codegen.UpdateCollectionMutation, Codegen.UpdateCollectionMutationVariables>(
UPDATE_COLLECTION,
{
input: {
id: 'T_2',
featuredAssetId: 'T_3',
assetIds: ['T_3'],
},
},
);

const { collection } = await adminClient.query<
Codegen.GetCollectionWithAssetsQuery,
Codegen.GetCollectionWithAssetsQueryVariables
>(GET_COLLECTION_WITH_ASSETS, {
id: 'T_2',
});
collectionFeaturedAssetId = collection!.featuredAsset!.id;
expect(collectionFeaturedAssetId).toBeDefined();

adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);
const { asset } = await adminClient.query<Codegen.GetAssetQuery, Codegen.GetAssetQueryVariables>(
GET_ASSET,
{
id: collectionFeaturedAssetId,
},
);
expect(asset?.id).toEqual(collectionFeaturedAssetId);
});

it('Featured asset is not available in channel2', async () => {
adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
const { asset } = await adminClient.query<Codegen.GetAssetQuery, Codegen.GetAssetQueryVariables>(
GET_ASSET,
{
id: collectionFeaturedAssetId,
},
);
expect(asset?.id).toBeUndefined();
});

it('Add Collection to channel2', async () => {
adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);
const { assignCollectionsToChannel } = await adminClient.query<
Codegen.AssignCollectionsToChannelMutation,
Codegen.AssignCollectionsToChannelMutationVariables
>(ASSIGN_COLLECTIONS_TO_CHANNEL, {
input: {
channelId: channel2Id,
collectionIds: ['T_2'],
},
});
expect(assignCollectionsToChannel[0].id).toEqual('T_2');
});

it('Get featured asset from channel2', async () => {
adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
const { asset } = await adminClient.query<Codegen.GetAssetQuery, Codegen.GetAssetQueryVariables>(
GET_ASSET,
{
id: collectionFeaturedAssetId,
},
);
expect(asset?.id).toEqual(collectionFeaturedAssetId);
});
});

const GET_COLLECTION_WITH_ASSETS = gql`
query GetCollectionWithAssets($id: ID!) {
collection(id: $id) {
id
name
featuredAsset {
...Asset
}
assets {
...Asset
}
}
}
${ASSET_FRAGMENT}
`;

export const ASSIGN_ASSET_TO_CHANNEL = gql`
mutation assignAssetsToChannel($input: AssignAssetsToChannelInput!) {
assignAssetsToChannel(input: $input) {
Expand Down
12 changes: 2 additions & 10 deletions packages/core/e2e/collection.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import path from 'path';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';

import { initialData } from '../../../e2e-common/e2e-initial-data';
import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
import { pick } from '../../common/lib/pick';

import { COLLECTION_FRAGMENT, FACET_VALUE_FRAGMENT } from './graphql/fragments';
Expand All @@ -28,6 +28,7 @@ import {
SortOrder,
} from './graphql/generated-e2e-admin-types';
import {
ASSIGN_COLLECTIONS_TO_CHANNEL,
CREATE_CHANNEL,
CREATE_COLLECTION,
DELETE_PRODUCT,
Expand Down Expand Up @@ -2579,15 +2580,6 @@ const PREVIEW_COLLECTION_VARIANTS = gql`
}
`;

const ASSIGN_COLLECTIONS_TO_CHANNEL = gql`
mutation AssignCollectionsToChannel($input: AssignCollectionsToChannelInput!) {
assignCollectionsToChannel(input: $input) {
...Collection
}
}
${COLLECTION_FRAGMENT}
`;

const REMOVE_COLLECTIONS_FROM_CHANNEL = gql`
mutation RemoveCollectionsFromChannel($input: RemoveCollectionsFromChannelInput!) {
removeCollectionsFromChannel(input: $input) {
Expand Down
Loading

0 comments on commit a8481bf

Please sign in to comment.