Skip to content

Commit

Permalink
updating snapshot tests braze moengage and trackey
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-ayoub-segment committed Nov 15, 2023
1 parent a2172b9 commit 4f3febd
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,150 @@ Object {
],
}
`;

exports[`Testing snapshot for Braze's updateUserProfile destination action: it should work with a single batched events 1`] = `
Headers {
Symbol(map): Object {
"authorization": Array [
"Bearer my-api-key",
],
"user-agent": Array [
"Segment (Actions)",
],
},
}
`;

exports[`Testing snapshot for Braze's updateUserProfile destination action: it should work with a single batched events 2`] = `
Object {
"attributes": Array [
Object {
"_update_existing_only": true,
"braze_id": undefined,
"country": "United States",
"current_location": Object {
"latitude": 40.2964197,
"longitude": -76.9411617,
},
"date_of_first_session": undefined,
"date_of_last_session": undefined,
"dob": undefined,
"email": undefined,
"email_click_tracking_disabled": undefined,
"email_open_tracking_disabled": undefined,
"email_subscribe": undefined,
"external_id": "user1234",
"facebook": undefined,
"first_name": undefined,
"gender": undefined,
"home_city": undefined,
"image_url": undefined,
"language": undefined,
"last_name": undefined,
"marked_email_as_spam_at": undefined,
"phone": undefined,
"push_subscribe": undefined,
"push_tokens": undefined,
"time_zone": undefined,
"twitter": undefined,
"user_alias": undefined,
},
],
}
`;

exports[`Testing snapshot for Braze's updateUserProfile destination action: it should work with batched events 1`] = `
Headers {
Symbol(map): Object {
"authorization": Array [
"Bearer my-api-key",
],
"user-agent": Array [
"Segment (Actions)",
],
"x-braze-batch": Array [
"true",
],
},
}
`;

exports[`Testing snapshot for Braze's updateUserProfile destination action: it should work with batched events 2`] = `
Object {
"attributes": Array [
Object {
"_update_existing_only": true,
"braze_id": undefined,
"country": "United States",
"current_location": Object {
"latitude": 40.2964197,
"longitude": -76.9411617,
},
"date_of_first_session": "2000-01-05T12:00:00.000Z",
"date_of_last_session": "2000-01-05T12:00:00.000Z",
"dob": undefined,
"email": undefined,
"email_click_tracking_disabled": undefined,
"email_open_tracking_disabled": undefined,
"email_subscribe": undefined,
"external_id": "user1234",
"facebook": undefined,
"first_name": undefined,
"gender": undefined,
"home_city": undefined,
"image_url": undefined,
"language": undefined,
"last_name": undefined,
"marked_email_as_spam_at": "2000-01-05T12:00:00.000Z",
"phone": undefined,
"push_subscribe": undefined,
"push_tokens": undefined,
"time_zone": undefined,
"twitter": undefined,
"user_alias": undefined,
},
Object {
"_update_existing_only": true,
"braze_id": undefined,
"country": "United States",
"current_location": Object {
"latitude": 40.2964197,
"longitude": -76.9411617,
},
"date_of_first_session": "2000-01-05T12:00:00.000Z",
"date_of_last_session": "2000-01-05T12:00:00.000Z",
"dob": undefined,
"email": undefined,
"email_click_tracking_disabled": undefined,
"email_open_tracking_disabled": undefined,
"email_subscribe": undefined,
"external_id": "user1234",
"facebook": undefined,
"first_name": undefined,
"gender": undefined,
"home_city": undefined,
"image_url": undefined,
"language": undefined,
"last_name": undefined,
"marked_email_as_spam_at": "2000-01-05T12:00:00.000Z",
"phone": undefined,
"push_subscribe": undefined,
"push_tokens": undefined,
"time_zone": undefined,
"twitter": undefined,
"user_alias": undefined,
},
],
}
`;

exports[`Testing snapshot for Braze's updateUserProfile destination action: required fields 1`] = `
Object {
"attributes": Array [
Object {
"braze_id": "M8rtOywDKgN((jhUBk9",
"external_id": "M8rtOywDKgN((jhUBk9",
},
],
}
`;
Original file line number Diff line number Diff line change
@@ -1,50 +1,73 @@
import nock from 'nock'
import { createTestEvent, createTestIntegration } from '@segment/actions-core'
import Destination from '../../index'
import { getEndpointByRegion } from '../../regional-endpoints'
// Jest Snapshot v1, https://goo.gl/fbAQLP

const testDestination = createTestIntegration(Destination)
const MOENGAGE_API_ID = 'SOME_APP_ID'
const MOENGAGE_API_KEY = 'SOME_APP_KEY'
const MOENGAGE_REGION = 'SOME_REGION'
exports[`Testing snapshot for actions-moengage destination: identifyUser action - all fields 1`] = `
Object {
"anonymous_id": "z(%@QRCz7h$8M)#]",
"context": Object {
"app": Object {
"version": "z(%@QRCz7h$8M)#]",
},
"library": Object {
"version": "z(%@QRCz7h$8M)#]",
},
"os": Object {
"name": "z(%@QRCz7h$8M)#]",
},
},
"timestamp": "2021-02-01T00:00:00.000Z",
"traits": Object {
"testType": "z(%@QRCz7h$8M)#]",
},
"type": "z(%@QRCz7h$8M)#]",
"update_existing_only": false,
"user_id": "z(%@QRCz7h$8M)#]",
}
`;

const endpoint = getEndpointByRegion()
exports[`Testing snapshot for actions-moengage destination: identifyUser action - required fields 1`] = `
Object {
"context": Object {
"app": Object {},
"library": Object {},
"os": Object {},
},
"type": "z(%@QRCz7h$8M)#]",
"update_existing_only": false,
}
`;

describe('ActionsMoengage.identifyUser', () => {
it('should validate action fields', async () => {
const event = createTestEvent({ traits: { name: 'abc' } })
exports[`Testing snapshot for actions-moengage destination: trackEvent action - all fields 1`] = `
Object {
"anonymous_id": "E@t!q#n(^u",
"context": Object {
"app": Object {
"version": "E@t!q#n(^u",
},
"library": Object {
"version": "E@t!q#n(^u",
},
"os": Object {
"name": "E@t!q#n(^u",
},
},
"event": "E@t!q#n(^u",
"properties": Object {
"testType": "E@t!q#n(^u",
},
"timestamp": "2021-02-01T00:00:00.000Z",
"type": "E@t!q#n(^u",
"user_id": "E@t!q#n(^u",
}
`;

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

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

expect(responses.length).toBe(1)
expect(responses[0].status).toBe(200)
expect(responses[0].data).toMatchObject({})
expect(responses[0].options.body).toBe(
`{"type":"track","user_id":"user1234","traits":{"name":"abc"},"context":{"app":{},"os":{},"library":{"version":"2.11.1"}},"anonymous_id":"${event.anonymousId}","timestamp":"${event.timestamp}","update_existing_only":false}`
)
})

it('should require api_id and api_key', async () => {
const event = createTestEvent()
nock(`${endpoint}`).post(`/v1/integrations/segment?appId=${MOENGAGE_API_ID}`).reply(200, {})

try {
await testDestination.testAction('identifyUser', {
event,
useDefaultMappings: true
})
} catch (e) {
expect(e.message).toBe('Missing API ID or API KEY')
}
})
})
exports[`Testing snapshot for actions-moengage destination: trackEvent action - required fields 1`] = `
Object {
"context": Object {
"app": Object {},
"library": Object {},
"os": Object {},
},
"event": "E@t!q#n(^u",
"type": "E@t!q#n(^u",
}
`;
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing snapshot for actions-trackey destination: identify action - all fields 1`] = `
exports[`Testing snapshot for actions-trackey destination: group action - all fields 1`] = `
Object {
"messageId": "4lC*xBPj6Zf^iE3J1PF",
"timestamp": "4lC*xBPj6Zf^iE3J1PF",
"groupId": "^Vvf$jtvC",
"messageId": "^Vvf$jtvC",
"timestamp": "^Vvf$jtvC",
"traits": Object {
"testType": "4lC*xBPj6Zf^iE3J1PF",
"testType": "^Vvf$jtvC",
},
"userId": "4lC*xBPj6Zf^iE3J1PF",
"userId": "^Vvf$jtvC",
}
`;

exports[`Testing snapshot for actions-trackey destination: identify action - required fields 1`] = `
exports[`Testing snapshot for actions-trackey destination: group action - required fields 1`] = `
Object {
"timestamp": "4lC*xBPj6Zf^iE3J1PF",
"userId": "4lC*xBPj6Zf^iE3J1PF",
"groupId": "^Vvf$jtvC",
"timestamp": "^Vvf$jtvC",
"userId": "^Vvf$jtvC",
}
`;

