Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removing device token from if condition in mixpanel destination #3982

Merged
merged 5 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/v0/destinations/mp/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ const getTransformedJSON = (message, mappingJson, useNewMapping) => {
}

const device = get(message, 'context.device');
if (device && device.token) {
if (device) {
let payload;
const deviceTokenArray = isDefined(device.token) ? [device.token] : [];
manish339k marked this conversation as resolved.
Show resolved Hide resolved
if (isAppleFamily(device.type)) {
payload = constructPayload(message, mPProfileIosConfigJson);
rawPayload.$ios_devices = [device.token];
rawPayload.$ios_devices = deviceTokenArray;
} else if (device.type.toLowerCase() === 'android') {
payload = constructPayload(message, mPProfileAndroidConfigJson);
rawPayload.$android_devices = [device.token];
rawPayload.$android_devices = deviceTokenArray;
}
rawPayload = { ...rawPayload, ...payload };
}
Expand Down Expand Up @@ -373,4 +374,5 @@ module.exports = {
trimTraits,
generatePageOrScreenCustomEventName,
recordBatchSizeMetrics,
getTransformedJSON,
};
175 changes: 175 additions & 0 deletions src/v0/destinations/mp/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ const {
buildUtmParams,
trimTraits,
generatePageOrScreenCustomEventName,
getTransformedJSON,
} = require('./util');
const { FEATURE_GZIP_SUPPORT } = require('../../util/constant');
const { ConfigurationError } = require('@rudderstack/integrations-lib');
const { mappingConfig, ConfigCategory } = require('./config');

const maxBatchSizeMock = 2;

Expand Down Expand Up @@ -489,3 +491,176 @@ describe('generatePageOrScreenCustomEventName', () => {
expect(result).toBe(expected);
});
});

describe('Unit test cases for getTransformedJSON', () => {
it('should transform the message payload to appropriate payload if device.token is present', () => {
const message = {
context: {
app: {
build: '1',
name: 'LeanPlumIntegrationAndroid',
namespace: 'com.android.SampleLeanPlum',
version: '1.0',
},
device: {
id: '5094f5704b9cf2b3',
manufacturer: 'Google',
model: 'Android SDK built for x86',
name: 'generic_x86',
type: 'ios',
token: 'test_device_token',
},
network: { carrier: 'Android', bluetooth: false, cellular: true, wifi: true },
os: { name: 'iOS', version: '8.1.0' },
timezone: 'Asia/Kolkata',
traits: { userId: 'test_user_id' },
},
};
const result = getTransformedJSON(message, mappingConfig[ConfigCategory.IDENTIFY.name], true);

const expectedResult = {
$carrier: 'Android',
$manufacturer: 'Google',
$model: 'Android SDK built for x86',
$wifi: true,
userId: 'test_user_id',
$ios_devices: ['test_device_token'],
$os: 'iOS',
$ios_device_model: 'Android SDK built for x86',
$ios_version: '8.1.0',
$ios_app_release: '1',
$ios_app_version: '1.0',
};

expect(result).toEqual(expectedResult);
});

it('should transform the message payload to appropriate payload if device.token is present and device.token is null or other value', () => {
const message = {
context: {
app: {
build: '1',
name: 'LeanPlumIntegrationAndroid',
namespace: 'com.android.SampleLeanPlum',
version: '1.0',
},
device: {
id: '5094f5704b9cf2b3',
manufacturer: 'Google',
model: 'Android SDK built for x86',
name: 'generic_x86',
type: 'android',
token: null,
},
network: { carrier: 'Android', bluetooth: false, cellular: true, wifi: true },
os: { name: 'Android', version: '8.1.0' },
timezone: 'Asia/Kolkata',
traits: { userId: 'test_user_id' },
},
};
const result = getTransformedJSON(message, mappingConfig[ConfigCategory.IDENTIFY.name], true);

const expectedResult = {
$carrier: 'Android',
$manufacturer: 'Google',
$model: 'Android SDK built for x86',
$wifi: true,
userId: 'test_user_id',
$android_devices: [null],
$os: 'Android',
$android_model: 'Android SDK built for x86',
$android_os_version: '8.1.0',
$android_manufacturer: 'Google',
$android_app_version: '1.0',
$android_app_version_code: '1.0',
$android_brand: 'Google',
};

expect(result).toEqual(expectedResult);
});

it('should transform the message payload to appropriate payload if device.token is not present for apple device', () => {
const message = {
context: {
app: {
build: '1',
name: 'LeanPlumIntegrationAndroid',
namespace: 'com.android.SampleLeanPlum',
version: '1.0',
},
device: {
id: '5094f5704b9cf2b3',
manufacturer: 'Google',
model: 'Android SDK built for x86',
name: 'generic_x86',
type: 'ios',
},
network: { carrier: 'Android', bluetooth: false, cellular: true, wifi: true },
os: { name: 'iOS', version: '8.1.0' },
timezone: 'Asia/Kolkata',
traits: { userId: 'test_user_id' },
},
};
const result = getTransformedJSON(message, mappingConfig[ConfigCategory.IDENTIFY.name], true);

const expectedResult = {
$carrier: 'Android',
$manufacturer: 'Google',
$model: 'Android SDK built for x86',
$wifi: true,
userId: 'test_user_id',
$ios_devices: [],
$os: 'iOS',
$ios_device_model: 'Android SDK built for x86',
$ios_version: '8.1.0',
$ios_app_release: '1',
$ios_app_version: '1.0',
};

expect(result).toEqual(expectedResult);
});

it('should transform the message payload to appropriate payload if device.token is not present for android device', () => {
const message = {
context: {
app: {
build: '1',
name: 'LeanPlumIntegrationAndroid',
namespace: 'com.android.SampleLeanPlum',
version: '1.0',
},
device: {
id: '5094f5704b9cf2b3',
manufacturer: 'Google',
model: 'Android SDK built for x86',
name: 'generic_x86',
type: 'android',
token: undefined,
},
network: { carrier: 'Android', bluetooth: false, cellular: true, wifi: true },
os: { name: 'Android', version: '8.1.0' },
timezone: 'Asia/Kolkata',
traits: { userId: 'test_user_id' },
},
};
const result = getTransformedJSON(message, mappingConfig[ConfigCategory.IDENTIFY.name], true);

const expectedResult = {
$carrier: 'Android',
$manufacturer: 'Google',
$model: 'Android SDK built for x86',
$wifi: true,
userId: 'test_user_id',
$android_devices: [],
manish339k marked this conversation as resolved.
Show resolved Hide resolved
$os: 'Android',
$android_model: 'Android SDK built for x86',
$android_os_version: '8.1.0',
$android_manufacturer: 'Google',
$android_app_version: '1.0',
$android_app_version_code: '1.0',
$android_brand: 'Google',
};

expect(result).toEqual(expectedResult);
});
});
Loading