Skip to content

Commit

Permalink
fix: adding ecomm test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Feb 20, 2024
1 parent caa8d45 commit 308c64c
Show file tree
Hide file tree
Showing 6 changed files with 1,165 additions and 5 deletions.
109 changes: 108 additions & 1 deletion src/v0/util/facebookUtils/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const { transformedPayloadData, fetchUserData, deduceFbcParam } = require('./index');
const {
transformedPayloadData,
fetchUserData,
deduceFbcParam,
getContentType,
} = require('./index');
const sha256 = require('sha256');
const { MAPPING_CONFIG, CONFIG_CATEGORIES } = require('../../destinations/facebook_pixel/config');

Expand Down Expand Up @@ -532,3 +537,105 @@ describe('fetchUserData', () => {
});
});
});

describe('getContentType', () => {
// Returns default value when no category or categoryToContent is provided
it('should return default value when no category or categoryToContent is provided', () => {
const message = {
properties: {
produtcs: [
{
product_id: '123',
},
],
},
};
const defaultValue = 'product';
const categoryToContent = [];
const destinationName = 'fb_pixel';

const result = getContentType(message, defaultValue, categoryToContent, destinationName);

expect(result).toBe(defaultValue);
});

// Returns default value when categoryToContent is not an array
it('should return default value when categoryToContent is not an array', () => {
const message = {
properties: {
products: [
{
product_id: '123',
},
],
},
};
const defaultValue = 'product';
const categoryToContent = 'not an array';
const destinationName = 'fb_pixel';

const result = getContentType(message, defaultValue, categoryToContent, destinationName);

expect(result).toBe(defaultValue);
});

// Returns categoryToContent value when category is provided and matches with categoryToContent
it('should return categoryToContent value when category is provided and matches with categoryToContent', () => {
const message = {
properties: {
category: 'clothing',
},
};
const defaultValue = 'product';
const categoryToContent = [{ from: 'clothing', to: 'garments' }];
const destinationName = 'fb_pixel';

const result = getContentType(message, defaultValue, categoryToContent, destinationName);

expect(result).toBe(categoryToContent[0].to);
});

// Returns integrationsObj.contentType when it exists
it('should return integrationsObj.contentType when it exists', () => {
const message = {
properties: {
products: [
{
product_id: '123',
},
],
},
integrations: {
fb_pixel: {
contentType: 'content_type_value',
},
},
};
const defaultValue = 'product';
const categoryToContent = [];
const destinationName = 'fb_pixel';
const integrationsObj = {
contentType: 'content_type_value',
};

const result = getContentType(message, defaultValue, categoryToContent, destinationName);

expect(result).toBe(integrationsObj.contentType);
});

// Returns 'product' when category is 'clothing' and categoryToContent is not provided
it("should return 'product' when category is 'clothing' and categoryToContent is not provided", () => {
const message = {
properties: {
category: 'clothing',
},
};
const defaultValue = 'product';
const categoryToContent = [];
const destinationName = 'fb_pixel';

const result = getContentType(message, defaultValue, categoryToContent, destinationName);

expect(result).toBe(defaultValue);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import { VERSION } from '../../../../../src/v0/destinations/facebook_pixel/config';
// TODO: 1) category to content via integrations object , 2) PII properties allowlist deny list , 3) use updated mapping
import { removeUndefinedAndNullValues } from '@rudderstack/integrations-lib';
import {
overrideDestination,
transformResultBuilder,
generateSimplifiedIdentifyPayload,
generateTrackPayload,
} from '../../../testUtils';

const commonDestination = {
Config: {
limitedDataUSage: true,
blacklistPiiProperties: [
{
blacklistPiiProperties: '',
blacklistPiiHash: false,
},
],
accessToken: '09876',
pixelId: 'dummyPixelId',
eventsToEvents: [
{
from: 'ABC Started',
to: 'InitiateCheckout',
},
],
eventCustomProperties: [
{
eventCustomProperties: '',
},
],
valueFieldIdentifier: '',
advancedMapping: false,
whitelistPiiProperties: [
{
whitelistPiiProperties: 'email',
},
],
categoryToContent: [
{
from: 'clothing',
to: 'newClothing',
},
],
},
Enabled: true,
};

const commonUserTraits = {
email: '[email protected]',
anonymousId: 'c82cbdff-e5be-4009-ac78-cdeea09ab4b1',
event_id: '12345',
};

const commonPropertiesWithoutProductArray = {
category: 'dummy',
quantity: 10,
value: 100,
product_id: '12345',
};

const commonTimestamp = new Date('2023-10-14');

export const configLevelFeaturesTestData = [
{
name: 'facebook_pixel',
description: 'config feature : limitedDataUSage switched on',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
message: generateTrackPayload({
event: 'product list viewed',
properties: commonPropertiesWithoutProductArray,
context: {
traits: commonUserTraits,
dataProcessingOptions: ['val1', 'val2', 'val3'],
},
timestamp: commonTimestamp,
}),
destination: commonDestination,
},
],
},
},
output: {
response: {
status: 200,
body: [
{
output: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: `https://graph.facebook.com/${VERSION}/dummyPixelId/events?access_token=09876`,
headers: {},
params: {},
body: {
JSON: {},
JSON_ARRAY: {},
XML: {},
FORM: {
data: [
'{"user_data":{"external_id":"3ffc8a075f330402d82aa0a86c596b0d2fe70df38b22c5be579f86a18e4aca47","em":"48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08","client_user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0"},"event_name":"ViewContent","event_time":1697241600,"event_id":"12345","action_source":"website","data_processing_options":"val1","data_processing_options_country":"val2","data_processing_options_state":"val3","custom_data":{"category":"dummy","quantity":10,"value":100,"product_id":"12345","content_ids":["dummy"],"content_type":"product_group","contents":[{"id":"dummy","quantity":1}],"content_category":"dummy","currency":"USD"}}',
],
},
},
files: {},
userId: '',
},
statusCode: 200,
},
],
},
},
},
{
name: 'facebook_pixel',
description:
'config feature : ContentCategoryMapping table is filled up, but category is passed with properties',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
message: generateTrackPayload({
event: 'product list viewed',
properties: { ...commonPropertiesWithoutProductArray, category: 'clothing' },
context: {
traits: commonUserTraits,
dataProcessingOptions: ['val1', 'val2', 'val3'],
},
timestamp: commonTimestamp,
}),
destination: commonDestination,
},
],
},
},
output: {
response: {
status: 200,
body: [
{
output: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: `https://graph.facebook.com/${VERSION}/dummyPixelId/events?access_token=09876`,
headers: {},
params: {},
body: {
JSON: {},
JSON_ARRAY: {},
XML: {},
FORM: {
data: [
'{"user_data":{"external_id":"3ffc8a075f330402d82aa0a86c596b0d2fe70df38b22c5be579f86a18e4aca47","em":"48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08","client_user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0"},"event_name":"ViewContent","event_time":1697241600,"event_id":"12345","action_source":"website","data_processing_options":"val1","data_processing_options_country":"val2","data_processing_options_state":"val3","custom_data":{"category":"clothing","quantity":10,"value":100,"product_id":"12345","content_ids":["clothing"],"content_type":"newClothing","contents":[{"id":"clothing","quantity":1}],"content_category":"clothing","currency":"USD"}}',
],
},
},
files: {},
userId: '',
},
statusCode: 200,
},
],
},
},
},
];
12 changes: 8 additions & 4 deletions test/integrations/destinations/facebook_pixel/processor/data.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// import { ecomTestData } from './ecomTestData';
// import { identifyTestData } from './identifyTestData';
// import { trackTestData } from './trackTestData';
import { trackTestData } from './trackTestData';
// import { validationTestData } from './validationTestData';
import { pageScreenTestData } from './pageScreenTestData';
// import { pageScreenTestData } from './pageScreenTestData';
import { ecommTestData } from './ecommTestData';
import { configLevelFeaturesTestData } from './configLevelFeaturesTestData';

export const mockFns = (_) => {
// @ts-ignore
Expand All @@ -11,8 +13,10 @@ export const mockFns = (_) => {

export const data = [
//...identifyTestData,
// ...trackTestData,
//...trackTestData,
// ...ecomTestData,
// ...validationTestData,
...pageScreenTestData,
// ...pageScreenTestData,
// ...ecommTestData,
...configLevelFeaturesTestData,
].map((d) => ({ ...d, mockFns }));
Loading

0 comments on commit 308c64c

Please sign in to comment.