Skip to content

Commit

Permalink
fix: enhance code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Mar 11, 2024
1 parent 1ff8127 commit 7cf683b
Show file tree
Hide file tree
Showing 4 changed files with 328 additions and 7 deletions.
28 changes: 28 additions & 0 deletions src/v0/destinations/facebook_pixel/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ const getTestMessage = () => {
return message;
};

const getTestMessageWithoutProductIdAndCategory = () => {
let message = {
properties: {
currency: 'CAD',
quantity: 1,
price: 24.75,
value: 30,
name: 'my product 1',
testDimension: true,
testMetric: true,
position: 4.5,
query: 'HDMI Cable',
},
};
return message;
};

const getTestCategoryToContent = () => {
let categoryToContent = [
{
Expand Down Expand Up @@ -52,6 +69,17 @@ describe('Unit test cases for facebook_pixel handle search', () => {
expect(handleSearch(getTestMessage())).toEqual(expectedOutput);
});

it('should return content with content_ids and content fields as empty array', async () => {
const expectedOutput = {
content_ids: [],
content_category: '',
value: 30,
search_string: 'HDMI Cable',
contents: [],
};
expect(handleSearch(getTestMessageWithoutProductIdAndCategory())).toEqual(expectedOutput);
});

it("mapping 'product_id' with contentId", async () => {
let message = getTestMessage();
message.properties.product_id = 'prd-123';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1070,4 +1070,51 @@ export const ecommTestData: ProcessorTestData[] = [
},
},
},
{
id: 'facebook_pixel-ecomm-test-12',
name: 'facebook_pixel',
description:
'Track call : product list viewed event call with properties without product array and revenue as string',
scenario: 'ecommerce',
successCriteria:
'Error : It should throw an error as revenue is not a number and should not be sent to the destination',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
message: generateTrackPayload({
event: 'product list viewed',
properties: { ...commonPropertiesWithoutProductArray, value: '$20' },
context: {
traits: commonUserTraits,
},
timestamp: commonTimestamp,
}),
metadata: generateMetadata(1),
destination: commonDestination,
},
],
},
},
output: {
response: {
status: 200,
body: [
{
error: 'Revenue could not be converted to number',
metadata: generateMetadata(1),
statTags: {
...commonStatTags,
destinationId: 'default-destinationId',
workspaceId: 'default-workspaceId',
},
statusCode: 400,
},
],
},
},
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,23 @@ export const pageScreenTestData: ProcessorTestData[] = [
params: {},
FORM: {
data: [
'{"user_data":{"external_id":"470582f368e5aeec2cf487decd1e125b7d265e8b0b06b74a25e999e93bfb699f"},"event_name":"PageView","event_time":1697297576,"event_source_url":"jkl","action_source":"website","custom_data":{"path":"/abc","referrer":"xyz","search":"def","title":"ghi","url":"jkl"}}',
JSON.stringify({
user_data: {
external_id:
'470582f368e5aeec2cf487decd1e125b7d265e8b0b06b74a25e999e93bfb699f',
},
event_name: 'PageView',
event_time: 1697297576,
event_source_url: 'jkl',
action_source: 'website',
custom_data: {
path: '/abc',
referrer: 'xyz',
search: 'def',
title: 'ghi',
url: 'jkl',
},
}),
],
},
files: {},
Expand Down Expand Up @@ -582,7 +598,23 @@ export const pageScreenTestData: ProcessorTestData[] = [
params: {},
FORM: {
data: [
'{"user_data":{"external_id":"470582f368e5aeec2cf487decd1e125b7d265e8b0b06b74a25e999e93bfb699f"},"event_name":"PageView","event_time":1697297576,"event_source_url":"jkl","action_source":"website","custom_data":{"path":"/abc","referrer":"xyz","search":"def","title":"ghi","url":"jkl"}}',
JSON.stringify({
user_data: {
external_id:
'470582f368e5aeec2cf487decd1e125b7d265e8b0b06b74a25e999e93bfb699f',
},
event_name: 'PageView',
event_time: 1697297576,
event_source_url: 'jkl',
action_source: 'website',
custom_data: {
path: '/abc',
referrer: 'xyz',
search: 'def',
title: 'ghi',
url: 'jkl',
},
}),
],
},
files: {},
Expand Down
Loading

0 comments on commit 7cf683b

Please sign in to comment.