-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: address and context.geo not present case
Signed-off-by: Sai Sankeerth <[email protected]>
- Loading branch information
Sai Sankeerth
committed
Nov 7, 2023
1 parent
d789f0e
commit d3d6b72
Showing
2 changed files
with
171 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { ProcessorTransformationRequest } from '../../src/types'; | ||
import { ProcessorTransformationRequest, RouterTransformationRequest } from '../../src/types'; | ||
import Enricher from '../../src/middlewares/enricher'; | ||
|
||
describe('geoLocation Enrichment during processor transformation tests', () => { | ||
describe('[GeoLocation Enrichment] Processor transformation tests', () => { | ||
test('should enrich when context.geo is populated correctly', () => { | ||
const inputData: ProcessorTransformationRequest[] = [ | ||
{ | ||
|
@@ -435,6 +435,172 @@ describe('geoLocation Enrichment during processor transformation tests', () => { | |
expect(ctx.request.body[0].message.traits?.address).toBe(undefined); | ||
}); | ||
|
||
test('should not contain address object, when context.geo & address are not present', () => { | ||
const inputData: ProcessorTransformationRequest[] = [ | ||
{ | ||
destination: { | ||
ID: '1afjtc6chkhdeKsXYrNFOzR5D9v', | ||
Name: 'Autopilot', | ||
DestinationDefinition: { | ||
ID: '1afjX4MlAucK57Q0ctTVlD27Tvo', | ||
Name: 'AUTOPILOT', | ||
DisplayName: 'Autopilot', | ||
Config: { | ||
cdkEnabled: true, | ||
excludeKeys: [], | ||
includeKeys: [], | ||
}, | ||
}, | ||
Config: { | ||
apiKey: 'dummyApiKey', | ||
customMappings: [ | ||
{ | ||
from: '0001', | ||
to: 'Signup', | ||
}, | ||
], | ||
triggerId: '00XX', | ||
}, | ||
Enabled: true, | ||
Transformations: [], | ||
// @ts-ignore | ||
IsProcessorEnabled: true, | ||
}, | ||
message: { | ||
anonymousId: 'ac7722c2-ccb6-4ae2-baf6-1effe861f4cd', | ||
channel: 'web', | ||
context: { | ||
app: { | ||
build: '1.0.0', | ||
name: 'RudderLabs JavaScript SDK', | ||
namespace: 'com.rudderlabs.javascript', | ||
version: '1.1.1-rc.2', | ||
}, | ||
library: { | ||
name: 'RudderLabs JavaScript SDK', | ||
version: '1.1.1-rc.2', | ||
}, | ||
locale: 'en-GB', | ||
os: { | ||
name: '', | ||
version: '', | ||
}, | ||
page: { | ||
path: '/tests/html/index4.html', | ||
referrer: '', | ||
search: '', | ||
title: '', | ||
url: 'http://localhost/tests/html/index4.html', | ||
}, | ||
screen: { | ||
density: 2, | ||
}, | ||
userAgent: | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36', | ||
}, | ||
integrations: { | ||
All: true, | ||
}, | ||
messageId: 'fad9b3fb-5778-4db3-9fb6-7168b554191f', | ||
originalTimestamp: '2020-04-17T14:42:44.722Z', | ||
receivedAt: '2020-04-17T20:12:44.758+05:30', | ||
request_ip: '[::1]:53513', | ||
sentAt: '2020-04-17T14:42:44.722Z', | ||
traits: { | ||
age: 23, | ||
email: '[email protected]', | ||
firstname: 'Test Kafka', | ||
}, | ||
timestamp: '2020-04-17T20:12:44.758+05:30', | ||
type: 'identify', | ||
userId: 'user12345', | ||
}, | ||
}, | ||
{ | ||
destination: { | ||
ID: '1afjtc6chkhdeKsXYrNFOzR5D9v', | ||
Name: 'Autopilot', | ||
DestinationDefinition: { | ||
ID: '1afjX4MlAucK57Q0ctTVlD27Tvo', | ||
Name: 'AUTOPILOT', | ||
DisplayName: 'Autopilot', | ||
Config: { | ||
cdkEnabled: true, | ||
excludeKeys: [], | ||
includeKeys: [], | ||
}, | ||
}, | ||
Config: { | ||
apiKey: 'dummyApiKey', | ||
customMappings: [ | ||
{ | ||
from: '0001', | ||
to: 'Signup', | ||
}, | ||
], | ||
triggerId: '00XX', | ||
}, | ||
Enabled: true, | ||
Transformations: [], | ||
// @ts-ignore | ||
IsProcessorEnabled: true, | ||
}, | ||
message: { | ||
anonymousId: 'ac7722c2-ccb6-4ae2-baf6-1effe861f4cd', | ||
channel: 'web', | ||
context: { | ||
app: { | ||
build: '1.0.0', | ||
name: 'RudderLabs JavaScript SDK', | ||
namespace: 'com.rudderlabs.javascript', | ||
version: '1.1.1-rc.2', | ||
}, | ||
library: { | ||
name: 'RudderLabs JavaScript SDK', | ||
version: '1.1.1-rc.2', | ||
}, | ||
locale: 'en-GB', | ||
os: { | ||
name: '', | ||
version: '', | ||
}, | ||
page: { | ||
path: '/tests/html/index4.html', | ||
referrer: '', | ||
search: '', | ||
title: '', | ||
url: 'http://localhost/tests/html/index4.html', | ||
}, | ||
screen: { | ||
density: 2, | ||
}, | ||
userAgent: | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36', | ||
}, | ||
integrations: { | ||
All: true, | ||
}, | ||
messageId: 'fad9b3fb-5778-4db3-9fb6-7168b554191f', | ||
originalTimestamp: '2020-04-17T14:42:44.722Z', | ||
receivedAt: '2020-04-17T20:12:44.758+05:30', | ||
request_ip: '[::1]:53513', | ||
sentAt: '2020-04-17T14:42:44.722Z', | ||
traits: { | ||
key: 'val', | ||
}, | ||
timestamp: '2020-04-17T20:12:44.758+05:30', | ||
type: 'identify', | ||
userId: 'user12345', | ||
}, | ||
}, | ||
]; | ||
const ctx = { request: { body: inputData } }; | ||
// @ts-ignore | ||
Enricher.enrichGeoLocation(ctx); | ||
expect(ctx.request.body[0].message.traits).not.toHaveProperty('address'); | ||
expect(ctx.request.body[1].message.traits).not.toHaveProperty('address'); | ||
}); | ||
|
||
test('should enrich when context.geo is populated correctly for multiple payloads with their own geolocation data', () => { | ||
const inputData: ProcessorTransformationRequest[] = [ | ||
{ | ||
|