Skip to content

Commit

Permalink
fix(core): Do not error when querying fulfillment on empty order
Browse files Browse the repository at this point in the history
Fixes #639
michaelbromley committed Jan 13, 2021
1 parent 7c372c2 commit b0c0457
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/core/e2e/order.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -54,6 +54,7 @@ import {
} from './graphql/generated-e2e-admin-types';
import {
AddItemToOrder,
ApplyCouponCode,
DeletionResult,
GetActiveOrder,
GetOrderByCodeWithPayments,
@@ -76,6 +77,7 @@ import {
} from './graphql/shared-definitions';
import {
ADD_ITEM_TO_ORDER,
APPLY_COUPON_CODE,
GET_ACTIVE_ORDER,
GET_ORDER_BY_CODE_WITH_PAYMENTS,
} from './graphql/shop-definitions';
@@ -340,6 +342,23 @@ describe('Orders resolver', () => {
let f2Id: string;
let f3Id: string;

// https://github.com/vendure-ecommerce/vendure/issues/639
it('returns fulfillments for Order with no lines', async () => {
// Apply a coupon code just to create an active order with no OrderLines
await shopClient.query<ApplyCouponCode.Mutation, ApplyCouponCode.Variables>(APPLY_COUPON_CODE, {
couponCode: 'TEST',
});
const { activeOrder } = await shopClient.query<GetActiveOrder.Query>(GET_ACTIVE_ORDER);
const { order } = await adminClient.query<
GetOrderFulfillments.Query,
GetOrderFulfillments.Variables
>(GET_ORDER_FULFILLMENTS, {
id: activeOrder!.id,
});

expect(order?.fulfillments).toEqual([]);
});

it('return error result if lines is empty', async () => {
const { order } = await adminClient.query<GetOrder.Query, GetOrder.Variables>(GET_ORDER, {
id: orderId,
2 changes: 1 addition & 1 deletion packages/core/src/service/services/order.service.ts
Original file line number Diff line number Diff line change
@@ -906,7 +906,7 @@ export class OrderService {

async getOrderFulfillments(ctx: RequestContext, order: Order): Promise<Fulfillment[]> {
let lines: OrderLine[];
if (order.lines?.[0].items?.[0]?.fulfillments !== undefined) {
if (order.lines?.[0]?.items?.[0]?.fulfillments !== undefined) {
lines = order.lines;
} else {
lines = await this.connection.getRepository(ctx, OrderLine).find({

0 comments on commit b0c0457

Please sign in to comment.