Skip to content

Commit 80aeefb

Browse files
authored
fix: added project name to user mappings ui (#9)
* fix: added project name to user mappings ui * fix: adding null check for properties in payload * fix: mapping moe field with project name * fix: test cases
1 parent 0528c94 commit 80aeefb

5 files changed

Lines changed: 116 additions & 15 deletions

File tree

packages/destination-actions/src/destinations/moengage/__tests__/__snapshots__/snapshot.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Object {
5252
},
5353
"event": "E@t!q#n(^u",
5454
"properties": Object {
55+
"moe_project_name": "E@t!q#n(^u",
5556
"testType": "E@t!q#n(^u",
5657
},
5758
"timestamp": "2021-02-01T00:00:00.000Z",
@@ -69,6 +70,7 @@ Object {
6970
"os": Object {},
7071
},
7172
"event": "E@t!q#n(^u",
73+
"properties": Object {},
7274
"type": "E@t!q#n(^u",
7375
"update_existing_only": false,
7476
}

packages/destination-actions/src/destinations/moengage/trackEvent/__tests__/__snapshots__/snapshot.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Object {
1616
},
1717
"event": "[3(wtAyZqr",
1818
"properties": Object {
19+
"moe_project_name": "[3(wtAyZqr",
1920
"testType": "[3(wtAyZqr",
2021
},
2122
"timestamp": "2021-02-01T00:00:00.000Z",
@@ -33,6 +34,7 @@ Object {
3334
"os": Object {},
3435
},
3536
"event": "[3(wtAyZqr",
37+
"properties": Object {},
3638
"type": "[3(wtAyZqr",
3739
"update_existing_only": false,
3840
}

packages/destination-actions/src/destinations/moengage/trackEvent/__tests__/index.test.ts

Lines changed: 94 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ import { createTestEvent, createTestIntegration } from '@segment/actions-core'
33
import Destination from '../../index'
44
import { getEndpointByRegion } from '../../regional-endpoints'
55

6-
76
const testDestination = createTestIntegration(Destination)
8-
const api_id = "APP_ID"
9-
const api_key = "APP_KEY"
10-
const region = "SOME_REGION"
11-
7+
const api_id = 'APP_ID'
8+
const api_key = 'APP_KEY'
9+
const region = 'SOME_REGION'
1210

1311
const endpoint = getEndpointByRegion()
1412

