Skip to content

Commit

Permalink
chore: refactor code and add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSudip committed Nov 5, 2024
1 parent 1940de4 commit 94b73fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
36 changes: 17 additions & 19 deletions src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ steps:
"event_id": $.getOneByPaths(., ^.destination.Config.deduplicationKey) ?? .messageId,
"app_id": ^.destination.Config.appId,
"advertiser_id": ^.destination.Config.advertiserId,
"partner_name": .properties.partnerName ? String(.properties.partnerName) : undefined,
"device_carrier": .properties.partnerName ? String(.context.network.carrier) : undefined,
"wifi": .context.network.wifi ? Boolean(.context.network.wifi) : undefined
"partner_name": .properties.partnerName ? String(.properties.partnerName),
"device_carrier": .properties.partnerName ? String(.context.network.carrier),
"wifi": .context.network.wifi ? Boolean(.context.network.wifi)
});
$.outputs.apiVersion === {{$.API_VERSION.v5}} ? commonFields = commonFields{~["advertiser_id"]};
$.removeUndefinedValues(commonFields)
Expand Down Expand Up @@ -107,7 +107,7 @@ steps:
"client_user_agent": .context.userAgent,
"external_id": {{{{$.getGenericPaths("userId")}}}},
"click_id": .properties.clickId,
"partner_id": .traits.partnerId ?? .context.traits.partnerId ? String(.traits.partnerId ?? .context.traits.partnerId) : undefined
"partner_id": .traits.partnerId ?? .context.traits.partnerId ? String(.traits.partnerId ?? .context.traits.partnerId)
});
!.destination.Config.sendExternalId ? userFields = userFields{~["external_id"]} : null;
userFields = $.removeUndefinedAndNullAndEmptyValues(userFields);
Expand All @@ -127,17 +127,15 @@ steps:
template: |
const customFields = .message.().({
"currency": .properties.currency,
"value": .properties.value !== undefined ? String(.properties.value) :
.properties.total !== undefined ? String(.properties.total) :
.properties.revenue !== undefined ? String(.properties.revenue) : undefined,
"value": (.properties.value ?? .properties.total ?? .properties.revenue) ? String(.properties.value ?? .properties.total ?? .properties.revenue),
"num_items": .properties.numOfItems && Number(.properties.numOfItems),
"order_id": .properties.order_id,
"search_string": .properties.query,
"opt_out_type": .properties.optOutType,
"content_name": .properties.contentName ? String(.properties.contentName) : undefined,
"content_category": .properties.contentCategory ? String(.properties.contentCategory) : undefined,
"content_brand": .properties.contentBrand ? String(.properties.contentBrand) : undefined,
"np": .properties.np ? String(.properties.np) : undefined
"content_name": .properties.contentName ? String(.properties.contentName),
"content_category": .properties.contentCategory ? String(.properties.contentCategory),
"content_brand": .properties.contentBrand ? String(.properties.contentBrand),
"np": .properties.np ? String(.properties.np)
});
$.removeUndefinedValues(customFields)
Expand All @@ -148,14 +146,14 @@ steps:
let products = .message.properties.products;
{
"num_items": $.sum(products.quantity.(Number(.))[]) || 0,
"content_ids": products.(.product_id ?? .sku ?? .id)[],
"content_ids": products.(String(.product_id ?? .sku ?? .id))[],
"contents": [email protected].({
"quantity": Number(.quantity ?? prop.quantity ?? 1),
"item_price": String(.price ?? prop.price),
"item_name": String(.name),
"id": .product_id ?? .sku ? String(.product_id ?? .sku) : undefined,
"item_category": .category ? String(.category) : undefined,
"item_brand": .brand ? String(.brand) : undefined
"id": .product_id ?? .sku ? String(.product_id ?? .sku),
"item_category": .category ? String(.category),
"item_brand": .brand ? String(.brand)
})[]
}
else:
Expand All @@ -164,14 +162,14 @@ steps:
const props = .message.properties;
const output = {
"num_items": Number(props.quantity) || 0,
"content_ids": (props.product_id ?? props.sku ?? props.id)[],
"content_ids": (props.product_id ?? props.sku ?? props.id) ? String(props.product_id ?? props.sku ?? props.id)[],
"contents": {
"quantity": Number(props.quantity) || 1,
"item_price": String(props.price),
"item_name": String(props.name),
"id": props.product_id ?? props.sku ? String(props.product_id ?? props.sku) : undefined,
"item_category": props.category ? String(props.category) : undefined,
"item_brand": props.brand ? String(props.brand) : undefined
"id": props.product_id ?? props.sku ? String(props.product_id ?? props.sku),
"item_category": props.category ? String(props.category),
"item_brand": props.brand ? String(props.brand)
}[]
};
- name: combineAllEcomFields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const data = [
library: { name: 'rudder-sdk-ruby-sync', version: '1.0.6' },
network: {
carrier: 'VI',
wifi: true,
wifi: 'true',
},
},
messageId: '7208bbb6-2c4e-45bb-bf5b-ad426f3593e9',
Expand Down Expand Up @@ -62,7 +62,7 @@ export const data = [
category: 'Games',
quantity: 1,
image_url: 'https:///www.example.com/product/path.jpg',
product_id: '507f1f77bcf86cd799439011',
product_id: 1234,
},
{
sku: '46493-32',
Expand Down Expand Up @@ -122,11 +122,11 @@ export const data = [
app_id: '429047995',
custom_data: {
content_brand: 'LV',
content_ids: ['507f1f77bcf86cd799439011', '505bd76785ebb509fc183733'],
content_ids: ['1234', '505bd76785ebb509fc183733'],
content_name: 'testContent',
contents: [
{
id: '507f1f77bcf86cd799439011',
id: '1234',
item_category: 'Games',
item_name: 'Monopoly: 3rd Edition',
item_price: '19',
Expand Down

0 comments on commit 94b73fa

Please sign in to comment.