-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Fix entity hydration postgres edge-case
Fixes #2546
- Loading branch information
1 parent
a9e67fe
commit 9546d1b
Showing
2 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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('[email protected]', '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) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters