diff --git a/src/v0/destinations/moengage/transform.js b/src/v0/destinations/moengage/transform.js index ea7db24406..8a16d9c7a7 100644 --- a/src/v0/destinations/moengage/transform.js +++ b/src/v0/destinations/moengage/transform.js @@ -119,7 +119,7 @@ const processEvent = (message, destination) => { response = responseBuilderSimple(message, category, destination); // only if device information is present device info will be added/updated // with an identify call otherwise only user info will be added/updated - if (message.context.device && message.context.device.type && message.context.device.token) { + if (message?.context?.device?.type && message?.context?.device?.token) { // build the response response = [ // user api payload (output for identify) diff --git a/test/integrations/destinations/moengage/processor/data.ts b/test/integrations/destinations/moengage/processor/data.ts index 50b0361381..1ce8705f53 100644 --- a/test/integrations/destinations/moengage/processor/data.ts +++ b/test/integrations/destinations/moengage/processor/data.ts @@ -2777,4 +2777,105 @@ export const data = [ }, }, }, + { + name: 'moengage', + description: + 'when identify is sent without context, the event should not throw internal server error', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + message: { + type: 'identify', + event: 'identify', + sentAt: '2023-11-22T03:42:40.346Z', + userId: 'userId16', + channel: 'mobile', + rudderId: 'dummy-rudderId', + timestamp: '2023-11-22T03:42:31.470Z', + receivedAt: '2023-11-22T03:42:43.281Z', + request_ip: '114.122.233.48', + anonymousId: 'anon-dummyId-1', + integrations: { + All: true, + }, + originalTimestamp: '2023-11-22T03:42:28.535Z', + }, + destination: { + ID: '1iuTZs6eEZVMm6GjRBe6bNShaL3', + Name: 'MoEngage Testing', + DestinationDefinition: { + ID: '1iu4802Tx27kNC4KNYYou6D8jzL', + Name: 'MOENGAGE', + DisplayName: 'MoEngage', + Config: { + destConfig: { defaultConfig: ['apiId', 'apiKey', 'region'] }, + excludeKeys: [], + includeKeys: [], + supportedSourceTypes: [ + 'android', + 'ios', + 'web', + 'unity', + 'amp', + 'cloud', + 'reactnative', + ], + }, + }, + Config: { + apiId: 'W0ZHNMPI2O4KHJ48ZILZACRA', + apiKey: 'dummyApiKey', + eventDelivery: false, + eventDeliveryTS: 1602757086384, + region: 'US', + }, + Enabled: true, + Transformations: [], + IsProcessorEnabled: true, + }, + }, + ], + method: 'POST', + }, + pathSuffix: '', + }, + output: { + response: { + status: 200, + body: [ + { + output: { + body: { + FORM: {}, + JSON: { + attributes: {}, + customer_id: 'userId16', + type: 'customer', + }, + JSON_ARRAY: {}, + XML: {}, + }, + endpoint: 'https://api-01.moengage.com/v1/customer/W0ZHNMPI2O4KHJ48ZILZACRA', + files: {}, + headers: { + Authorization: 'Basic VzBaSE5NUEkyTzRLSEo0OFpJTFpBQ1JBOmR1bW15QXBpS2V5', + 'Content-Type': 'application/json', + 'MOE-APPKEY': 'W0ZHNMPI2O4KHJ48ZILZACRA', + }, + method: 'POST', + params: {}, + type: 'REST', + userId: 'anon-dummyId-1', + version: '1', + }, + statusCode: 200, + }, + ], + }, + }, + }, ];