Skip to content

Commit

Permalink
test(core): Add tests for #2013
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Aug 7, 2023
1 parent bdab886 commit 5691f81
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion packages/core/e2e/entity-hydrator.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { mergeConfig, Order, Product, ProductVariant } from '@vendure/core';
import {
ChannelService,
EntityHydrator,
mergeConfig,
Order,
Product,
ProductVariant,
RequestContext,
ActiveOrderService,
} from '@vendure/core';
import { createErrorResultGuard, createTestEnvironment, ErrorResultGuard } from '@vendure/testing';
import gql from 'graphql-tag';
import path from 'path';
Expand All @@ -11,6 +20,7 @@ import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-conf
import { HydrationTestPlugin } from './fixtures/test-plugins/hydration-test-plugin';
import { UpdateChannelMutation, UpdateChannelMutationVariables } from './graphql/generated-e2e-admin-types';
import {
AddItemToOrderDocument,
AddItemToOrderMutation,
AddItemToOrderMutationVariables,
UpdatedOrderFragment,
Expand Down Expand Up @@ -225,6 +235,60 @@ describe('Entity hydration', () => {
expect(hydrateChannel.customFields.thumb).toBeDefined();
expect(hydrateChannel.customFields.thumb.id).toBe('T_2');
});

// https://github.com/vendure-ecommerce/vendure/issues/2013
describe('hydration of OrderLine ProductVariantPrices', () => {
let order: Order | undefined;

it('Create order with 3 items', async () => {
await shopClient.asUserWithCredentials('hayden.zieme12@hotmail.com', 'test');
await shopClient.query(AddItemToOrderDocument, {
productVariantId: '1',
quantity: 1,
});
await shopClient.query(AddItemToOrderDocument, {
productVariantId: '2',
quantity: 1,
});
const { addItemToOrder } = await shopClient.query(AddItemToOrderDocument, {
productVariantId: '3',
quantity: 1,
});
orderResultGuard.assertSuccess(addItemToOrder);
const channel = await server.app.get(ChannelService).getDefaultChannel();
// This is ugly, but in our real life example we use a CTX constructed by Vendure
const ctx = new RequestContext({
channel,
authorizedAsOwnerOnly: true,
apiType: 'shop',
isAuthorized: true,
session: {
activeOrderId: addItemToOrder.id,
activeChannelId: 1,
user: {
id: 2,
},
} as any,
});
order = await server.app.get(ActiveOrderService).getActiveOrder(ctx, undefined);
await server.app.get(EntityHydrator).hydrate(ctx, order!, {
relations: ['lines.productVariant'],
applyProductVariantPrices: true,
});
});

it('Variant of orderLine 1 has a price', async () => {
expect(order!.lines[0].productVariant.priceWithTax).toBeGreaterThan(0);
});

it('Variant of orderLine 2 has a price', async () => {
expect(order!.lines[1].productVariant.priceWithTax).toBeGreaterThan(0);
});

it('Variant of orderLine 3 has a price', async () => {
expect(order!.lines[1].productVariant.priceWithTax).toBeGreaterThan(0);
});
});
});

function getVariantWithName(product: Product, name: string) {
Expand Down

0 comments on commit 5691f81

Please sign in to comment.