Skip to content

Commit

Permalink
refactor: Clean up todos in search plugin e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Oct 11, 2021
1 parent 65add05 commit 705bf08
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 74 deletions.
73 changes: 35 additions & 38 deletions packages/core/e2e/default-search-plugin.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ import { awaitRunningJobs } from './utils/await-running-jobs';
// on the default of 5s.
jest.setTimeout(10000);

interface SearchProductShopVariables extends SearchProductsShop.Variables {
input: SearchProductsShop.Variables['input'] & {
// This input field is dynamically added only when the `indexStockStatus` init option
// is set to `true`, and therefore not included in the generated type. Therefore
// we need to manually patch it here.
inStock?: boolean;
};
}

describe('Default search plugin', () => {
const { server, adminClient, shopClient } = createTestEnvironment(
mergeConfig(testConfig, {
Expand Down Expand Up @@ -99,13 +108,13 @@ describe('Default search plugin', () => {
});

function doAdminSearchQuery(input: SearchInput) {
return adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(SEARCH_PRODUCTS, {
return adminClient.query<SearchProductsShop.Query, SearchProductShopVariables>(SEARCH_PRODUCTS, {
input,
});
}

async function testGroupByProduct(client: SimpleGraphQLClient) {
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand All @@ -117,7 +126,7 @@ describe('Default search plugin', () => {
}

async function testNoGrouping(client: SimpleGraphQLClient) {
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand All @@ -132,7 +141,7 @@ describe('Default search plugin', () => {
client: SimpleGraphQLClient,
sortBy: keyof SearchResultSortParameter,
) {
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand All @@ -155,7 +164,7 @@ describe('Default search plugin', () => {
client: SimpleGraphQLClient,
sortBy: keyof SearchResultSortParameter,
) {
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand All @@ -175,7 +184,7 @@ describe('Default search plugin', () => {
}

async function testMatchSearchTerm(client: SimpleGraphQLClient) {
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand All @@ -195,7 +204,7 @@ describe('Default search plugin', () => {
}

async function testMatchFacetIdsAnd(client: SimpleGraphQLClient) {
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand All @@ -216,7 +225,7 @@ describe('Default search plugin', () => {
}

async function testMatchFacetIdsOr(client: SimpleGraphQLClient) {
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand Down Expand Up @@ -244,7 +253,7 @@ describe('Default search plugin', () => {
}

async function testMatchFacetValueFiltersAnd(client: SimpleGraphQLClient) {
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand All @@ -264,7 +273,7 @@ describe('Default search plugin', () => {
}

async function testMatchFacetValueFiltersOr(client: SimpleGraphQLClient) {
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand All @@ -291,7 +300,7 @@ describe('Default search plugin', () => {
}

async function testMatchFacetValueFiltersOrWithAnd(client: SimpleGraphQLClient) {
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand All @@ -315,7 +324,7 @@ describe('Default search plugin', () => {
}

async function testMatchFacetValueFiltersWithFacetIdsOr(client: SimpleGraphQLClient) {
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand All @@ -341,7 +350,7 @@ describe('Default search plugin', () => {
}

async function testMatchFacetValueFiltersWithFacetIdsAnd(client: SimpleGraphQLClient) {
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand All @@ -361,7 +370,7 @@ describe('Default search plugin', () => {
}

async function testMatchCollectionId(client: SimpleGraphQLClient) {
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand All @@ -378,7 +387,7 @@ describe('Default search plugin', () => {
}

async function testMatchCollectionSlug(client: SimpleGraphQLClient) {
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand Down Expand Up @@ -589,7 +598,7 @@ describe('Default search plugin', () => {
});

it('encodes the productId and productVariantId', async () => {
const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand Down Expand Up @@ -620,7 +629,7 @@ describe('Default search plugin', () => {
},
);
await awaitRunningJobs(adminClient);
const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand All @@ -633,7 +642,7 @@ describe('Default search plugin', () => {
});

it('encodes collectionIds', async () => {
const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
Expand All @@ -648,13 +657,11 @@ describe('Default search plugin', () => {
});

it('inStock is false and not grouped by product', async () => {
// ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
groupByProduct: false,
// @ts-ignore
inStock: false,
},
},
Expand All @@ -663,13 +670,11 @@ describe('Default search plugin', () => {
});

it('inStock is false and grouped by product', async () => {
// ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
groupByProduct: true,
// @ts-ignore
inStock: false,
},
},
Expand All @@ -678,13 +683,11 @@ describe('Default search plugin', () => {
});

it('inStock is true and not grouped by product', async () => {
// ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
groupByProduct: false,
// @ts-ignore
inStock: true,
},
},
Expand All @@ -693,13 +696,11 @@ describe('Default search plugin', () => {
});

it('inStock is true and grouped by product', async () => {
// ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
groupByProduct: true,
// @ts-ignore
inStock: true,
},
},
Expand All @@ -708,13 +709,11 @@ describe('Default search plugin', () => {
});

it('inStock is undefined and not grouped by product', async () => {
// ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
groupByProduct: false,
// @ts-ignore
inStock: undefined,
},
},
Expand All @@ -723,13 +722,11 @@ describe('Default search plugin', () => {
});

it('inStock is undefined and grouped by product', async () => {
// ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS_SHOP,
{
input: {
groupByProduct: true,
// @ts-ignore
inStock: undefined,
},
},
Expand Down Expand Up @@ -1445,7 +1442,7 @@ describe('Default search plugin', () => {
adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
const { search } = await adminClient.query<
SearchProductsShop.Query,
SearchProductsShop.Variables
SearchProductShopVariables
>(
SEARCH_PRODUCTS,
{
Expand Down Expand Up @@ -1478,7 +1475,7 @@ describe('Default search plugin', () => {

describe('multiple language handling', () => {
function searchInLanguage(languageCode: LanguageCode) {
return adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
return adminClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
SEARCH_PRODUCTS,
{
input: {
Expand Down
15 changes: 8 additions & 7 deletions packages/dev-server/dev-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AdminUiPlugin } from '@vendure/admin-ui-plugin';
import { AssetServerPlugin } from '@vendure/asset-server-plugin';
import { ADMIN_API_PATH, API_PORT, SHOP_API_PATH } from '@vendure/common/lib/shared-constants';
import {
DefaultJobQueuePlugin,
DefaultLogger,
DefaultSearchPlugin,
dummyPaymentHandler,
Expand Down Expand Up @@ -65,15 +66,15 @@ export const devConfig: VendureConfig = {
route: 'assets',
assetUploadDir: path.join(__dirname, 'assets'),
}),
// DefaultSearchPlugin.init({ bufferUpdates: true }),
DefaultSearchPlugin.init({ bufferUpdates: true, indexStockStatus: false }),
BullMQJobQueuePlugin.init({}),
// DefaultJobQueuePlugin,
// DefaultJobQueuePlugin.init(),
// JobQueueTestPlugin.init({ queueCount: 10 }),
ElasticsearchPlugin.init({
host: 'http://localhost',
port: 9200,
bufferUpdates: true,
}),
// ElasticsearchPlugin.init({
// host: 'http://localhost',
// port: 9200,
// bufferUpdates: true,
// }),
EmailPlugin.init({
devMode: true,
route: 'mailbox',
Expand Down
Loading

0 comments on commit 705bf08

Please sign in to comment.