|
|
@@ -1,10 +1,7 @@
|
|
|
-import { Args, Query, Resolver } from '@nestjs/graphql';
|
|
|
-import { ID } from '@vendure/common/lib/shared-types';
|
|
|
import {
|
|
|
Asset,
|
|
|
Collection,
|
|
|
Country,
|
|
|
- Ctx,
|
|
|
CustomFields,
|
|
|
defaultShippingCalculator,
|
|
|
defaultShippingEligibilityChecker,
|
|
|
@@ -12,32 +9,22 @@ import {
|
|
|
FacetValue,
|
|
|
manualFulfillmentHandler,
|
|
|
mergeConfig,
|
|
|
- PluginCommonModule,
|
|
|
Product,
|
|
|
ProductOption,
|
|
|
ProductOptionGroup,
|
|
|
ProductVariant,
|
|
|
- RequestContext,
|
|
|
ShippingMethod,
|
|
|
- TransactionalConnection,
|
|
|
- VendureEntity,
|
|
|
- VendurePlugin,
|
|
|
} from '@vendure/core';
|
|
|
import { createTestEnvironment } from '@vendure/testing';
|
|
|
import gql from 'graphql-tag';
|
|
|
import path from 'path';
|
|
|
-import { Entity, JoinColumn, OneToOne } from 'typeorm';
|
|
|
|
|
|
import { initialData } from '../../../e2e-common/e2e-initial-data';
|
|
|
-import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
|
|
|
+import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
|
|
|
|
|
|
import { testSuccessfulPaymentMethod } from './fixtures/test-payment-methods';
|
|
|
-import {
|
|
|
- UpdateProductVariantsMutation,
|
|
|
- UpdateProductVariantsMutationVariables,
|
|
|
-} from './graphql/generated-e2e-admin-types';
|
|
|
+import { TestPlugin1636_1664 } from './fixtures/test-plugins/issue-1636-1664/issue-1636-1664-plugin';
|
|
|
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';
|
|
|
|
|
|
@@ -79,17 +66,6 @@ const entitiesWithCustomFields = enumerate<keyof CustomFields>()(
|
|
|
'Zone',
|
|
|
);
|
|
|
|
|
|
-@Entity()
|
|
|
-class Vendor extends VendureEntity {
|
|
|
- constructor() {
|
|
|
- super();
|
|
|
- }
|
|
|
-
|
|
|
- @OneToOne(type => Product, { eager: true })
|
|
|
- @JoinColumn()
|
|
|
- featuredProduct: Product;
|
|
|
-}
|
|
|
-
|
|
|
const customFieldConfig: CustomFields = {};
|
|
|
for (const entity of entitiesWithCustomFields) {
|
|
|
customFieldConfig[entity] = [
|
|
|
@@ -108,26 +84,7 @@ customFieldConfig.Product?.push(
|
|
|
{ name: 'cfProduct', type: 'relation', entity: Product, list: false },
|
|
|
{ name: 'cfShippingMethod', type: 'relation', entity: ShippingMethod, list: false },
|
|
|
{ name: 'cfInternalAsset', type: 'relation', entity: Asset, list: false, internal: true },
|
|
|
- {
|
|
|
- name: 'cfVendor',
|
|
|
- type: 'relation',
|
|
|
- entity: Vendor,
|
|
|
- graphQLType: 'Vendor',
|
|
|
- list: false,
|
|
|
- internal: false,
|
|
|
- public: true,
|
|
|
- },
|
|
|
);
|
|
|
-customFieldConfig.User?.push({
|
|
|
- name: 'cfVendor',
|
|
|
- type: 'relation',
|
|
|
- entity: Vendor,
|
|
|
- graphQLType: 'Vendor',
|
|
|
- list: false,
|
|
|
- eager: true,
|
|
|
- internal: false,
|
|
|
- public: true,
|
|
|
-});
|
|
|
customFieldConfig.ProductVariant?.push({
|
|
|
name: 'cfRelatedProducts',
|
|
|
type: 'relation',
|
|
|
@@ -137,49 +94,6 @@ customFieldConfig.ProductVariant?.push({
|
|
|
public: true,
|
|
|
});
|
|
|
|
|
|
-const testResolverSpy = jest.fn();
|
|
|
-
|
|
|
-@Resolver()
|
|
|
-class TestResolver1636 {
|
|
|
- constructor(private connection: TransactionalConnection) {}
|
|
|
-
|
|
|
- @Query()
|
|
|
- async getAssetTest(@Ctx() ctx: RequestContext, @Args() args: { id: ID }) {
|
|
|
- const asset = await this.connection.findOneInChannel(ctx, Asset, args.id, ctx.channelId, {
|
|
|
- relations: ['customFields.single', 'customFields.multi'],
|
|
|
- });
|
|
|
- testResolverSpy(asset);
|
|
|
- return true;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-@VendurePlugin({
|
|
|
- imports: [PluginCommonModule],
|
|
|
- entities: [Vendor],
|
|
|
- shopApiExtensions: {
|
|
|
- schema: gql`
|
|
|
- extend type Query {
|
|
|
- getAssetTest(id: ID!): Boolean!
|
|
|
- }
|
|
|
- type Vendor {
|
|
|
- id: ID
|
|
|
- featuredProduct: Product
|
|
|
- }
|
|
|
- `,
|
|
|
- resolvers: [TestResolver1636],
|
|
|
- },
|
|
|
- adminApiExtensions: {
|
|
|
- schema: gql`
|
|
|
- type Vendor {
|
|
|
- id: ID
|
|
|
- featuredProduct: Product
|
|
|
- }
|
|
|
- `,
|
|
|
- resolvers: [],
|
|
|
- },
|
|
|
-})
|
|
|
-class TestPlugin1636 {}
|
|
|
-
|
|
|
const customConfig = mergeConfig(testConfig(), {
|
|
|
paymentOptions: {
|
|
|
paymentMethodHandlers: [testSuccessfulPaymentMethod],
|
|
|
@@ -189,7 +103,7 @@ const customConfig = mergeConfig(testConfig(), {
|
|
|
timezone: 'Z',
|
|
|
},
|
|
|
customFields: customFieldConfig,
|
|
|
- plugins: [TestPlugin1636],
|
|
|
+ plugins: [TestPlugin1636_1664],
|
|
|
});
|
|
|
|
|
|
describe('Custom field relations', () => {
|
|
|
@@ -1177,13 +1091,13 @@ describe('Custom field relations', () => {
|
|
|
|
|
|
// https://github.com/vendure-ecommerce/vendure/issues/1636
|
|
|
it('calling TransactionalConnection.findOneInChannel() returns custom field relations', async () => {
|
|
|
- testResolverSpy.mockReset();
|
|
|
+ TestPlugin1636_1664.testResolverSpy.mockReset();
|
|
|
await shopClient.query(gql`
|
|
|
query {
|
|
|
getAssetTest(id: "T_1")
|
|
|
}
|
|
|
`);
|
|
|
- const args = testResolverSpy.mock.calls[0];
|
|
|
+ const args = TestPlugin1636_1664.testResolverSpy.mock.calls[0];
|
|
|
expect(args[0].customFields.single.id).toEqual(2);
|
|
|
expect(args[0].customFields.multi.length).toEqual(2);
|
|
|
});
|