|
|
@@ -4,6 +4,7 @@ import { pick } from '@vendure/common/lib/pick';
|
|
|
import {
|
|
|
DefaultJobQueuePlugin,
|
|
|
DefaultLogger,
|
|
|
+ FacetValue,
|
|
|
facetValueCollectionFilter,
|
|
|
LogLevel,
|
|
|
mergeConfig,
|
|
|
@@ -39,6 +40,8 @@ import {
|
|
|
UpdateCollection,
|
|
|
UpdateProduct,
|
|
|
UpdateProductVariants,
|
|
|
+ UpdateProductVariantsMutation,
|
|
|
+ UpdateProductVariantsMutationVariables,
|
|
|
UpdateTaxRate,
|
|
|
} from '../../core/e2e/graphql/generated-e2e-admin-types';
|
|
|
import { SearchProductsShop } from '../../core/e2e/graphql/generated-e2e-shop-types';
|
|
|
@@ -115,11 +118,21 @@ const INDEX_PREFIX = 'e2e-tests';
|
|
|
describe('Elasticsearch plugin', () => {
|
|
|
const { server, adminClient, shopClient } = createTestEnvironment(
|
|
|
mergeConfig(testConfig(), {
|
|
|
+ customFields: {
|
|
|
+ ProductVariant: [
|
|
|
+ {
|
|
|
+ name: 'material',
|
|
|
+ type: 'relation',
|
|
|
+ entity: FacetValue,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
plugins: [
|
|
|
ElasticsearchPlugin.init({
|
|
|
indexPrefix: INDEX_PREFIX,
|
|
|
port: elasticsearchPort,
|
|
|
host: elasticsearchHost,
|
|
|
+ hydrateProductVariantRelations: ['customFields.material'],
|
|
|
customProductVariantMappings: {
|
|
|
inStock: {
|
|
|
graphQlType: 'Boolean!',
|
|
|
@@ -127,6 +140,19 @@ describe('Elasticsearch plugin', () => {
|
|
|
return variant.stockOnHand > 0;
|
|
|
},
|
|
|
},
|
|
|
+ materialCode: {
|
|
|
+ graphQlType: 'String!',
|
|
|
+ valueFn: variant => {
|
|
|
+ const materialFacetValue: FacetValue | undefined = (
|
|
|
+ variant.customFields as any
|
|
|
+ ).material;
|
|
|
+ let result = '';
|
|
|
+ if (materialFacetValue) {
|
|
|
+ result = `${materialFacetValue.code}`;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ },
|
|
|
+ },
|
|
|
},
|
|
|
customProductMappings: {
|
|
|
answer: {
|
|
|
@@ -1347,6 +1373,43 @@ describe('Elasticsearch plugin', () => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+ // https://github.com/vendure-ecommerce/vendure/issues/1638
|
|
|
+ it('hydrates variant custom field relation', async () => {
|
|
|
+ const { updateProductVariants } = await adminClient.query<
|
|
|
+ UpdateProductVariantsMutation,
|
|
|
+ UpdateProductVariantsMutationVariables
|
|
|
+ >(UPDATE_PRODUCT_VARIANTS, {
|
|
|
+ input: [
|
|
|
+ {
|
|
|
+ id: 'T_20',
|
|
|
+ customFields: {
|
|
|
+ materialId: 'T_1',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ });
|
|
|
+ expect(updateProductVariants[0]!.id).toBe('T_20');
|
|
|
+
|
|
|
+ await adminClient.query<Reindex.Mutation>(REINDEX);
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
+ const query = `{
|
|
|
+ search(input: { groupByProduct: false, term: "tripod" }) {
|
|
|
+ items {
|
|
|
+ productVariantName
|
|
|
+ productVariantId
|
|
|
+ customMappings {
|
|
|
+ ...on CustomProductVariantMappings {
|
|
|
+ materialCode
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }`;
|
|
|
+ const { search } = await shopClient.query(gql(query));
|
|
|
+
|
|
|
+ expect(search.items.map((i: any) => i.customMappings)).toEqual([{ materialCode: 'electronics' }]);
|
|
|
+ });
|
|
|
+
|
|
|
it('product mappings', async () => {
|
|
|
const query = `{
|
|
|
search(input: { take: 1, groupByProduct: true, sort: { name: ASC } }) {
|