Skip to content

Commit

Permalink
fix(core): Do not list deleted productVariants in a Collection
Browse files Browse the repository at this point in the history
Fixes #100
  • Loading branch information
michaelbromley committed May 29, 2019
1 parent 6a54be3 commit e1fecbb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
39 changes: 36 additions & 3 deletions packages/core/e2e/collection.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -14,6 +17,7 @@ import {
CreateCollection,
CreateCollectionInput,
CreateCollectionSelectVariants,
DeleteProduct,
FacetValueFragment,
GetAssetList,
GetCollection,
Expand All @@ -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';
Expand Down Expand Up @@ -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<GetCollectionBreadcrumbs.Query>(GET_COLLECTION_BREADCRUMBS, { id: 'T_1' });
const result = await client.query<GetCollectionBreadcrumbs.Query>(GET_COLLECTION_BREADCRUMBS, {
id: 'T_1',
});
expect(result.collection!.breadcrumbs[0].name).toBe(ROOT_COLLECTION_NAME);
});

Expand Down Expand Up @@ -705,6 +718,26 @@ describe('Collection resolver', () => {
});
});

it('collection does not list deleted products', async () => {
await client.query<DeleteProduct.Mutation, DeleteProduct.Variables>(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) {
Expand Down
8 changes: 8 additions & 0 deletions packages/core/e2e/graphql/shared-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
`;
9 changes: 1 addition & 8 deletions packages/core/e2e/product.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/service/services/product-variant.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e1fecbb

Please sign in to comment.