From db86b2c445934037c2cb824e0bd54db3c0ebc59b Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Sun, 18 Aug 2024 20:43:49 +0530 Subject: [PATCH 1/3] fix: fixing facebook utils --- src/v0/util/facebookUtils/index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/v0/util/facebookUtils/index.js b/src/v0/util/facebookUtils/index.js index 7462320cca..0787c1fb0a 100644 --- a/src/v0/util/facebookUtils/index.js +++ b/src/v0/util/facebookUtils/index.js @@ -148,11 +148,14 @@ const getContentType = (message, defaultValue, categoryToContent, destinationNam } let { category } = properties || {}; - if (!category) { - const { products } = properties; - if (products && products.length > 0 && Array.isArray(products) && isObject(products[0])) { - category = products[0].category; - } + if ( + !category && + properties?.products && + properties?.products.length > 0 && + Array.isArray(properties?.products) && + isObject(properties?.products[0]) + ) { + category = properties?.products[0].category; } if (Array.isArray(categoryToContent) && category) { From b02031191aac43204d4de7e6957b5a080928acf9 Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Sun, 18 Aug 2024 20:52:07 +0530 Subject: [PATCH 2/3] fix: adding test cases --- src/v0/util/facebookUtils/index.test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/v0/util/facebookUtils/index.test.js b/src/v0/util/facebookUtils/index.test.js index 1a2de4ed12..90588c627b 100644 --- a/src/v0/util/facebookUtils/index.test.js +++ b/src/v0/util/facebookUtils/index.test.js @@ -639,6 +639,21 @@ describe('getContentType', () => { expect(result).toBe(defaultValue); }); + + it('should return default value when no product array or categoryToContent is provided', () => { + const message = { + properties: { + revenue: 1234, + }, + }; + const defaultValue = 'product'; + const categoryToContent = []; + const destinationName = 'fb_pixel'; + + const result = getContentType(message, defaultValue, categoryToContent, destinationName); + + expect(result).toBe(defaultValue); + }); }); describe('isHtmlFormat', () => { From 376b4423fc6886da2c2114c31dc26ee2600189e5 Mon Sep 17 00:00:00 2001 From: shrouti1507 <60211312+shrouti1507@users.noreply.github.com> Date: Tue, 20 Aug 2024 11:16:45 +0530 Subject: [PATCH 3/3] fix: review comments addressed Co-authored-by: Anant Jain <62471433+anantjain45823@users.noreply.github.com> --- src/v0/util/facebookUtils/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/v0/util/facebookUtils/index.js b/src/v0/util/facebookUtils/index.js index 0787c1fb0a..fd94db442b 100644 --- a/src/v0/util/facebookUtils/index.js +++ b/src/v0/util/facebookUtils/index.js @@ -150,9 +150,8 @@ const getContentType = (message, defaultValue, categoryToContent, destinationNam let { category } = properties || {}; if ( !category && - properties?.products && - properties?.products.length > 0 && Array.isArray(properties?.products) && + properties?.products.length > 0 && isObject(properties?.products[0]) ) { category = properties?.products[0].category;