Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Object {
},
"event": "E@t!q#n(^u",
"properties": Object {
"moe_project_name": "E@t!q#n(^u",
"testType": "E@t!q#n(^u",
},
"timestamp": "2021-02-01T00:00:00.000Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Object {
},
"event": "[3(wtAyZqr",
"properties": Object {
"moe_project_name": "[3(wtAyZqr",
"testType": "[3(wtAyZqr",
},
"timestamp": "2021-02-01T00:00:00.000Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ import { createTestEvent, createTestIntegration } from '@segment/actions-core'
import Destination from '../../index'
import { getEndpointByRegion } from '../../regional-endpoints'


const testDestination = createTestIntegration(Destination)
const api_id = "APP_ID"
const api_key = "APP_KEY"
const region = "SOME_REGION"

const api_id = 'APP_ID'
const api_key = 'APP_KEY'
const region = 'SOME_REGION'

const endpoint = getEndpointByRegion()

describe('ActionsMoengage.trackEvent', () => {

it('should validate action fields', async () => {
const event = createTestEvent({ event: 'Test Event' })

Expand All @@ -28,17 +25,98 @@ describe('ActionsMoengage.trackEvent', () => {
region
}
})

expect(responses.length).toBe(1)
expect(responses[0].status).toBe(200)
expect(responses[0].data).toMatchObject({})
expect(responses[0].options.json).toMatchObject(
{
type: 'track',
event: 'Test Event',
context: {library: { version: '2.11.1' }}
expect(responses[0].options.json).toMatchObject({
type: 'track',
event: 'Test Event',
context: { library: { version: '2.11.1' } }
})
})

it('should include project_name in properties when provided', async () => {
const event = createTestEvent({
event: 'Test Event',
properties: { key1: 'value1' }
})

Comment thread
satyamMIPL marked this conversation as resolved.
nock(`${endpoint}`).post(`/v1/integrations/segment?appId=${api_id}`).reply(200, {})

const responses = await testDestination.testAction('trackEvent', {
event,
useDefaultMappings: true,
mapping: { project_name: 'MyProject' },
settings: {
api_id,
api_key,
region
}
})

expect(responses.length).toBe(1)
expect(responses[0].status).toBe(200)
expect(responses[0].options.json).toMatchObject({
type: 'track',
event: 'Test Event',
properties: {
key1: 'value1',
moe_project_name: 'MyProject'
}
})
})

it('should not include project_name in properties when it is empty string', async () => {
const event = createTestEvent({
event: 'Test Event',
properties: { key1: 'value1' }
})

nock(`${endpoint}`).post(`/v1/integrations/segment?appId=${api_id}`).reply(200, {})

const responses = await testDestination.testAction('trackEvent', {
event,
useDefaultMappings: true,
mapping: { project_name: '' },
settings: {
api_id,
api_key,
region
}
})

expect(responses.length).toBe(1)
expect(responses[0].status).toBe(200)
const payload = responses[0].options.json as Record<string, unknown>
const properties = payload.properties as Record<string, unknown>
expect(properties).not.toHaveProperty('moe_project_name')
expect(properties).toMatchObject({ key1: 'value1' })
})

it('should not include project_name in properties when it is not provided', async () => {
const event = createTestEvent({
event: 'Test Event',
properties: { key1: 'value1' }
})

nock(`${endpoint}`).post(`/v1/integrations/segment?appId=${api_id}`).reply(200, {})

const responses = await testDestination.testAction('trackEvent', {
event,
useDefaultMappings: true,
settings: {
api_id,
api_key,
region
}
)
})

expect(responses.length).toBe(1)
expect(responses[0].status).toBe(200)
const payload = responses[0].options.json as Record<string, unknown>
const properties = payload.properties as Record<string, unknown>
expect(properties).not.toHaveProperty('moe_project_name')
})

it('should require event field', async () => {
Expand All @@ -47,16 +125,16 @@ describe('ActionsMoengage.trackEvent', () => {

nock(`${endpoint}`).post(`/v1/integrations/segment?appId=${api_id}`).reply(200, {})

try {
await testDestination.testAction('trackEvent', {
event, useDefaultMappings: true, settings: {
await expect(
testDestination.testAction('trackEvent', {
event,
useDefaultMappings: true,
settings: {
api_id,
api_key,
region
}
})
} catch (e) {
expect(e.message).toBe("The root value is missing the required field 'event'.")
}
).rejects.toThrow("The root value is missing the required field 'event'.")
})
})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ const action: ActionDefinition<Settings, Payload> = {
'@path': '$.properties'
}
},
project_name: {
label: 'Project Name',
type: 'string',
description:
'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.',
required: false,
default: ''
},
update_existing_only: {
label: 'Update Existing Users Only',
type: 'boolean',
Expand All @@ -98,6 +106,14 @@ const action: ActionDefinition<Settings, Payload> = {
throw new IntegrationError('Missing API ID or API KEY', 'Missing required field', 400)
}

let properties = payload.properties
if (payload.project_name) {
properties = {
...(payload.properties ?? {}),
moe_project_name: payload.project_name
}
}

const event = {
type: payload.type,
user_id: payload.userId,
Expand All @@ -108,7 +124,7 @@ const action: ActionDefinition<Settings, Payload> = {
os: { name: payload.os_name },
library: { version: payload.library_version }
},
properties: payload.properties,
properties,
timestamp: payload.timestamp,
update_existing_only: payload.update_existing_only || false
Comment thread
satyamMIPL marked this conversation as resolved.
}
Expand Down
Loading