diff --git a/packages/core/e2e/collection.e2e-spec.ts b/packages/core/e2e/collection.e2e-spec.ts index 1ad0323e63..ddfad1fb46 100644 --- a/packages/core/e2e/collection.e2e-spec.ts +++ b/packages/core/e2e/collection.e2e-spec.ts @@ -4,7 +4,10 @@ import gql from 'graphql-tag'; import path from 'path'; import { StringOperator } from '../src/common/configurable-operation'; -import { facetValueCollectionFilter, variantNameCollectionFilter } from '../src/config/collection/default-collection-filters'; +import { + facetValueCollectionFilter, + variantNameCollectionFilter, +} from '../src/config/collection/default-collection-filters'; import { TEST_SETUP_TIMEOUT_MS } from './config/test-config'; import { COLLECTION_FRAGMENT, FACET_VALUE_FRAGMENT } from './graphql/fragments'; @@ -14,6 +17,7 @@ import { CreateCollection, CreateCollectionInput, CreateCollectionSelectVariants, + DeleteProduct, FacetValueFragment, GetAssetList, GetCollection, @@ -30,7 +34,14 @@ import { UpdateProduct, UpdateProductVariants, } from './graphql/generated-e2e-admin-types'; -import { CREATE_COLLECTION, GET_ASSET_LIST, UPDATE_COLLECTION, UPDATE_PRODUCT, UPDATE_PRODUCT_VARIANTS } from './graphql/shared-definitions'; +import { + CREATE_COLLECTION, + DELETE_PRODUCT, + GET_ASSET_LIST, + UPDATE_COLLECTION, + UPDATE_PRODUCT, + UPDATE_PRODUCT_VARIANTS, +} from './graphql/shared-definitions'; import { TestAdminClient } from './test-client'; import { TestServer } from './test-server'; import { assertThrowsWithMessage } from './utils/assert-throws-with-message'; @@ -73,7 +84,9 @@ describe('Collection resolver', () => { * Test case for https://github.com/vendure-ecommerce/vendure/issues/97 */ it('collection breadcrumbs works after bootstrap', async () => { - const result = await client.query(GET_COLLECTION_BREADCRUMBS, { id: 'T_1' }); + const result = await client.query(GET_COLLECTION_BREADCRUMBS, { + id: 'T_1', + }); expect(result.collection!.breadcrumbs[0].name).toBe(ROOT_COLLECTION_NAME); }); @@ -705,6 +718,26 @@ describe('Collection resolver', () => { }); }); + it('collection does not list deleted products', async () => { + await client.query(DELETE_PRODUCT, { + id: 'T_2', // curvy monitor + }); + const { collection } = await client.query< + GetCollectionProducts.Query, + GetCollectionProducts.Variables + >(GET_COLLECTION_PRODUCT_VARIANTS, { + id: pearCollection.id, + }); + expect(collection!.productVariants.items.map(i => i.name)).toEqual([ + 'Laptop 13 inch 8GB', + 'Laptop 15 inch 8GB', + 'Laptop 13 inch 16GB', + 'Laptop 15 inch 16GB', + 'Gaming PC i7-8700 240GB SSD', + 'Instant Camera', + ]); + }); + function getFacetValueId(code: string): string { const match = facetValues.find(fv => fv.code === code); if (!match) { diff --git a/packages/core/e2e/graphql/shared-definitions.ts b/packages/core/e2e/graphql/shared-definitions.ts index 6a4deeb4e7..a80061357e 100644 --- a/packages/core/e2e/graphql/shared-definitions.ts +++ b/packages/core/e2e/graphql/shared-definitions.ts @@ -228,3 +228,11 @@ export const GET_FACET_LIST = gql` } ${FACET_WITH_VALUES_FRAGMENT} `; + +export const DELETE_PRODUCT = gql` + mutation DeleteProduct($id: ID!) { + deleteProduct(id: $id) { + result + } + } +`; diff --git a/packages/core/e2e/product.e2e-spec.ts b/packages/core/e2e/product.e2e-spec.ts index f69121305c..923fdd2c7f 100644 --- a/packages/core/e2e/product.e2e-spec.ts +++ b/packages/core/e2e/product.e2e-spec.ts @@ -22,6 +22,7 @@ import { } from './graphql/generated-e2e-admin-types'; import { CREATE_PRODUCT, + DELETE_PRODUCT, GET_ASSET_LIST, GET_PRODUCT_LIST, GET_PRODUCT_WITH_VARIANTS, @@ -678,14 +679,6 @@ describe('Product resolver', () => { }); }); -const DELETE_PRODUCT = gql` - mutation DeleteProduct($id: ID!) { - deleteProduct(id: $id) { - result - } - } -`; - export const ADD_OPTION_GROUP_TO_PRODUCT = gql` mutation AddOptionGroupToProduct($productId: ID!, $optionGroupId: ID!) { addOptionGroupToProduct(productId: $productId, optionGroupId: $optionGroupId) { diff --git a/packages/core/src/service/services/product-variant.service.ts b/packages/core/src/service/services/product-variant.service.ts index d8a7e2e6d2..c2d905a08b 100644 --- a/packages/core/src/service/services/product-variant.service.ts +++ b/packages/core/src/service/services/product-variant.service.ts @@ -103,11 +103,12 @@ export class ProductVariantService { channelId: ctx.channelId, }) .leftJoin('productvariant.collections', 'collection') + .leftJoin('productvariant.product', 'product') + .andWhere('product.deletedAt IS NULL', { deletedAt: null }) .andWhere('collection.id = :collectionId', { collectionId }); if (options && options.filter && options.filter.enabled && options.filter.enabled.eq === true) { - qb.leftJoin('productvariant.product', 'product') - .andWhere('product.enabled = :enabled', { enabled: true }); + qb.andWhere('product.enabled = :enabled', { enabled: true }); } return qb.getManyAndCount()