Skip to content

Commit

Permalink
chore: comments addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 committed Nov 1, 2023
1 parent e650cbd commit f4d14d0
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/v0/destinations/am/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const handleTraits = (messageTrait, destination) => {
const getScreenevTypeAndUpdatedProperties = (message, CATEGORY_KEY) => {
const name = message.name || message.event || get(message, CATEGORY_KEY);
return {
evType: `Viewed ${name || ''} Screen`,
evType: `Viewed ${name ? `${name} ` : ''}Screen`,
updatedProperties: {
...message.properties,
name,
Expand Down Expand Up @@ -322,7 +322,7 @@ const getDefaultResponseData = (message, rawPayload, evType, groupInfo) => {
delete rawPayload.event_properties.revenue;
}
}
const groups = groupInfo && Object.assign(groupInfo);
const groups = groupInfo && cloneDeep(groupInfo);
return { groups, rawPayload };
};
const getResponseData = (evType, destination, rawPayload, message, groupInfo) => {
Expand Down Expand Up @@ -389,12 +389,7 @@ const nonAliasResponsebuilder = (
payload.time = new Date(getFieldValueFromMessage(message, 'timestamp')).getTime();

// send user_id only when present, for anonymous users not required
if (
message.userId &&
message.userId !== '' &&
message.userId !== 'null' &&
message.userId !== null
) {
if (message.userId && message.userId !== null) {
payload.user_id = message.userId;
}
payload.session_id = getSessionId(message);
Expand Down Expand Up @@ -554,10 +549,9 @@ const responseBuilderSimple = (
};

const getGroupInfo = (destination, groupInfo, groupTraits) => {
let updatedGroupInfo = { ...groupInfo };
const groupTypeTrait = get(destination, 'Config.groupTypeTrait');
const groupValueTrait = get(destination, 'Config.groupValueTrait');
const { groupTypeTrait, groupValueTrait } = destination.Config;
if (groupTypeTrait && groupValueTrait) {
let updatedGroupInfo = { ...groupInfo };
const groupTypeValue = get(groupTraits, groupTypeTrait);
const groupNameValue = get(groupTraits, groupValueTrait);
// since the property updates on group at https://api2.amplitude.com/groupidentify
Expand Down Expand Up @@ -730,7 +724,7 @@ const getProductPurchasedEvents = (message, destination) => {

const trackRevenueEvent = (message, destination) => {
let sendEvents = [];
const originalEvent = JSON.parse(JSON.stringify(message));
const originalEvent = cloneDeep(message);

if (destination.Config.trackProductsOnce === false) {
if (isProductArrayInPayload(message)) {
Expand Down Expand Up @@ -830,10 +824,7 @@ const getBatchEvents = (message, destination, metadata, batchEventResponse) => {
if (batchEventArray.length === 0) {
if (JSON.stringify(incomingMessageJSON).length < AMBatchSizeLimit) {
delete message.body.JSON.options;
Object.assign(batchEventResponse, {
batchedRequest: message,
});

batchEventResponse.batchedRequest = message;
set(batchEventResponse, 'batchedRequest.endpoint', BATCH_ENDPOINT);
batchEventResponse.metadata = [metadata];
}
Expand Down
63 changes: 63 additions & 0 deletions test/__tests__/data/am_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -4262,6 +4262,69 @@
}
}
},
{
"message": {
"anonymousId": "5d205961641ee6c5",
"channel": "mobile",
"context": {
"app": {
"build": "6",
"name": "Sample Kotlin",
"namespace": "com.example.testapp1mg",
"version": "1.2"
},
"device": {
"id": "5d205961641ee6c5",
"manufacturer": "Google",
"model": "Android SDK built for x86",
"name": "generic_x86",
"type": "Android"
},
"library": {
"name": "com.rudderstack.android.sdk.core",
"version": "1.7.0"
},
"locale": "en-US",
"network": {
"carrier": "Android",
"bluetooth": false,
"cellular": true,
"wifi": true
},
"os": {
"name": "Android",
"version": "7.1.1"
},
"screen": {
"density": 440,
"height": 2148,
"width": 1080
},
"sessionId": "1662393792",
"timezone": "Asia/Kolkata",
"traits": {
"anonymousId": "5d205961641ee6c5",
"id": "User Android",
"userId": "User Android"
},
"userAgent": "Dalvik/2.1.0 (Linux; U; Android 7.1.1; Android SDK built for x86 Build/NYC)"
},
"integrations": {
"All": true
},
"messageId": "1662393883248-509420bf-b812-4f8d-bdb2-8c811bfde87f",
"properties": {
},
"originalTimestamp": "2022-09-05T16:04:43.250Z",
"type": "screen",
"userId": "User Android"
},
"destination": {
"Config": {
"apiKey": "abcde"
}
}
},
{
"message": {
"channel": "web",
Expand Down
51 changes: 51 additions & 0 deletions test/__tests__/data/am_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -3913,6 +3913,57 @@
"files": {},
"userId": "5d205961641ee6c5"
},
{
"version": "1",
"type": "REST",
"method": "POST",
"endpoint": "https://api2.amplitude.com/2/httpapi",
"headers": {
"Content-Type": "application/json"
},
"params": {},
"body": {
"JSON": {
"api_key": "abcde",
"events": [
{
"os_name": "Android",
"os_version": "7.1.1",
"device_model": "Android SDK built for x86",
"device_manufacturer": "Google",
"device_id": "5d205961641ee6c5",
"carrier": "Android",
"app_name": "Sample Kotlin",
"app_version": "1.2",
"platform": "Android",
"language": "en-US",
"event_properties": {
},
"insert_id": "1662393883248-509420bf-b812-4f8d-bdb2-8c811bfde87f",
"user_properties": {
"anonymousId": "5d205961641ee6c5",
"id": "User Android",
"userId": "User Android"
},
"event_type": "Viewed Screen",
"user_id": "User Android",
"device_brand": "Google",
"time": 1662393883250,
"session_id": 1662393792,
"library": "rudderstack"
}
],
"options": {
"min_id_length": 1
}
},
"JSON_ARRAY": {},
"XML": {},
"FORM": {}
},
"files": {},
"userId": "5d205961641ee6c5"
},
{
"version": "1",
"type": "REST",
Expand Down

0 comments on commit f4d14d0

Please sign in to comment.