Просмотр исходного кода

test(core): Add e2e test for search indexing variant asset

Relates to #2907
Michael Bromley 1 год назад
Родитель
Сommit
eefe89621a

+ 23 - 0
packages/core/e2e/default-search-plugin.e2e-spec.ts

@@ -1084,6 +1084,28 @@ describe('Default search plugin', () => {
 
 
                     expect(search2.items[0].productAsset).toBeNull();
                     expect(search2.items[0].productAsset).toBeNull();
                 });
                 });
+
+                it('updates index when asset is added to a ProductVariant', async () => {
+                    const { search: search1 } = await searchForLaptop();
+
+                    expect(search1.items[0].productVariantAsset).toBeNull();
+
+                    await adminClient.query<
+                        UpdateProductVariantsMutation,
+                        UpdateProductVariantsMutationVariables
+                    >(UPDATE_PRODUCT_VARIANTS, {
+                        input: search1.items.map(item => ({
+                            id: item.productVariantId,
+                            featuredAssetId: 'T_2',
+                        })),
+                    });
+
+                    await awaitRunningJobs(adminClient);
+
+                    const { search: search2 } = await searchForLaptop();
+
+                    expect(search2.items[0].productVariantAsset!.id).toBe('T_2');
+                });
             });
             });
 
 
             it('does not include deleted ProductVariants in index', async () => {
             it('does not include deleted ProductVariants in index', async () => {
@@ -1971,6 +1993,7 @@ export const SEARCH_GET_ASSETS = gql`
             totalItems
             totalItems
             items {
             items {
                 productId
                 productId
+                productVariantId
                 productName
                 productName
                 productVariantName
                 productVariantName
                 productAsset {
                 productAsset {

+ 5 - 0
packages/core/e2e/graphql/generated-e2e-admin-types.ts

@@ -6907,6 +6907,7 @@ export type SearchGetAssetsQuery = {
         totalItems: number;
         totalItems: number;
         items: Array<{
         items: Array<{
             productId: string;
             productId: string;
+            productVariantId: string;
             productName: string;
             productName: string;
             productVariantName: string;
             productVariantName: string;
             productAsset?: {
             productAsset?: {
@@ -18024,6 +18025,10 @@ export const SearchGetAssetsDocument = {
                                         kind: 'SelectionSet',
                                         kind: 'SelectionSet',
                                         selections: [
                                         selections: [
                                             { kind: 'Field', name: { kind: 'Name', value: 'productId' } },
                                             { kind: 'Field', name: { kind: 'Name', value: 'productId' } },
+                                            {
+                                                kind: 'Field',
+                                                name: { kind: 'Name', value: 'productVariantId' },
+                                            },
                                             { kind: 'Field', name: { kind: 'Name', value: 'productName' } },
                                             { kind: 'Field', name: { kind: 'Name', value: 'productName' } },
                                             {
                                             {
                                                 kind: 'Field',
                                                 kind: 'Field',