|
|
@@ -32,7 +32,12 @@ import { initialData } from '../../../e2e-common/e2e-initial-data';
|
|
|
import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
|
|
|
|
|
|
import { testSuccessfulPaymentMethod } from './fixtures/test-payment-methods';
|
|
|
+import {
|
|
|
+ UpdateProductVariantsMutation,
|
|
|
+ UpdateProductVariantsMutationVariables,
|
|
|
+} from './graphql/generated-e2e-admin-types';
|
|
|
import { AddItemToOrder } from './graphql/generated-e2e-shop-types';
|
|
|
+import { UPDATE_PRODUCT_VARIANTS } from './graphql/shared-definitions';
|
|
|
import { ADD_ITEM_TO_ORDER } from './graphql/shop-definitions';
|
|
|
import { sortById } from './utils/test-order-utils';
|
|
|
|
|
|
@@ -123,6 +128,14 @@ customFieldConfig.User?.push({
|
|
|
internal: false,
|
|
|
public: true,
|
|
|
});
|
|
|
+customFieldConfig.ProductVariant?.push({
|
|
|
+ name: 'cfRelatedProducts',
|
|
|
+ type: 'relation',
|
|
|
+ entity: Product,
|
|
|
+ list: true,
|
|
|
+ internal: false,
|
|
|
+ public: true,
|
|
|
+});
|
|
|
|
|
|
const testResolverSpy = jest.fn();
|
|
|
|
|
|
@@ -856,6 +869,43 @@ describe('Custom field relations', () => {
|
|
|
expect(customer).toBeDefined();
|
|
|
});
|
|
|
|
|
|
+ // https://github.com/vendure-ecommerce/vendure/issues/1664
|
|
|
+ it('successfully gets product.variants with nested custom field relation', async () => {
|
|
|
+ await adminClient.query(gql`
|
|
|
+ mutation {
|
|
|
+ updateProductVariants(
|
|
|
+ input: [{ id: "T_1", customFields: { cfRelatedProductsIds: ["T_2"] } }]
|
|
|
+ ) {
|
|
|
+ id
|
|
|
+ }
|
|
|
+ }
|
|
|
+ `);
|
|
|
+
|
|
|
+ const { product } = await adminClient.query(gql`
|
|
|
+ query {
|
|
|
+ product(id: "T_1") {
|
|
|
+ variants {
|
|
|
+ id
|
|
|
+ customFields {
|
|
|
+ cfRelatedProducts {
|
|
|
+ featuredAsset {
|
|
|
+ id
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ `);
|
|
|
+
|
|
|
+ expect(product).toBeDefined();
|
|
|
+ expect(product.variants[0].customFields.cfRelatedProducts).toEqual([
|
|
|
+ {
|
|
|
+ featuredAsset: { id: 'T_2' },
|
|
|
+ },
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
it('successfully gets product by slug with eager-loading custom field relation', async () => {
|
|
|
const { product } = await shopClient.query(gql`
|
|
|
query {
|