Skip to content

Commit

Permalink
fix: cloneDeep for all, add test-cases to reflect same referencing & …
Browse files Browse the repository at this point in the history
…null message cases

Signed-off-by: Sai Sankeerth <[email protected]>
  • Loading branch information
Sai Sankeerth committed Nov 9, 2023
1 parent 687f2fa commit e4c6bb2
Show file tree
Hide file tree
Showing 3 changed files with 269 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/helpers/geoLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export default class GeoLocationHelper {
public static getMessageWithGeoLocationData(
message: Record<string, FixMe>,
): Record<string, FixMe> {
const msg = cloneDeep(message || {});
if (isEmpty(msg?.context?.geo || {})) {
let msg = message;
if (isEmpty(msg?.context?.geo)) {
// geo-location data was not sent
return {};
}
Expand All @@ -46,6 +46,7 @@ export default class GeoLocationHelper {
{},
);
if (!isEmpty(address) || !isEmpty(mappedAddress)) {
msg = cloneDeep(message || {});
set(msg, addressKey, { ...address, ...mappedAddress });
}
return msg;
Expand Down
17 changes: 17 additions & 0 deletions test/helper/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ describe('GeoLocationHelper tests', () => {
city: 'Dharamshala',
postalCode: '123546',
});
// same reference check
expect(enhancedMsg.traits.address).toStrictEqual(msg.traits.address);
});

test("when context.geo doesn't have some properties, do not make use of non-available values in context.geo", () => {
Expand Down Expand Up @@ -407,6 +409,21 @@ describe('GeoLocationHelper tests', () => {
const enhancedMsg = GeoLocationHelper.getMessageWithGeoLocationData(msg);

expect(enhancedMsg).toEqual({});
// @ts-ignore
expect(enhancedMsg?.traits?.address).toBe(undefined);
// @ts-ignore
expect(enhancedMsg?.context?.traits?.address).toBe(undefined);
});

test('when message is null(no geo-enrichment happened), enrichment would not happen', () => {
const msg = null;

// @ts-ignore
const enhancedMsg = GeoLocationHelper.getMessageWithGeoLocationData(msg);

expect(enhancedMsg).toEqual({});
// @ts-ignore
expect(enhancedMsg?.traits).toBe(undefined);
});
});

Expand Down
249 changes: 249 additions & 0 deletions test/integrations/destinations/webhook/processor/data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,251 @@
const geoLocationData = [
{
name: 'webhook',
description: '[GeoLocation] Test 0',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
message: {
anonymousId: 'c82cbdff-e5be-4009-ac78-cdeea09ab4b1',
context: {
device: {
id: 'df16bffa-5c3d-4fbb-9bce-3bab098129a7R',
manufacturer: 'Xiaomi',
model: 'Redmi 6',
name: 'xiaomi',
},
network: { carrier: 'Banglalink' },
os: { name: 'android', version: '8.1.0' },
traits: {
address: { city: 'Dhaka', country: 'Bangladesh' },
anonymousId: 'c82cbdff-e5be-4009-ac78-cdeea09ab4b1',
},
geo: {
city: 'Gurugram',
country: 'IN',
ip: '223.190.82.63',
location: '28.459700,77.028200',
postal: '122001',
region: 'Haryana',
timezone: 'Asia/Kolkata',
},
},
event: 'spin_result',
integrations: { All: true },
message_id: 'a80f82be-9bdc-4a9f-b2a5-15621ee41df8',
properties: {
additional_bet_index: 0,
battle_id: 'N/A',
bet_amount: 9,
bet_level: 1,
bet_multiplier: 1,
coin_balance: 9466052,
current_module_name: 'CasinoGameModule',
days_in_game: 0,
extra_param: 'N/A',
fb_profile: '0',
featureGameType: 'N/A',
game_fps: 30,
game_id: 'fireEagleBase',
game_name: 'FireEagleSlots',
gem_balance: 0,
graphicsQuality: 'HD',
idfa: '2bf99787-33d2-4ae2-a76a-c49672f97252',
internetReachability: 'ReachableViaLocalAreaNetwork',
isLowEndDevice: 'False',
is_auto_spin: 'False',
is_turbo: 'False',
isf: 'False',
ishighroller: 'False',
jackpot_win_amount: 90,
jackpot_win_type: 'Silver',
level: 6,
lifetime_gem_balance: 0,
no_of_spin: 1,
player_total_battles: 0,
player_total_shields: 0,
start_date: '2019-08-01',
total_payments: 0,
tournament_id: 'T1561970819',
userId: 'c82cbdff-e5be-4009-ac78-cdeea09ab4b1',
versionSessionCount: 2,
win_amount: 0,
},
timestamp: '2019-09-01T15:46:51.693229+05:30',
type: 'track',
user_properties: {
coin_balance: 9466052,
current_module_name: 'CasinoGameModule',
fb_profile: '0',
game_fps: 30,
game_name: 'FireEagleSlots',
gem_balance: 0,
graphicsQuality: 'HD',
idfa: '2bf99787-33d2-4ae2-a76a-c49672f97252',
internetReachability: 'ReachableViaLocalAreaNetwork',
isLowEndDevice: false,
level: 6,
lifetime_gem_balance: 0,
player_total_battles: 0,
player_total_shields: 0,
start_date: '2019-08-01',
total_payments: 0,
userId: 'c82cbdff-e5be-4009-ac78-cdeea09ab4b1',
versionSessionCount: 2,
},
},
destination: {
Config: {
webhookUrl: 'http://6b0e6a60.ngrok.io',
headers: [
{ from: '', to: '' },
{ from: 'test2', to: 'value2' },
],
},
DestinationDefinition: {
Config: {
cdkV2Enabled: true,
},
},
},
metadata: {
destinationId: 'd1',
workspaceId: 'w1',
},
},
],
method: 'POST',
},
},
output: {
response: {
status: 200,
body: [
{
metadata: {
destinationId: 'd1',
workspaceId: 'w1',
},
output: {
body: {
XML: {},
JSON_ARRAY: {},
JSON: {
timestamp: '2019-09-01T15:46:51.693229+05:30',
user_properties: {
total_payments: 0,
internetReachability: 'ReachableViaLocalAreaNetwork',
level: 6,
userId: 'c82cbdff-e5be-4009-ac78-cdeea09ab4b1',
coin_balance: 9466052,
player_total_shields: 0,
isLowEndDevice: false,
game_fps: 30,
idfa: '2bf99787-33d2-4ae2-a76a-c49672f97252',
graphicsQuality: 'HD',
current_module_name: 'CasinoGameModule',
player_total_battles: 0,
lifetime_gem_balance: 0,
gem_balance: 0,
fb_profile: '0',
start_date: '2019-08-01',
versionSessionCount: 2,
game_name: 'FireEagleSlots',
},
integrations: { All: true },
event: 'spin_result',
message_id: 'a80f82be-9bdc-4a9f-b2a5-15621ee41df8',
anonymousId: 'c82cbdff-e5be-4009-ac78-cdeea09ab4b1',
context: {
geo: {
city: 'Gurugram',
country: 'IN',
ip: '223.190.82.63',
location: '28.459700,77.028200',
postal: '122001',
region: 'Haryana',
timezone: 'Asia/Kolkata',
},
device: {
model: 'Redmi 6',
manufacturer: 'Xiaomi',
id: 'df16bffa-5c3d-4fbb-9bce-3bab098129a7R',
name: 'xiaomi',
},
traits: {
anonymousId: 'c82cbdff-e5be-4009-ac78-cdeea09ab4b1',
address: {
city: 'Dhaka',
country: 'Bangladesh',
postalCode: '122001',
state: 'Haryana',
},
},
os: { version: '8.1.0', name: 'android' },
network: { carrier: 'Banglalink' },
},
type: 'track',
properties: {
userId: 'c82cbdff-e5be-4009-ac78-cdeea09ab4b1',
jackpot_win_type: 'Silver',
coin_balance: 9466052,
bet_level: 1,
ishighroller: 'False',
tournament_id: 'T1561970819',
battle_id: 'N/A',
bet_amount: 9,
fb_profile: '0',
player_total_shields: 0,
is_turbo: 'False',
player_total_battles: 0,
bet_multiplier: 1,
start_date: '2019-08-01',
versionSessionCount: 2,
graphicsQuality: 'HD',
is_auto_spin: 'False',
days_in_game: 0,
additional_bet_index: 0,
isLowEndDevice: 'False',
game_fps: 30,
extra_param: 'N/A',
idfa: '2bf99787-33d2-4ae2-a76a-c49672f97252',
current_module_name: 'CasinoGameModule',
game_id: 'fireEagleBase',
featureGameType: 'N/A',
gem_balance: 0,
internetReachability: 'ReachableViaLocalAreaNetwork',
total_payments: 0,
level: 6,
win_amount: 0,
no_of_spin: 1,
game_name: 'FireEagleSlots',
jackpot_win_amount: 90,
lifetime_gem_balance: 0,
isf: 'False',
},
},
FORM: {},
},
files: {},
endpoint: 'http://6b0e6a60.ngrok.io',
userId: 'c82cbdff-e5be-4009-ac78-cdeea09ab4b1',
headers: { 'content-type': 'application/json', test2: 'value2' },
version: '1',
params: {},
type: 'REST',
method: 'POST',
},
statusCode: 200,
},
],
},
},
},
];
export const data = [
{
name: 'webhook',
Expand Down Expand Up @@ -2167,4 +2415,5 @@ export const data = [
},
},
},
...geoLocationData,
];

0 comments on commit e4c6bb2

Please sign in to comment.