|
|
@@ -8,6 +8,10 @@ import {
|
|
|
ProductVariant,
|
|
|
RequestContext,
|
|
|
ActiveOrderService,
|
|
|
+ OrderService,
|
|
|
+ TransactionalConnection,
|
|
|
+ OrderLine,
|
|
|
+ RequestContextService,
|
|
|
} from '@vendure/core';
|
|
|
import { createErrorResultGuard, createTestEnvironment, ErrorResultGuard } from '@vendure/testing';
|
|
|
import gql from 'graphql-tag';
|
|
|
@@ -43,7 +47,7 @@ describe('Entity hydration', () => {
|
|
|
await server.init({
|
|
|
initialData,
|
|
|
productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-full.csv'),
|
|
|
- customerCount: 1,
|
|
|
+ customerCount: 2,
|
|
|
});
|
|
|
await adminClient.asSuperAdmin();
|
|
|
}, TEST_SETUP_TIMEOUT_MS);
|
|
|
@@ -290,6 +294,46 @@ describe('Entity hydration', () => {
|
|
|
expect(order!.lines[1].productVariant.priceWithTax).toBeGreaterThan(0);
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+ // https://github.com/vendure-ecommerce/vendure/issues/2546
|
|
|
+ it('Preserves ordering when merging arrays of relations', async () => {
|
|
|
+ await shopClient.asUserWithCredentials('trevor_donnelly96@hotmail.com', 'test');
|
|
|
+ await shopClient.query(AddItemToOrderDocument, {
|
|
|
+ productVariantId: '1',
|
|
|
+ quantity: 1,
|
|
|
+ });
|
|
|
+ const { addItemToOrder } = await shopClient.query(AddItemToOrderDocument, {
|
|
|
+ productVariantId: '2',
|
|
|
+ quantity: 2,
|
|
|
+ });
|
|
|
+ orderResultGuard.assertSuccess(addItemToOrder);
|
|
|
+ const internalOrderId = +addItemToOrder.id.replace(/^\D+/g, '');
|
|
|
+ const ctx = await server.app.get(RequestContextService).create({ apiType: 'admin' });
|
|
|
+ const order = await server.app
|
|
|
+ .get(OrderService)
|
|
|
+ .findOne(ctx, internalOrderId, ['lines.productVariant']);
|
|
|
+
|
|
|
+ for (const line of order?.lines ?? []) {
|
|
|
+ // Assert that things are as we expect before hydrating
|
|
|
+ expect(line.productVariantId).toBe(line.productVariant.id);
|
|
|
+ }
|
|
|
+
|
|
|
+ // modify the first order line to make postgres tend to return the lines in the wrong order
|
|
|
+ await server.app
|
|
|
+ .get(TransactionalConnection)
|
|
|
+ .getRepository(ctx, OrderLine)
|
|
|
+ .update(order!.lines[0].id, {
|
|
|
+ sellerChannelId: 1,
|
|
|
+ });
|
|
|
+
|
|
|
+ await server.app.get(EntityHydrator).hydrate(ctx, order!, {
|
|
|
+ relations: ['lines.sellerChannel'],
|
|
|
+ });
|
|
|
+
|
|
|
+ for (const line of order?.lines ?? []) {
|
|
|
+ expect(line.productVariantId).toBe(line.productVariant.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
function getVariantWithName(product: Product, name: string) {
|