From b783dd0d1d9e670dd69956b6cdedc6fca54f8689 Mon Sep 17 00:00:00 2001 From: Arno Erpenbeck <88486704+arnoerpenbeck@users.noreply.github.com> Date: Fri, 3 May 2024 14:49:26 +0200 Subject: [PATCH] fix(CTC-135): do not create order with empty tags array --- event/src/order/orderMapper.ts | 8 ++++++-- event/tests/orderMapper.test.ts | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/event/src/order/orderMapper.ts b/event/src/order/orderMapper.ts index 13ade7c..a851600 100644 --- a/event/src/order/orderMapper.ts +++ b/event/src/order/orderMapper.ts @@ -19,7 +19,7 @@ export class OrderMapper { public async mapOrder(commercetoolsOrder: CommercetoolsOrder): Promise { const configuration = await getConfiguration(); - return { + const order: FulfillmenttoolsOrder = { tenantOrderId: commercetoolsOrder.orderNumber || commercetoolsOrder.id, consumer: this.mapConsumer(commercetoolsOrder), orderDate: new Date(commercetoolsOrder.createdAt), @@ -31,8 +31,12 @@ export class OrderMapper { paymentInfo: { currency: commercetoolsOrder.totalPrice.currencyCode, }, - tags: this.mapTags(commercetoolsOrder, configuration), }; + const tags = this.mapTags(commercetoolsOrder, configuration); + if (tags && tags.length > 0) { + order.tags = tags; + } + return order; } private async getPreselectedFacilities(commercetoolsOrder: CommercetoolsOrder): Promise { diff --git a/event/tests/orderMapper.test.ts b/event/tests/orderMapper.test.ts index b6eb361..fb6433e 100644 --- a/event/tests/orderMapper.test.ts +++ b/event/tests/orderMapper.test.ts @@ -54,6 +54,7 @@ describe('OrderMapper', () => { expect(article.title).toEqual('Cigköfte Wrap'); expect(article.imageUrl).toEqual('https://fancy-image.example.com'); expect(fulfillmenttoolsOrder.tenantOrderId).toEqual('orderNumber'); + expect(fulfillmenttoolsOrder.tags).toBeUndefined(); }); it('defaults to id if orderNumber is undefined', async () => {