exports[`Testing snapshot for actions-trackey destination: group action - all fields 1`] = `
exports[`Testing snapshot for actions-trackey destination: identify action - all fields 1`] = `
Object {
"groupId": "dv8xxzqiX16YI!L#st",
"messageId": "dv8xxzqiX16YI!L#st",
"timestamp": "dv8xxzqiX16YI!L#st",
"messageId": "6aniX&1",
"timestamp": "6aniX&1",
"traits": Object {
"testType": "dv8xxzqiX16YI!L#st",
"testType": "6aniX&1",
},
"userId": "dv8xxzqiX16YI!L#st",
"userId": "6aniX&1",
}
`;

exports[`Testing snapshot for actions-trackey destination: group action - required fields 1`] = `
exports[`Testing snapshot for actions-trackey destination: identify action - required fields 1`] = `
Object {
"groupId": "dv8xxzqiX16YI!L#st",
"timestamp": "dv8xxzqiX16YI!L#st",
"userId": "dv8xxzqiX16YI!L#st",
"timestamp": "6aniX&1",
"userId": "6aniX&1",
}
`;

exports[`Testing snapshot for actions-trackey destination: track action - all fields 1`] = `
Object {
"event": "qnx]3%$)][Qxz",
"event": "eT[K8ft@uBryp",
"groupId": Object {
"testType": "qnx]3%$)][Qxz",
"testType": "eT[K8ft@uBryp",
},
"messageId": "qnx]3%$)][Qxz",
"messageId": "eT[K8ft@uBryp",
"properties": Object {
"testType": "qnx]3%$)][Qxz",
"testType": "eT[K8ft@uBryp",
},
"timestamp": "qnx]3%$)][Qxz",
"userId": "qnx]3%$)][Qxz",
"timestamp": "eT[K8ft@uBryp",
"userId": "eT[K8ft@uBryp",
}
`;

