From 79b1b5d7e694b9de0f64ce3258e84221976ebac1 Mon Sep 17 00:00:00 2001 From: Matiss Janis Aboltins Date: Tue, 10 Dec 2024 19:25:07 +0000 Subject: [PATCH] :bug: fix wrapping content causing failures --- .../calculate-building-id.js | 6 ++++++ .../calculate-building-id.test.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/mutations/calculate-building-id/calculate-building-id.js b/src/mutations/calculate-building-id/calculate-building-id.js index caab14c..49bdb45 100644 --- a/src/mutations/calculate-building-id/calculate-building-id.js +++ b/src/mutations/calculate-building-id/calculate-building-id.js @@ -6,6 +6,12 @@ async function calculateBuildingId(parent, input, context) { const data = { ...input, images: JSON.stringify(input.images), + building_material: input.building_material?.trim(), + building_project: input.building_project?.trim(), + location_address: input.location_address?.trim(), + location_district: input.location_district?.trim(), + location_parish: input.location_parish?.trim(), + cadastre_number: input.cadastre_number?.trim(), }; const addr = normalizeAddress(data); diff --git a/src/mutations/calculate-building-id/calculate-building-id.test.js b/src/mutations/calculate-building-id/calculate-building-id.test.js index 08278f4..666b876 100644 --- a/src/mutations/calculate-building-id/calculate-building-id.test.js +++ b/src/mutations/calculate-building-id/calculate-building-id.test.js @@ -82,4 +82,20 @@ describe('calculateBuildingId', () => { expect(output).toEqual(123); }); + + test('trims the cadastre_number field before inserting', async () => { + await calculateBuildingId( + {}, + { ...mockInput, cadastre_number: '\n\t\t\t\t\t\t123\n\t\t\t\t\t\t' }, + { + dataSources, + }, + ); + + expect(dataSources.userClassifieds.create).toHaveBeenCalledWith( + expect.objectContaining({ + cadastre_number: '123', + }), + ); + }); });