From a8259268cf649aa3dc5018c8454916334c1210e6 Mon Sep 17 00:00:00 2001 From: Sai Sankeerth Date: Thu, 9 Nov 2023 17:46:07 +0530 Subject: [PATCH] fix: name of the returned object & name of the function Signed-off-by: Sai Sankeerth --- src/helpers/geoLocation.ts | 18 +++++++++++------- src/middlewares/enricher.ts | 2 +- test/helper/helper.test.ts | 22 +++++++++++----------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/helpers/geoLocation.ts b/src/helpers/geoLocation.ts index 94b4420be5..eb010ea3b9 100644 --- a/src/helpers/geoLocation.ts +++ b/src/helpers/geoLocation.ts @@ -7,24 +7,28 @@ import * as GenericFieldMappingJson from '../v0/util/data/GenericFieldMapping.js export default class GeoLocationHelper { public static getAddressKeyAndValue(message: Record): { - addressKey: string; - address: Record; + key: string; + value: Record; } { - const { value: address, key: foundKey } = - getFirstMatchingKeyAndValue(message, GenericFieldMappingJson.address) || {}; + const { value, key: foundKey } = getFirstMatchingKeyAndValue( + message, + GenericFieldMappingJson.address, + ); const { key: traitsKey } = getFirstMatchingKeyAndValue(message, GenericFieldMappingJson.traits); const addressKey = foundKey || (traitsKey ? `${traitsKey}.address` : GenericFieldMappingJson.address[0]); - return { addressKey, address }; + return { key: addressKey, value }; } - public static getGeoLocationData(message: Record): Record { + public static getMessageWithGeoLocationData( + message: Record, + ): Record { const msg = cloneDeep(message || {}); if (isEmpty(msg?.context?.geo || {})) { // geo-location data was not sent return {}; } - const { address, addressKey } = GeoLocationHelper.getAddressKeyAndValue(message); + const { value: address, key: addressKey } = GeoLocationHelper.getAddressKeyAndValue(message); const addressFieldMapping = { city: 'city', country: 'country', diff --git a/src/middlewares/enricher.ts b/src/middlewares/enricher.ts index 0b84b19ab0..53f05dcd68 100644 --- a/src/middlewares/enricher.ts +++ b/src/middlewares/enricher.ts @@ -13,7 +13,7 @@ export default class Enricher { data: RouterTransformationRequestData[], ): RouterTransformationRequestData[] { return data.map((inpEv) => { - const geoEnrichedMessage = GeoLocationHelper.getGeoLocationData(inpEv.message); + const geoEnrichedMessage = GeoLocationHelper.getMessageWithGeoLocationData(inpEv.message); return { ...inpEv, message: { diff --git a/test/helper/helper.test.ts b/test/helper/helper.test.ts index 1677f1e5b7..16c80bdfa7 100644 --- a/test/helper/helper.test.ts +++ b/test/helper/helper.test.ts @@ -59,7 +59,7 @@ describe('GeoLocationHelper tests', () => { userId: 'abcd-124', }; - const enhancedMsg = GeoLocationHelper.getGeoLocationData(msg); + const enhancedMsg = GeoLocationHelper.getMessageWithGeoLocationData(msg); expect(enhancedMsg.context.traits.address).not.toBe(undefined); expect(enhancedMsg.context.traits.address).toEqual({ @@ -126,7 +126,7 @@ describe('GeoLocationHelper tests', () => { userId: 'abcd-124', }; - const enhancedMsg = GeoLocationHelper.getGeoLocationData(msg); + const enhancedMsg = GeoLocationHelper.getMessageWithGeoLocationData(msg); expect(enhancedMsg.context.traits.address).not.toBe(undefined); expect(enhancedMsg.context.traits.address).toEqual({ @@ -199,7 +199,7 @@ describe('GeoLocationHelper tests', () => { userId: 'abcd-124', }; - const enhancedMsg = GeoLocationHelper.getGeoLocationData(msg); + const enhancedMsg = GeoLocationHelper.getMessageWithGeoLocationData(msg); expect(enhancedMsg.traits.address).not.toBe(undefined); expect(enhancedMsg.traits.address).toEqual({ @@ -276,7 +276,7 @@ describe('GeoLocationHelper tests', () => { userId: 'abcd-124', }; - const enhancedMsg = GeoLocationHelper.getGeoLocationData(msg); + const enhancedMsg = GeoLocationHelper.getMessageWithGeoLocationData(msg); expect(enhancedMsg.traits.address).not.toBe(undefined); expect(enhancedMsg.traits.address).toEqual({ @@ -351,7 +351,7 @@ describe('GeoLocationHelper tests', () => { userId: 'abcd-124', }; - const enhancedMsg = GeoLocationHelper.getGeoLocationData(msg); + const enhancedMsg = GeoLocationHelper.getMessageWithGeoLocationData(msg); expect(enhancedMsg.traits.address).not.toBe(undefined); expect(enhancedMsg.traits.address).toEqual({ @@ -408,7 +408,7 @@ describe('GeoLocationHelper tests', () => { userId: 'abcd-124', }; - const enhancedMsg = GeoLocationHelper.getGeoLocationData(msg); + const enhancedMsg = GeoLocationHelper.getMessageWithGeoLocationData(msg); expect(enhancedMsg).toEqual({}); }); @@ -416,7 +416,7 @@ describe('GeoLocationHelper tests', () => { describe('get addressKey & address tests', () => { test('addressKey should be "traits.address", when address is not present but traits object is present', () => { - const { addressKey } = GeoLocationHelper.getAddressKeyAndValue({ + const { key: addressKey } = GeoLocationHelper.getAddressKeyAndValue({ traits: { name: 'Bruce Wayne', age: 35, @@ -427,7 +427,7 @@ describe('get addressKey & address tests', () => { }); test('addressKey should be "context.traits.address", when address is not present but traits object is present', () => { - const { addressKey } = GeoLocationHelper.getAddressKeyAndValue({ + const { key: addressKey } = GeoLocationHelper.getAddressKeyAndValue({ context: { traits: { name: 'Bruce Wayne', @@ -440,7 +440,7 @@ describe('get addressKey & address tests', () => { }); test('addressKey should be "traits.address", when traits object is not present at all', () => { - const { addressKey } = GeoLocationHelper.getAddressKeyAndValue({ + const { key: addressKey } = GeoLocationHelper.getAddressKeyAndValue({ anonymousId: '129893-2idi9292', originalTimestamp: '2020-04-17T14:42:44.722Z', receivedAt: '2020-04-17T20:12:44.758+05:30', @@ -465,7 +465,7 @@ describe('get addressKey & address tests', () => { }); test('addressKey should be "context.traits.address", when address is present in context.traits & address is not present in traits', () => { - const { addressKey } = GeoLocationHelper.getAddressKeyAndValue({ + const { key: addressKey } = GeoLocationHelper.getAddressKeyAndValue({ anonymousId: '129893-2idi9292', originalTimestamp: '2020-04-17T14:42:44.722Z', receivedAt: '2020-04-17T20:12:44.758+05:30', @@ -499,7 +499,7 @@ describe('get addressKey & address tests', () => { }); test('addressKey should be "traits.address", when empty payload is sent', () => { - const { addressKey } = GeoLocationHelper.getAddressKeyAndValue({}); + const { key: addressKey } = GeoLocationHelper.getAddressKeyAndValue({}); expect(addressKey).toEqual('traits.address'); }); });