Skip to content

Commit

Permalink
feat(core): Implement search by collection slug
Browse files Browse the repository at this point in the history
Closes #405
  • Loading branch information
michaelbromley committed Aug 20, 2020
1 parent 06bb780 commit a4cbdbb
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 67 deletions.
9 changes: 5 additions & 4 deletions packages/admin-ui/src/lib/core/src/common/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ export type CreateZoneInput = {
/**
* @description
* ISO 4217 currency code
*
*
* @docsCategory common
*/
export enum CurrencyCode {
Expand Down Expand Up @@ -1407,7 +1407,7 @@ export type JobSortParameter = {
/**
* @description
* The state of a Job in the JobQueue
*
*
* @docsCategory common
*/
export enum JobState {
Expand All @@ -1425,7 +1425,7 @@ export enum JobState {
* region or script modifier (e.g. de_AT). The selection available is based
* on the [Unicode CLDR summary list](https://unicode-org.github.io/cldr-staging/charts/37/summary/root.html)
* and includes the major spoken languages of the world and any widely-used variants.
*
*
* @docsCategory common
*/
export enum LanguageCode {
Expand Down Expand Up @@ -2661,7 +2661,7 @@ export type PaymentMethodSortParameter = {
* @description
* Permissions for administrators and customers. Used to control access to
* GraphQL resolvers via the {@link Allow} decorator.
*
*
* @docsCategory common
*/
export enum Permission {
Expand Down Expand Up @@ -3340,6 +3340,7 @@ export type SearchInput = {
facetValueIds?: Maybe<Array<Scalars['ID']>>;
facetValueOperator?: Maybe<LogicalOperator>;
collectionId?: Maybe<Scalars['ID']>;
collectionSlug?: Maybe<Scalars['String']>;
groupByProduct?: Maybe<Scalars['Boolean']>;
take?: Maybe<Scalars['Int']>;
skip?: Maybe<Scalars['Int']>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3170,6 +3170,7 @@ export type SearchInput = {
facetValueIds?: Maybe<Array<Scalars['ID']>>;
facetValueOperator?: Maybe<LogicalOperator>;
collectionId?: Maybe<Scalars['ID']>;
collectionSlug?: Maybe<Scalars['String']>;
groupByProduct?: Maybe<Scalars['Boolean']>;
take?: Maybe<Scalars['Int']>;
skip?: Maybe<Scalars['Int']>;
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/generated-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,7 @@ export type SearchInput = {
facetValueIds?: Maybe<Array<Scalars['ID']>>;
facetValueOperator?: Maybe<LogicalOperator>;
collectionId?: Maybe<Scalars['ID']>;
collectionSlug?: Maybe<Scalars['String']>;
groupByProduct?: Maybe<Scalars['Boolean']>;
take?: Maybe<Scalars['Int']>;
skip?: Maybe<Scalars['Int']>;
Expand Down
9 changes: 5 additions & 4 deletions packages/common/src/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ export type CreateZoneInput = {
/**
* @description
* ISO 4217 currency code
*
*
* @docsCategory common
*/
export enum CurrencyCode {
Expand Down Expand Up @@ -1399,7 +1399,7 @@ export type JobSortParameter = {
/**
* @description
* The state of a Job in the JobQueue
*
*
* @docsCategory common
*/
export enum JobState {
Expand All @@ -1417,7 +1417,7 @@ export enum JobState {
* region or script modifier (e.g. de_AT). The selection available is based
* on the [Unicode CLDR summary list](https://unicode-org.github.io/cldr-staging/charts/37/summary/root.html)
* and includes the major spoken languages of the world and any widely-used variants.
*
*
* @docsCategory common
*/
export enum LanguageCode {
Expand Down Expand Up @@ -2621,7 +2621,7 @@ export type PaymentMethodSortParameter = {
* @description
* Permissions for administrators and customers. Used to control access to
* GraphQL resolvers via the {@link Allow} decorator.
*
*
* @docsCategory common
*/
export enum Permission {
Expand Down Expand Up @@ -3297,6 +3297,7 @@ export type SearchInput = {
facetValueIds?: Maybe<Array<Scalars['ID']>>;
facetValueOperator?: Maybe<LogicalOperator>;
collectionId?: Maybe<Scalars['ID']>;
collectionSlug?: Maybe<Scalars['String']>;
groupByProduct?: Maybe<Scalars['Boolean']>;
take?: Maybe<Scalars['Int']>;
skip?: Maybe<Scalars['Int']>;
Expand Down
37 changes: 35 additions & 2 deletions packages/core/e2e/default-search-plugin.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,23 @@ describe('Default search plugin', () => {
]);
}

async function testMatchCollectionSlug(client: SimpleGraphQLClient) {
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
collectionSlug: 'plants',
groupByProduct: true,
},
},
);
expect(result.search.items.map(i => i.productName)).toEqual([
'Spiky Cactus',
'Orchid',
'Bonsai Tree',
]);
}

async function testSinglePrices(client: SimpleGraphQLClient) {
const result = await client.query<SearchGetPrices.Query, SearchGetPrices.Variables>(
SEARCH_GET_PRICES,
Expand Down Expand Up @@ -254,6 +271,8 @@ describe('Default search plugin', () => {

it('matches by collectionId', () => testMatchCollectionId(shopClient));

it('matches by collectionSlug', () => testMatchCollectionSlug(shopClient));

it('single prices', () => testSinglePrices(shopClient));

it('price ranges', () => testPriceRanges(shopClient));
Expand Down Expand Up @@ -406,6 +425,8 @@ describe('Default search plugin', () => {

it('matches by collectionId', () => testMatchCollectionId(adminClient));

it('matches by collectionSlug', () => testMatchCollectionSlug(adminClient));

it('single prices', () => testSinglePrices(adminClient));

it('price ranges', () => testPriceRanges(adminClient));
Expand Down Expand Up @@ -531,9 +552,21 @@ describe('Default search plugin', () => {
await awaitRunningJobs(adminClient);
// add an additional check for the collection filters to update
await awaitRunningJobs(adminClient);
const result = await doAdminSearchQuery({ collectionId: 'T_2', groupByProduct: true });
const result1 = await doAdminSearchQuery({ collectionId: 'T_2', groupByProduct: true });

expect(result.search.items.map(i => i.productName)).toEqual([
expect(result1.search.items.map(i => i.productName)).toEqual([
'Road Bike',
'Skipping Rope',
'Boxing Gloves',
'Tent',
'Cruiser Skateboard',
'Football',
'Running Shoe',
]);

const result2 = await doAdminSearchQuery({ collectionSlug: 'plants', groupByProduct: true });

expect(result2.search.items.map(i => i.productName)).toEqual([
'Road Bike',
'Skipping Rope',
'Boxing Gloves',
Expand Down
83 changes: 42 additions & 41 deletions packages/core/e2e/graphql/generated-e2e-admin-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3170,6 +3170,7 @@ export type SearchInput = {
facetValueIds?: Maybe<Array<Scalars['ID']>>;
facetValueOperator?: Maybe<LogicalOperator>;
collectionId?: Maybe<Scalars['ID']>;
collectionSlug?: Maybe<Scalars['String']>;
groupByProduct?: Maybe<Scalars['Boolean']>;
take?: Maybe<Scalars['Int']>;
skip?: Maybe<Scalars['Int']>;
Expand Down Expand Up @@ -4019,20 +4020,6 @@ export type CreateCountryMutation = { __typename?: 'Mutation' } & {
createCountry: { __typename?: 'Country' } & CountryFragment;
};

export type CustomerGroupFragment = { __typename?: 'CustomerGroup' } & Pick<CustomerGroup, 'id' | 'name'> & {
customers: { __typename?: 'CustomerList' } & Pick<CustomerList, 'totalItems'> & {
items: Array<{ __typename?: 'Customer' } & Pick<Customer, 'id'>>;
};
};

export type CreateCustomerGroupMutationVariables = {
input: CreateCustomerGroupInput;
};

export type CreateCustomerGroupMutation = { __typename?: 'Mutation' } & {
createCustomerGroup: { __typename?: 'CustomerGroup' } & CustomerGroupFragment;
};

export type UpdateCustomerGroupMutationVariables = {
input: UpdateCustomerGroupInput;
};
Expand Down Expand Up @@ -4083,15 +4070,6 @@ export type AddCustomersToGroupMutation = { __typename?: 'Mutation' } & {
addCustomersToGroup: { __typename?: 'CustomerGroup' } & CustomerGroupFragment;
};

export type RemoveCustomersFromGroupMutationVariables = {
groupId: Scalars['ID'];
customerIds: Array<Scalars['ID']>;
};

export type RemoveCustomersFromGroupMutation = { __typename?: 'Mutation' } & {
removeCustomersFromGroup: { __typename?: 'CustomerGroup' } & CustomerGroupFragment;
};

export type GetCustomerWithGroupsQueryVariables = {
id: Scalars['ID'];
};
Expand Down Expand Up @@ -5078,6 +5056,29 @@ export type GetOrderQuery = { __typename?: 'Query' } & {
order?: Maybe<{ __typename?: 'Order' } & OrderWithLinesFragment>;
};

export type CustomerGroupFragment = { __typename?: 'CustomerGroup' } & Pick<CustomerGroup, 'id' | 'name'> & {
customers: { __typename?: 'CustomerList' } & Pick<CustomerList, 'totalItems'> & {
items: Array<{ __typename?: 'Customer' } & Pick<Customer, 'id'>>;
};
};

export type CreateCustomerGroupMutationVariables = {
input: CreateCustomerGroupInput;
};

export type CreateCustomerGroupMutation = { __typename?: 'Mutation' } & {
createCustomerGroup: { __typename?: 'CustomerGroup' } & CustomerGroupFragment;
};

export type RemoveCustomersFromGroupMutationVariables = {
groupId: Scalars['ID'];
customerIds: Array<Scalars['ID']>;
};

export type RemoveCustomersFromGroupMutation = { __typename?: 'Mutation' } & {
removeCustomersFromGroup: { __typename?: 'CustomerGroup' } & CustomerGroupFragment;
};

export type UpdateOptionGroupMutationVariables = {
input: UpdateProductOptionGroupInput;
};
Expand Down Expand Up @@ -6082,18 +6083,6 @@ export namespace CreateCountry {
export type CreateCountry = CountryFragment;
}

export namespace CustomerGroup {
export type Fragment = CustomerGroupFragment;
export type Customers = CustomerGroupFragment['customers'];
export type Items = NonNullable<CustomerGroupFragment['customers']['items'][0]>;
}

export namespace CreateCustomerGroup {
export type Variables = CreateCustomerGroupMutationVariables;
export type Mutation = CreateCustomerGroupMutation;
export type CreateCustomerGroup = CustomerGroupFragment;
}

export namespace UpdateCustomerGroup {
export type Variables = UpdateCustomerGroupMutationVariables;
export type Mutation = UpdateCustomerGroupMutation;
Expand Down Expand Up @@ -6129,12 +6118,6 @@ export namespace AddCustomersToGroup {
export type AddCustomersToGroup = CustomerGroupFragment;
}

export namespace RemoveCustomersFromGroup {
export type Variables = RemoveCustomersFromGroupMutationVariables;
export type Mutation = RemoveCustomersFromGroupMutation;
export type RemoveCustomersFromGroup = CustomerGroupFragment;
}

export namespace GetCustomerWithGroups {
export type Variables = GetCustomerWithGroupsQueryVariables;
export type Query = GetCustomerWithGroupsQuery;
Expand Down Expand Up @@ -6767,6 +6750,24 @@ export namespace GetOrder {
export type Order = OrderWithLinesFragment;
}

export namespace CustomerGroup {
export type Fragment = CustomerGroupFragment;
export type Customers = CustomerGroupFragment['customers'];
export type Items = NonNullable<CustomerGroupFragment['customers']['items'][0]>;
}

export namespace CreateCustomerGroup {
export type Variables = CreateCustomerGroupMutationVariables;
export type Mutation = CreateCustomerGroupMutation;
export type CreateCustomerGroup = CustomerGroupFragment;
}

export namespace RemoveCustomersFromGroup {
export type Variables = RemoveCustomersFromGroupMutationVariables;
export type Mutation = RemoveCustomersFromGroupMutation;
export type RemoveCustomersFromGroup = CustomerGroupFragment;
}

export namespace UpdateOptionGroup {
export type Variables = UpdateOptionGroupMutationVariables;
export type Mutation = UpdateOptionGroupMutation;
Expand Down
1 change: 1 addition & 0 deletions packages/core/e2e/graphql/generated-e2e-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,7 @@ export type SearchInput = {
facetValueIds?: Maybe<Array<Scalars['ID']>>;
facetValueOperator?: Maybe<LogicalOperator>;
collectionId?: Maybe<Scalars['ID']>;
collectionSlug?: Maybe<Scalars['String']>;
groupByProduct?: Maybe<Scalars['Boolean']>;
take?: Maybe<Scalars['Int']>;
skip?: Maybe<Scalars['Int']>;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/api/schema/common/common-types.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ input SearchInput {
facetValueIds: [ID!]
facetValueOperator: LogicalOperator
collectionId: ID
collectionSlug: String
groupByProduct: Boolean
take: Int
skip: Int
Expand Down
Loading

0 comments on commit a4cbdbb

Please sign in to comment.