|
|
@@ -2,21 +2,21 @@ import gql from 'graphql-tag';
|
|
|
import path from 'path';
|
|
|
|
|
|
import {
|
|
|
- CREATE_PRODUCT_CATEGORY,
|
|
|
+ CREATE_COLLECTION,
|
|
|
GET_ASSET_LIST,
|
|
|
- GET_PRODUCT_CATEGORY,
|
|
|
- MOVE_PRODUCT_CATEGORY,
|
|
|
- UPDATE_PRODUCT_CATEGORY,
|
|
|
+ GET_COLLECTION,
|
|
|
+ MOVE_COLLECTION,
|
|
|
+ UPDATE_COLLECTION,
|
|
|
} from '../../admin-ui/src/app/data/definitions/product-definitions';
|
|
|
import {
|
|
|
- CreateProductCategory,
|
|
|
+ Collection,
|
|
|
+ CreateCollection,
|
|
|
GetAssetList,
|
|
|
- GetProductCategory,
|
|
|
+ GetCollection,
|
|
|
LanguageCode,
|
|
|
- MoveProductCategory,
|
|
|
- ProductCategory,
|
|
|
+ MoveCollection,
|
|
|
SortOrder,
|
|
|
- UpdateProductCategory,
|
|
|
+ UpdateCollection,
|
|
|
} from '../../shared/generated-types';
|
|
|
import { ROOT_CATEGORY_NAME } from '../../shared/shared-constants';
|
|
|
|
|
|
@@ -25,13 +25,13 @@ import { TestAdminClient } from './test-client';
|
|
|
import { TestServer } from './test-server';
|
|
|
import { assertThrowsWithMessage } from './test-utils';
|
|
|
|
|
|
-describe('ProductCategory resolver', () => {
|
|
|
+describe('Collection resolver', () => {
|
|
|
const client = new TestAdminClient();
|
|
|
const server = new TestServer();
|
|
|
let assets: GetAssetList.Items[];
|
|
|
- let electronicsCategory: ProductCategory.Fragment;
|
|
|
- let laptopsCategory: ProductCategory.Fragment;
|
|
|
- let appleCategory: ProductCategory.Fragment;
|
|
|
+ let electronicsCategory: Collection.Fragment;
|
|
|
+ let laptopsCategory: Collection.Fragment;
|
|
|
+ let appleCategory: Collection.Fragment;
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
const token = await server.init({
|
|
|
@@ -53,142 +53,139 @@ describe('ProductCategory resolver', () => {
|
|
|
await server.destroy();
|
|
|
});
|
|
|
|
|
|
- describe('createProductCategory', () => {
|
|
|
- it('creates a root category', async () => {
|
|
|
- const result = await client.query<
|
|
|
- CreateProductCategory.Mutation,
|
|
|
- CreateProductCategory.Variables
|
|
|
- >(CREATE_PRODUCT_CATEGORY, {
|
|
|
- input: {
|
|
|
- assetIds: [assets[0].id, assets[1].id],
|
|
|
- featuredAssetId: assets[1].id,
|
|
|
- facetValueIds: ['T_1'],
|
|
|
- translations: [{ languageCode: LanguageCode.en, name: 'Electronics', description: '' }],
|
|
|
+ describe('createCollection', () => {
|
|
|
+ it('creates a root collection', async () => {
|
|
|
+ const result = await client.query<CreateCollection.Mutation, CreateCollection.Variables>(
|
|
|
+ CREATE_COLLECTION,
|
|
|
+ {
|
|
|
+ input: {
|
|
|
+ assetIds: [assets[0].id, assets[1].id],
|
|
|
+ featuredAssetId: assets[1].id,
|
|
|
+ facetValueIds: ['T_1'],
|
|
|
+ translations: [
|
|
|
+ { languageCode: LanguageCode.en, name: 'Electronics', description: '' },
|
|
|
+ ],
|
|
|
+ },
|
|
|
},
|
|
|
- });
|
|
|
+ );
|
|
|
|
|
|
- electronicsCategory = result.createProductCategory;
|
|
|
+ electronicsCategory = result.createCollection;
|
|
|
expect(electronicsCategory).toMatchSnapshot();
|
|
|
expect(electronicsCategory.parent.name).toBe(ROOT_CATEGORY_NAME);
|
|
|
});
|
|
|
|
|
|
it('creates a nested category', async () => {
|
|
|
- const result = await client.query<
|
|
|
- CreateProductCategory.Mutation,
|
|
|
- CreateProductCategory.Variables
|
|
|
- >(CREATE_PRODUCT_CATEGORY, {
|
|
|
- input: {
|
|
|
- parentId: electronicsCategory.id,
|
|
|
- translations: [{ languageCode: LanguageCode.en, name: 'Laptops', description: '' }],
|
|
|
- facetValueIds: ['T_2'],
|
|
|
+ const result = await client.query<CreateCollection.Mutation, CreateCollection.Variables>(
|
|
|
+ CREATE_COLLECTION,
|
|
|
+ {
|
|
|
+ input: {
|
|
|
+ parentId: electronicsCategory.id,
|
|
|
+ translations: [{ languageCode: LanguageCode.en, name: 'Laptops', description: '' }],
|
|
|
+ facetValueIds: ['T_2'],
|
|
|
+ },
|
|
|
},
|
|
|
- });
|
|
|
- laptopsCategory = result.createProductCategory;
|
|
|
+ );
|
|
|
+ laptopsCategory = result.createCollection;
|
|
|
expect(laptopsCategory.parent.name).toBe(electronicsCategory.name);
|
|
|
});
|
|
|
|
|
|
it('creates a 2nd level nested category', async () => {
|
|
|
- const result = await client.query<
|
|
|
- CreateProductCategory.Mutation,
|
|
|
- CreateProductCategory.Variables
|
|
|
- >(CREATE_PRODUCT_CATEGORY, {
|
|
|
- input: {
|
|
|
- parentId: laptopsCategory.id,
|
|
|
- translations: [{ languageCode: LanguageCode.en, name: 'Apple', description: '' }],
|
|
|
- facetValueIds: ['T_3', 'T_4'],
|
|
|
+ const result = await client.query<CreateCollection.Mutation, CreateCollection.Variables>(
|
|
|
+ CREATE_COLLECTION,
|
|
|
+ {
|
|
|
+ input: {
|
|
|
+ parentId: laptopsCategory.id,
|
|
|
+ translations: [{ languageCode: LanguageCode.en, name: 'Apple', description: '' }],
|
|
|
+ facetValueIds: ['T_3', 'T_4'],
|
|
|
+ },
|
|
|
},
|
|
|
- });
|
|
|
- appleCategory = result.createProductCategory;
|
|
|
+ );
|
|
|
+ appleCategory = result.createCollection;
|
|
|
expect(appleCategory.parent.name).toBe(laptopsCategory.name);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('productCategory query', () => {
|
|
|
+ describe('collection query', () => {
|
|
|
it('returns a category', async () => {
|
|
|
- const result = await client.query<GetProductCategory.Query, GetProductCategory.Variables>(
|
|
|
- GET_PRODUCT_CATEGORY,
|
|
|
- { id: laptopsCategory.id },
|
|
|
- );
|
|
|
- if (!result.productCategory) {
|
|
|
+ const result = await client.query<GetCollection.Query, GetCollection.Variables>(GET_COLLECTION, {
|
|
|
+ id: laptopsCategory.id,
|
|
|
+ });
|
|
|
+ if (!result.collection) {
|
|
|
fail(`did not return the category`);
|
|
|
return;
|
|
|
}
|
|
|
- expect(result.productCategory.id).toBe(laptopsCategory.id);
|
|
|
+ expect(result.collection.id).toBe(laptopsCategory.id);
|
|
|
});
|
|
|
|
|
|
it('resolves descendantFacetValues 1 level deep', async () => {
|
|
|
const result = await client.query(GET_DECENDANT_FACET_VALUES, { id: laptopsCategory.id });
|
|
|
- if (!result.productCategory) {
|
|
|
+ if (!result.collection) {
|
|
|
fail(`did not return the category`);
|
|
|
return;
|
|
|
}
|
|
|
- expect(result.productCategory.descendantFacetValues.map(v => v.id)).toEqual(['T_3', 'T_4']);
|
|
|
+ expect(result.collection.descendantFacetValues.map(v => v.id)).toEqual(['T_3', 'T_4']);
|
|
|
});
|
|
|
|
|
|
it('resolves descendantFacetValues 2 levels deep', async () => {
|
|
|
const result = await client.query(GET_DECENDANT_FACET_VALUES, { id: electronicsCategory.id });
|
|
|
- if (!result.productCategory) {
|
|
|
+ if (!result.collection) {
|
|
|
fail(`did not return the category`);
|
|
|
return;
|
|
|
}
|
|
|
- expect(result.productCategory.descendantFacetValues.map(v => v.id)).toEqual([
|
|
|
- 'T_2',
|
|
|
- 'T_3',
|
|
|
- 'T_4',
|
|
|
- ]);
|
|
|
+ expect(result.collection.descendantFacetValues.map(v => v.id)).toEqual(['T_2', 'T_3', 'T_4']);
|
|
|
});
|
|
|
|
|
|
it('resolves ancestorFacetValues at root', async () => {
|
|
|
const result = await client.query(GET_ANCESTOR_FACET_VALUES, { id: electronicsCategory.id });
|
|
|
- if (!result.productCategory) {
|
|
|
+ if (!result.collection) {
|
|
|
fail(`did not return the category`);
|
|
|
return;
|
|
|
}
|
|
|
- expect(result.productCategory.ancestorFacetValues.map(v => v.id)).toEqual([]);
|
|
|
+ expect(result.collection.ancestorFacetValues.map(v => v.id)).toEqual([]);
|
|
|
});
|
|
|
|
|
|
it('resolves ancestorFacetValues 1 level deep', async () => {
|
|
|
const result = await client.query(GET_ANCESTOR_FACET_VALUES, { id: laptopsCategory.id });
|
|
|
- if (!result.productCategory) {
|
|
|
+ if (!result.collection) {
|
|
|
fail(`did not return the category`);
|
|
|
return;
|
|
|
}
|
|
|
- expect(result.productCategory.ancestorFacetValues.map(v => v.id)).toEqual(['T_1']);
|
|
|
+ expect(result.collection.ancestorFacetValues.map(v => v.id)).toEqual(['T_1']);
|
|
|
});
|
|
|
|
|
|
it('resolves ancestorFacetValues 2 levels deep', async () => {
|
|
|
const result = await client.query(GET_ANCESTOR_FACET_VALUES, { id: appleCategory.id });
|
|
|
- if (!result.productCategory) {
|
|
|
+ if (!result.collection) {
|
|
|
fail(`did not return the category`);
|
|
|
return;
|
|
|
}
|
|
|
- expect(result.productCategory.ancestorFacetValues.map(v => v.id)).toEqual(['T_1', 'T_2']);
|
|
|
+ expect(result.collection.ancestorFacetValues.map(v => v.id)).toEqual(['T_1', 'T_2']);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('updateProductCategory', () => {
|
|
|
+ describe('updateCollection', () => {
|
|
|
it('updates the details', async () => {
|
|
|
- const result = await client.query<
|
|
|
- UpdateProductCategory.Mutation,
|
|
|
- UpdateProductCategory.Variables
|
|
|
- >(UPDATE_PRODUCT_CATEGORY, {
|
|
|
- input: {
|
|
|
- id: appleCategory.id,
|
|
|
- assetIds: [assets[1].id],
|
|
|
- featuredAssetId: assets[1].id,
|
|
|
- facetValueIds: ['T_3'],
|
|
|
- translations: [{ languageCode: LanguageCode.en, description: 'Apple stuff ' }],
|
|
|
+ const result = await client.query<UpdateCollection.Mutation, UpdateCollection.Variables>(
|
|
|
+ UPDATE_COLLECTION,
|
|
|
+ {
|
|
|
+ input: {
|
|
|
+ id: appleCategory.id,
|
|
|
+ assetIds: [assets[1].id],
|
|
|
+ featuredAssetId: assets[1].id,
|
|
|
+ facetValueIds: ['T_3'],
|
|
|
+ translations: [{ languageCode: LanguageCode.en, description: 'Apple stuff ' }],
|
|
|
+ },
|
|
|
},
|
|
|
- });
|
|
|
+ );
|
|
|
|
|
|
- expect(result.updateProductCategory).toMatchSnapshot();
|
|
|
+ expect(result.updateCollection).toMatchSnapshot();
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('moveProductCategory', () => {
|
|
|
+ describe('moveCollection', () => {
|
|
|
it('moves a category to a new parent', async () => {
|
|
|
- const result = await client.query<MoveProductCategory.Mutation, MoveProductCategory.Variables>(
|
|
|
- MOVE_PRODUCT_CATEGORY,
|
|
|
+ const result = await client.query<MoveCollection.Mutation, MoveCollection.Variables>(
|
|
|
+ MOVE_COLLECTION,
|
|
|
{
|
|
|
input: {
|
|
|
categoryId: appleCategory.id,
|
|
|
@@ -198,55 +195,46 @@ describe('ProductCategory resolver', () => {
|
|
|
},
|
|
|
);
|
|
|
|
|
|
- expect(result.moveProductCategory.parent.id).toBe(electronicsCategory.id);
|
|
|
+ expect(result.moveCollection.parent.id).toBe(electronicsCategory.id);
|
|
|
|
|
|
const positions = await getChildrenOf(electronicsCategory.id);
|
|
|
expect(positions.map(i => i.id)).toEqual([appleCategory.id, laptopsCategory.id]);
|
|
|
});
|
|
|
|
|
|
it('alters the position in the current parent', async () => {
|
|
|
- await client.query<MoveProductCategory.Mutation, MoveProductCategory.Variables>(
|
|
|
- MOVE_PRODUCT_CATEGORY,
|
|
|
- {
|
|
|
- input: {
|
|
|
- categoryId: appleCategory.id,
|
|
|
- parentId: electronicsCategory.id,
|
|
|
- index: 1,
|
|
|
- },
|
|
|
+ await client.query<MoveCollection.Mutation, MoveCollection.Variables>(MOVE_COLLECTION, {
|
|
|
+ input: {
|
|
|
+ categoryId: appleCategory.id,
|
|
|
+ parentId: electronicsCategory.id,
|
|
|
+ index: 1,
|
|
|
},
|
|
|
- );
|
|
|
+ });
|
|
|
|
|
|
const afterResult = await getChildrenOf(electronicsCategory.id);
|
|
|
expect(afterResult.map(i => i.id)).toEqual([laptopsCategory.id, appleCategory.id]);
|
|
|
});
|
|
|
|
|
|
it('corrects an out-of-bounds negative index value', async () => {
|
|
|
- await client.query<MoveProductCategory.Mutation, MoveProductCategory.Variables>(
|
|
|
- MOVE_PRODUCT_CATEGORY,
|
|
|
- {
|
|
|
- input: {
|
|
|
- categoryId: appleCategory.id,
|
|
|
- parentId: electronicsCategory.id,
|
|
|
- index: -3,
|
|
|
- },
|
|
|
+ await client.query<MoveCollection.Mutation, MoveCollection.Variables>(MOVE_COLLECTION, {
|
|
|
+ input: {
|
|
|
+ categoryId: appleCategory.id,
|
|
|
+ parentId: electronicsCategory.id,
|
|
|
+ index: -3,
|
|
|
},
|
|
|
- );
|
|
|
+ });
|
|
|
|
|
|
const afterResult = await getChildrenOf(electronicsCategory.id);
|
|
|
expect(afterResult.map(i => i.id)).toEqual([appleCategory.id, laptopsCategory.id]);
|
|
|
});
|
|
|
|
|
|
it('corrects an out-of-bounds positive index value', async () => {
|
|
|
- await client.query<MoveProductCategory.Mutation, MoveProductCategory.Variables>(
|
|
|
- MOVE_PRODUCT_CATEGORY,
|
|
|
- {
|
|
|
- input: {
|
|
|
- categoryId: appleCategory.id,
|
|
|
- parentId: electronicsCategory.id,
|
|
|
- index: 10,
|
|
|
- },
|
|
|
+ await client.query<MoveCollection.Mutation, MoveCollection.Variables>(MOVE_COLLECTION, {
|
|
|
+ input: {
|
|
|
+ categoryId: appleCategory.id,
|
|
|
+ parentId: electronicsCategory.id,
|
|
|
+ index: 10,
|
|
|
},
|
|
|
- );
|
|
|
+ });
|
|
|
|
|
|
const afterResult = await getChildrenOf(electronicsCategory.id);
|
|
|
expect(afterResult.map(i => i.id)).toEqual([laptopsCategory.id, appleCategory.id]);
|
|
|
@@ -256,17 +244,14 @@ describe('ProductCategory resolver', () => {
|
|
|
'throws if attempting to move into self',
|
|
|
assertThrowsWithMessage(
|
|
|
() =>
|
|
|
- client.query<MoveProductCategory.Mutation, MoveProductCategory.Variables>(
|
|
|
- MOVE_PRODUCT_CATEGORY,
|
|
|
- {
|
|
|
- input: {
|
|
|
- categoryId: appleCategory.id,
|
|
|
- parentId: appleCategory.id,
|
|
|
- index: 0,
|
|
|
- },
|
|
|
+ client.query<MoveCollection.Mutation, MoveCollection.Variables>(MOVE_COLLECTION, {
|
|
|
+ input: {
|
|
|
+ categoryId: appleCategory.id,
|
|
|
+ parentId: appleCategory.id,
|
|
|
+ index: 0,
|
|
|
},
|
|
|
- ),
|
|
|
- `Cannot move a ProductCategory into itself`,
|
|
|
+ }),
|
|
|
+ `Cannot move a Collection into itself`,
|
|
|
),
|
|
|
);
|
|
|
|
|
|
@@ -274,30 +259,27 @@ describe('ProductCategory resolver', () => {
|
|
|
'throws if attempting to move into a decendant of self',
|
|
|
assertThrowsWithMessage(
|
|
|
() =>
|
|
|
- client.query<MoveProductCategory.Mutation, MoveProductCategory.Variables>(
|
|
|
- MOVE_PRODUCT_CATEGORY,
|
|
|
- {
|
|
|
- input: {
|
|
|
- categoryId: appleCategory.id,
|
|
|
- parentId: appleCategory.id,
|
|
|
- index: 0,
|
|
|
- },
|
|
|
+ client.query<MoveCollection.Mutation, MoveCollection.Variables>(MOVE_COLLECTION, {
|
|
|
+ input: {
|
|
|
+ categoryId: appleCategory.id,
|
|
|
+ parentId: appleCategory.id,
|
|
|
+ index: 0,
|
|
|
},
|
|
|
- ),
|
|
|
- `Cannot move a ProductCategory into itself`,
|
|
|
+ }),
|
|
|
+ `Cannot move a Collection into itself`,
|
|
|
),
|
|
|
);
|
|
|
|
|
|
async function getChildrenOf(parentId: string): Promise<Array<{ name: string; id: string }>> {
|
|
|
const result = await client.query(GET_CATEGORIES);
|
|
|
- return result.productCategories.items.filter(i => i.parent.id === parentId);
|
|
|
+ return result.collections.items.filter(i => i.parent.id === parentId);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
const GET_CATEGORIES = gql`
|
|
|
query GetCategories {
|
|
|
- productCategories(languageCode: en) {
|
|
|
+ collections(languageCode: en) {
|
|
|
items {
|
|
|
id
|
|
|
name
|
|
|
@@ -313,7 +295,7 @@ const GET_CATEGORIES = gql`
|
|
|
|
|
|
const GET_DECENDANT_FACET_VALUES = gql`
|
|
|
query GetDescendantFacetValues($id: ID!) {
|
|
|
- productCategory(id: $id) {
|
|
|
+ collection(id: $id) {
|
|
|
id
|
|
|
descendantFacetValues {
|
|
|
id
|
|
|
@@ -325,7 +307,7 @@ const GET_DECENDANT_FACET_VALUES = gql`
|
|
|
|
|
|
const GET_ANCESTOR_FACET_VALUES = gql`
|
|
|
query GetAncestorFacetValues($id: ID!) {
|
|
|
- productCategory(id: $id) {
|
|
|
+ collection(id: $id) {
|
|
|
id
|
|
|
ancestorFacetValues {
|
|
|
id
|