exports[`Testing snapshot for actions-trackey destination: track action - required fields 1`] = `
Object {
"event": "qnx]3%$)][Qxz",
"timestamp": "qnx]3%$)][Qxz",
"userId": "qnx]3%$)][Qxz",
"event": "eT[K8ft@uBryp",
"timestamp": "eT[K8ft@uBryp",
"userId": "eT[K8ft@uBryp",
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

exports[`Testing snapshot for Trackey's group destination action: all fields 1`] = `
Object {
"groupId": "XKWTBCZ%QyH",
"messageId": "XKWTBCZ%QyH",
"timestamp": "XKWTBCZ%QyH",
"groupId": "IF@l7Hj&FhM",
"messageId": "IF@l7Hj&FhM",
"timestamp": "IF@l7Hj&FhM",
"traits": Object {
"testType": "XKWTBCZ%QyH",
"testType": "IF@l7Hj&FhM",
},
"userId": "XKWTBCZ%QyH",
"userId": "IF@l7Hj&FhM",
}
`;

exports[`Testing snapshot for Trackey's group destination action: required fields 1`] = `
Object {
"groupId": "XKWTBCZ%QyH",
"timestamp": "XKWTBCZ%QyH",
"userId": "XKWTBCZ%QyH",
"groupId": "IF@l7Hj&FhM",
"timestamp": "IF@l7Hj&FhM",
"userId": "IF@l7Hj&FhM",
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Trackey.group', () => {
}
})

const response = await testDestination.testAction('registerCompany', {
const response = await testDestination.testAction('group', {
event,
useDefaultMappings: true,
settings: {
Expand Down
Loading

0 comments on commit 4f3febd

Please sign in to comment.