Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sayan-das-in committed Oct 21, 2024
1 parent 9743b63 commit 211d60c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Braze Cloud Mode (Actions) trackEvent should require one of braze_id, user_alias, or external_id 1`] = `"One of \\"external_id\\" or \\"user_alias\\" or \\"braze_id\\" is required."`;
exports[`Braze Cloud Mode (Actions) trackEvent should require one of braze_id, user_alias, or external_id 1`] = `"One of \\"external_id\\" or \\"user_alias\\" or \\"braze_id\\" or \\"email\\" is required."`;

exports[`Braze Cloud Mode (Actions) trackEvent should work with batched events 1`] = `
Headers {
Expand Down Expand Up @@ -75,7 +75,7 @@ Headers {
}
`;

exports[`Braze Cloud Mode (Actions) trackPurchase should require one of braze_id, user_alias, or external_id 1`] = `"One of \\"external_id\\" or \\"user_alias\\" or \\"braze_id\\" is required."`;
exports[`Braze Cloud Mode (Actions) trackPurchase should require one of braze_id, user_alias, or external_id 1`] = `"One of \\"external_id\\" or \\"user_alias\\" or \\"braze_id\\" or \\"email\\" is required."`;

exports[`Braze Cloud Mode (Actions) trackPurchase should work with default mappings 1`] = `
Headers {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ describe('MultiStatus', () => {
externalId: 'test-external-id'
}
}),
// Valid Event
createTestEvent({
type: 'identify',
receivedAt,
traits: {
name: 'Example User Two',
email: '[email protected]'
}
}),
// Event without any user identifier
createTestEvent({
type: 'identify',
Expand All @@ -68,11 +77,17 @@ describe('MultiStatus', () => {
body: 'success'
})

// The third event fails as pre-request validation fails for not having a valid user identifier
// The second event doesn't fail as there is no error reported by Braze API
expect(response[1]).toMatchObject({
status: 200,
body: 'success'
})

// The third event fails as pre-request validation fails for not having a valid user identifier
expect(response[2]).toMatchObject({
status: 400,
errortype: 'PAYLOAD_VALIDATION_FAILED',
errormessage: 'One of "external_id" or "user_alias" or "braze_id" is required.',
errormessage: 'One of "external_id" or "user_alias" or "braze_id" or "email" is required.',
errorreporter: 'DESTINATION'
})
})
Expand Down Expand Up @@ -201,6 +216,9 @@ describe('MultiStatus', () => {
describe('trackPurchase', () => {
const mapping = {
time: receivedAt,
email: {
'@path': '$.properties.email'
},
external_id: {
'@path': '$.properties.externalId'
},
Expand Down Expand Up @@ -236,6 +254,28 @@ describe('MultiStatus', () => {
]
}
}),
createTestEvent({
event: 'Order Completed',
type: 'track',
receivedAt,
properties: {
email: '[email protected]',
products: [
{
product_id: 'test-product-id',
currency: 'USD',
price: 99.99,
quantity: 1
},
{
product_id: 'test-product-id',
currency: 'USD',
price: 99.99,
quantity: 1
}
]
}
}),
// Event with no product
createTestEvent({
event: 'Order Completed',
Expand Down Expand Up @@ -276,19 +316,24 @@ describe('MultiStatus', () => {
body: 'success'
})

// The second event fails as it doesn't have any products
expect(response[1]).toMatchObject({
status: 200,
body: 'success'
})

// The third event fails as it doesn't have any products
expect(response[2]).toMatchObject({
status: 400,
errortype: 'PAYLOAD_VALIDATION_FAILED',
errormessage: 'This event was not sent to Braze because it did not contain any products.',
errorreporter: 'DESTINATION'
})

// The third event fails as pre-request validation fails for not having a valid user identifier
expect(response[2]).toMatchObject({
// The forth event fails as pre-request validation fails for not having a valid user identifier
expect(response[3]).toMatchObject({
status: 400,
errortype: 'PAYLOAD_VALIDATION_FAILED',
errormessage: 'One of "external_id" or "user_alias" or "braze_id" is required.',
errormessage: 'One of "external_id" or "user_alias" or "braze_id" or "email" is required.',
errorreporter: 'DESTINATION'
})
})
Expand Down Expand Up @@ -542,6 +587,15 @@ describe('MultiStatus', () => {
externalId: 'test-external-id'
}
}),
createTestEvent({
type: 'identify',
receivedAt,
traits: {
firstName: 'Example',
lastName: 'User',
email: '[email protected]'
}
}),
// Event without any user identifier
createTestEvent({
type: 'identify',
Expand All @@ -565,11 +619,17 @@ describe('MultiStatus', () => {
body: 'success'
})

// The third event fails as pre-request validation fails for not having a valid user identifier
// The second event doesn't fail as there is no error reported by Braze API
expect(response[1]).toMatchObject({
status: 200,
body: 'success'
})

// The third event fails as pre-request validation fails for not having a valid user identifier
expect(response[2]).toMatchObject({
status: 400,
errortype: 'PAYLOAD_VALIDATION_FAILED',
errormessage: 'One of "external_id" or "user_alias" or "braze_id" is required.',
errormessage: 'One of "external_id" or "user_alias" or "braze_id" or "email" is required.',
errorreporter: 'DESTINATION'
})
})
Expand Down

0 comments on commit 211d60c

Please sign in to comment.