Skip to content

Commit

Permalink
chore: refactor, address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yashasvibajpai committed Nov 6, 2023
1 parent a0d5bb5 commit 00229e2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 51 deletions.
14 changes: 6 additions & 8 deletions src/v0/sources/revenuecat/transform.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
const { camelCase } = require('lodash');
const path = require('path');
const fs = require('fs');
const moment = require('moment');
const { removeUndefinedAndNullValues, isDefinedAndNotNull } = require('../../util');
const Message = require('../message');

// import mapping json using JSON.parse to preserve object key order
const mapping = JSON.parse(fs.readFileSync(path.resolve(__dirname, './mapping.json'), 'utf-8'));

function process(event) {
const message = new Message(`RevenueCat`);

Expand All @@ -23,8 +18,6 @@ function process(event) {
message.setProperty('properties', properties);
}

message.setPropertiesV2(event, mapping);

// setting up app_user_id to externalId : revenuecatAppUserId
if (event?.event?.app_user_id) {
message.context.externalId = [
Expand All @@ -35,11 +28,16 @@ function process(event) {
];
}

if (isDefinedAndNotNull(event?.event?.event_timestamp_ms) && moment(event?.event?.event_timestamp_ms).isValid()) {
if (
isDefinedAndNotNull(event?.event?.event_timestamp_ms) &&
moment(event?.event?.event_timestamp_ms).isValid()
) {
const validTimestamp = new Date(event.event.event_timestamp_ms).toISOString();
message.setProperty('originalTimestamp', validTimestamp);
message.setProperty('sentAt', validTimestamp);
}
message.event = event?.event?.type;
message.messageId = event?.event?.id;

// removing undefined and null values from message
removeUndefinedAndNullValues(message);
Expand Down
78 changes: 35 additions & 43 deletions test/integrations/sources/revenuecat/data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const data = [
export const data = [
{
name: 'revenuecat',
description: 'Simple track call',
Expand Down Expand Up @@ -164,46 +164,42 @@ const data = [
request: {
body: [
{
batch: [
{
api_version: '1.0',
event: {
aliases: ['yourCustomerAliasedID', 'yourCustomerAliasedID'],
app_id: 'yourAppID',
app_user_id: 'yourCustomerAppUserID',
commission_percentage: 0.3,
country_code: 'US',
currency: 'USD',
entitlement_id: 'pro_cat',
entitlement_ids: ['pro_cat'],
environment: 'PRODUCTION',
event_timestamp_ms: 1591121855319,
expiration_at_ms: 1591726653000,
id: 'UniqueIdentifierOfEvent',
is_family_share: false,
offer_code: 'free_month',
original_app_user_id: 'OriginalAppUserID',
original_transaction_id: '1530648507000',
period_type: 'NORMAL',
presented_offering_id: 'OfferingID',
price: 2.49,
price_in_purchased_currency: 2.49,
product_id: 'onemonth_no_trial',
purchased_at_ms: 1591121853000,
store: 'APP_STORE',
subscriber_attributes: {
'$Favorite Cat': {
updated_at_ms: 1581121853000,
value: 'Garfield',
},
},
takehome_percentage: 0.7,
tax_percentage: 0.3,
transaction_id: '170000869511114',
type: 'INITIAL_PURCHASE',
api_version: '1.0',
event: {
aliases: ['yourCustomerAliasedID', 'yourCustomerAliasedID'],
app_id: 'yourAppID',
app_user_id: 'yourCustomerAppUserID',
commission_percentage: 0.3,
country_code: 'US',
currency: 'USD',
entitlement_id: 'pro_cat',
entitlement_ids: ['pro_cat'],
environment: 'PRODUCTION',
event_timestamp_ms: 1591121855319,
expiration_at_ms: 1591726653000,
id: 'UniqueIdentifierOfEvent',
is_family_share: false,
offer_code: 'free_month',
original_app_user_id: 'OriginalAppUserID',
original_transaction_id: '1530648507000',
period_type: 'NORMAL',
presented_offering_id: 'OfferingID',
price: 2.49,
price_in_purchased_currency: 2.49,
product_id: 'onemonth_no_trial',
purchased_at_ms: 1591121853000,
store: 'APP_STORE',
subscriber_attributes: {
'$Favorite Cat': {
updated_at_ms: 1581121853000,
value: 'Garfield',
},
},
],
takehome_percentage: 0.7,
tax_percentage: 0.3,
transaction_id: '170000869511114',
type: 'INITIAL_PURCHASE',
},
},
],
method: 'POST',
Expand Down Expand Up @@ -288,7 +284,3 @@ const data = [
},
},
];

module.exports = {
data,
};

0 comments on commit 00229e2

Please sign in to comment.