|
|
@@ -3,9 +3,10 @@ import gql from 'graphql-tag';
|
|
|
import path from 'path';
|
|
|
|
|
|
import { CREATE_COLLECTION, UPDATE_COLLECTION } from '../../../admin-ui/src/app/data/definitions/collection-definitions';
|
|
|
-import { GET_PRODUCT_WITH_VARIANTS, UPDATE_PRODUCT_VARIANTS } from '../../../admin-ui/src/app/data/definitions/product-definitions';
|
|
|
-import { ConfigArgType, CreateCollection, LanguageCode, UpdateCollection } from '../../common/lib/generated-types';
|
|
|
-import { GetProductWithVariants, UpdateProductVariants } from '../../common/src/generated-types';
|
|
|
+import { CREATE_FACET } from '../../../admin-ui/src/app/data/definitions/facet-definitions';
|
|
|
+import { GET_PRODUCT_WITH_VARIANTS, UPDATE_PRODUCT, UPDATE_PRODUCT_VARIANTS } from '../../../admin-ui/src/app/data/definitions/product-definitions';
|
|
|
+import { ConfigArgType, CreateCollection, FacetWithValues, UpdateCollection } from '../../common/lib/generated-types';
|
|
|
+import { CreateFacet, GetProductWithVariants, LanguageCode, UpdateProduct, UpdateProductVariants } from '../../common/src/generated-types';
|
|
|
import { facetValueCollectionFilter } from '../src/config/collection/default-collection-filters';
|
|
|
|
|
|
import { TEST_SETUP_TIMEOUT_MS } from './config/test-config';
|
|
|
@@ -85,6 +86,57 @@ describe('Shop catalog', () => {
|
|
|
{ id: 'T_6', name: 'Curvy Monitor 27 inch'},
|
|
|
]);
|
|
|
});
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('facets', () => {
|
|
|
+ let facetValue: FacetWithValues.Values;
|
|
|
+
|
|
|
+ beforeAll(async () => {
|
|
|
+ const result = await adminClient.query<CreateFacet.Mutation, CreateFacet.Variables>(CREATE_FACET, {
|
|
|
+ input: {
|
|
|
+ code: 'profit-margin',
|
|
|
+ isPrivate: true,
|
|
|
+ translations: [
|
|
|
+ { languageCode: LanguageCode.en, name: 'Profit Margin' },
|
|
|
+ ],
|
|
|
+ values: [
|
|
|
+ { code: 'massive', translations: [{ languageCode: LanguageCode.en, name: 'massive' }] },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ });
|
|
|
+ facetValue = result.createFacet.values[0];
|
|
|
+
|
|
|
+ await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(UPDATE_PRODUCT, {
|
|
|
+ input: {
|
|
|
+ id: 'T_2',
|
|
|
+ facetValueIds: [facetValue.id],
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ await adminClient.query<UpdateProductVariants.Mutation, UpdateProductVariants.Variables>(UPDATE_PRODUCT_VARIANTS, {
|
|
|
+ input: [{
|
|
|
+ id: 'T_6',
|
|
|
+ facetValueIds: [facetValue.id],
|
|
|
+ }],
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('omits private Product.facetValues', async () => {
|
|
|
+ const result = await shopClient.query(GET_PRODUCT_FACET_VALUES, {
|
|
|
+ id: 'T_2',
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(result.product!.facetValues.map((fv: any) => fv.name)).toEqual([]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('omits private ProductVariant.facetValues', async () => {
|
|
|
+ const result = await shopClient.query(GET_PRODUCT_VARIANT_FACET_VALUES, {
|
|
|
+ id: 'T_2',
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(result.product!.variants[0].facetValues.map((fv: any) => fv.name)).toEqual([]);
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
describe('collections', () => {
|
|
|
@@ -252,3 +304,30 @@ const GET_COLLECTION_LIST = gql`{
|
|
|
}
|
|
|
}
|
|
|
}`;
|
|
|
+
|
|
|
+const GET_PRODUCT_FACET_VALUES = gql`
|
|
|
+ query ($id: ID!){
|
|
|
+ product(id: $id) {
|
|
|
+ id
|
|
|
+ name
|
|
|
+ facetValues {
|
|
|
+ name
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+`;
|
|
|
+
|
|
|
+const GET_PRODUCT_VARIANT_FACET_VALUES = gql`
|
|
|
+ query ($id: ID!){
|
|
|
+ product(id: $id) {
|
|
|
+ id
|
|
|
+ name
|
|
|
+ variants {
|
|
|
+ id
|
|
|
+ facetValues {
|
|
|
+ name
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+`;
|