1513
describe('ActionsMoengage.trackEvent', () => {
16-
1714
it('should validate action fields', async () => {
1815
const event = createTestEvent({ event: 'Test Event' })
1916

@@ -28,17 +25,98 @@ describe('ActionsMoengage.trackEvent', () => {
2825
region
2926
}
3027
})
31-
28+
3229
expect(responses.length).toBe(1)
3330
expect(responses[0].status).toBe(200)
3431
expect(responses[0].data).toMatchObject({})
35-
expect(responses[0].options.json).toMatchObject(
36-
{
37-
type: 'track',
38-
event: 'Test Event',
39-
context: {library: { version: '2.11.1' }}
32+
expect(responses[0].options.json).toMatchObject({
33+
type: 'track',
34+
event: 'Test Event',
35+
context: { library: { version: '2.11.1' } }
36+
})
37+
})
38+
39+
it('should include project_name in properties when provided', async () => {
40+
const event = createTestEvent({
41+
event: 'Test Event',
42+
properties: { key1: 'value1' }
43+
})
44+
45+
nock(`${endpoint}`).post(`/v1/integrations/segment?appId=${api_id}`).reply(200, {})
46+
47+
const responses = await testDestination.testAction('trackEvent', {
48+
event,
49+
useDefaultMappings: true,
50+
mapping: { project_name: 'MyProject' },
51+
settings: {
52+
api_id,
53+
api_key,
54+
region
55+
}
56+
})
57+
58+
expect(responses.length).toBe(1)
59+
expect(responses[0].status).toBe(200)
60+
expect(responses[0].options.json).toMatchObject({
61+
type: 'track',
62+
event: 'Test Event',
63+
properties: {
64+
key1: 'value1',
65+
moe_project_name: 'MyProject'
66+
}
67+
})
68+
})
69+
70+
it('should not include project_name in properties when it is empty string', async () => {
71+
const event = createTestEvent({
72+
event: 'Test Event',
73+
properties: { key1: 'value1' }
74+
})
75+
76+
nock(`${endpoint}`).post(`/v1/integrations/segment?appId=${api_id}`).reply(200, {})
77+
78+
const responses = await testDestination.testAction('trackEvent', {
79+
event,
80+
useDefaultMappings: true,
81+
mapping: { project_name: '' },
82+
settings: {
83+
api_id,
84+
api_key,
85+
region
86+
}
87+
})
88+
89+
expect(responses.length).toBe(1)
90+
expect(responses[0].status).toBe(200)
91+
const payload = responses[0].options.json as Record<string, unknown>
92+
const properties = payload.properties as Record<string, unknown>
93+
expect(properties).not.toHaveProperty('moe_project_name')
94+
expect(properties).toMatchObject({ key1: 'value1' })
95+
})
96+
97+
it('should not include project_name in properties when it is not provided', async () => {
98+
const event = createTestEvent({
99+
event: 'Test Event',
100+
properties: { key1: 'value1' }
101+
})
102+
103+
nock(`${endpoint}`).post(`/v1/integrations/segment?appId=${api_id}`).reply(200, {})
104+
105+
const responses = await testDestination.testAction('trackEvent', {
106+
event,
107+
useDefaultMappings: true,
108+
settings: {
109+
api_id,
110+
api_key,
111+
region
40112
}
41-
)
113+
})
114+
115+
expect(responses.length).toBe(1)
116+
expect(responses[0].status).toBe(200)
117+
const payload = responses[0].options.json as Record<string, unknown>
118+
const properties = payload.properties as Record<string, unknown>
119+
expect(properties).not.toHaveProperty('moe_project_name')
42120
})
43121

44122
it('should require event field', async () => {
@@ -49,7 +127,9 @@ describe('ActionsMoengage.trackEvent', () => {
49127

50128
try {
51129
await testDestination.testAction('trackEvent', {
52-
event, useDefaultMappings: true, settings: {
130+
event,
131+
useDefaultMappings: true,
132+
settings: {
53133
api_id,
54134
api_key,
55135
region

packages/destination-actions/src/destinations/moengage/trackEvent/generated-types.ts

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/destination-actions/src/destinations/moengage/trackEvent/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ const action: ActionDefinition<Settings, Payload> = {
8484
'@path': '$.properties'
8585
}
8686
},
87+
project_name: {
88+
label: 'Project Name',
89+
type: 'string',
90+
description:
91+
'Enter the Project Name from MoEngage Settings > Portfolio. Values must match exactly. Mismatched events stay at the portfolio level and are unusable for project-level analysis. Leave this field blank if Portfolio is not enabled for your workspace.',
92+
required: false,
93+
default: ''
94+
},
8795
update_existing_only: {
8896
label: 'Update Existing Users Only',
8997
type: 'boolean',
@@ -98,6 +106,11 @@ const action: ActionDefinition<Settings, Payload> = {
98106
throw new IntegrationError('Missing API ID or API KEY', 'Missing required field', 400)
99107
}
100108

109+
const properties = payload.properties ? { ...payload.properties } : {}
110+
if (payload.project_name) {
111+
properties.moe_project_name = payload.project_name
112+
}
113+
101114
const event = {
102115
type: payload.type,
103116
user_id: payload.userId,
@@ -108,7 +121,7 @@ const action: ActionDefinition<Settings, Payload> = {
108121
os: { name: payload.os_name },
109122
library: { version: payload.library_version }
110123
},
111-
properties: payload.properties,
124+
properties,
112125
timestamp: payload.timestamp,
113126
update_existing_only: payload.update_existing_only || false
114127
}

0 commit comments

Comments
 (0)