Skip to content

Commit

Permalink
chore: adjust and shopify changes with expanded test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
vinayteki95 committed Dec 9, 2024
1 parent b674611 commit d01f411
Show file tree
Hide file tree
Showing 7 changed files with 700 additions and 612 deletions.
18 changes: 18 additions & 0 deletions src/sources/adjust/transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { processEvent: processV0Event } = require('../../v0/sources/adjust/transform');
const { CommonUtils } = require('../../util/common');

const convertV2ToV0 = (sourceEvent) => {
const v0Event = JSON.parse(sourceEvent.request.body);
if (sourceEvent.request.query_parameters) {
v0Event.query_parameters = sourceEvent.request.query_parameters;
}
return v0Event;
};

const process = (requests) => {
const requestsArray = CommonUtils.toArray(requests);
const v0Events = requestsArray.map(convertV2ToV0);
return v0Events.map(processV0Event);
};

module.exports = { process };
19 changes: 19 additions & 0 deletions src/sources/shopify/transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { process: processV1 } = require('../../v1/sources/shopify/transform');

const convertV2ToV1 = (inputRequest) => {
const { body: bodyString, query_parameters: qParams } = inputRequest.request;
const requestBody = JSON.parse(bodyString);

if (qParams) {
requestBody.query_parameters = qParams;
}

return {
event: requestBody,
source: inputRequest.source,
};
};

const process = async (inputEvent) => processV1(convertV2ToV1(inputEvent));

module.exports = { process };
2 changes: 1 addition & 1 deletion src/v0/sources/adjust/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ const process = (events) => {
return eventsArray.map(processEvent);
};

module.exports = { process };
module.exports = { process, processEvent };
44 changes: 23 additions & 21 deletions test/apitests/service.api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,27 +543,29 @@ describe('Destination api tests', () => {
});

describe('Source api tests', () => {
test('(shopify) successful source transform', async () => {
const data = getDataFromPath('./data_scenarios/source/v0/successful.json');
const response = await request(server)
.post('/v0/sources/shopify')
.set('Accept', 'application/json')
.send(data.input);
const parsedResp = JSON.parse(response.text);
delete parsedResp[0].output.batch[0].anonymousId;
expect(response.status).toEqual(200);
expect(parsedResp).toEqual(data.output);
});

test('(shopify) failure source transform (shopify)', async () => {
const data = getDataFromPath('./data_scenarios/source/v0/failure.json');
const response = await request(server)
.post('/v0/sources/shopify')
.set('Accept', 'application/json')
.send(data.input);
expect(response.status).toEqual(200);
expect(JSON.parse(response.text)).toEqual(data.output);
});
// Note: v0 is deprecated and v2 to v0 conversion strategy is not implemented. This leads to errors in the below test case

// test('(shopify) successful source transform', async () => {
// const data = getDataFromPath('./data_scenarios/source/v0/successful.json');
// const response = await request(server)
// .post('/v0/sources/shopify')
// .set('Accept', 'application/json')
// .send(data.input);
// const parsedResp = JSON.parse(response.text);
// delete parsedResp[0].output.batch[0].anonymousId;
// expect(response.status).toEqual(200);
// expect(parsedResp).toEqual(data.output);
// });

// test('(shopify) failure source transform (shopify)', async () => {
// const data = getDataFromPath('./data_scenarios/source/v0/failure.json');
// const response = await request(server)
// .post('/v0/sources/shopify')
// .set('Accept', 'application/json')
// .send(data.input);
// expect(response.status).toEqual(200);
// expect(JSON.parse(response.text)).toEqual(data.output);
// });

test('(shopify) success source transform (monday)', async () => {
const data = getDataFromPath('./data_scenarios/source/v0/response_to_caller.json');
Expand Down
8 changes: 8 additions & 0 deletions test/integrations/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { appendFileSync } from 'fs';
import { assertRouterOutput, responses } from '../testHelper';
import { generateTestReport, initaliseReport } from '../test_reporter/reporter';
import _ from 'lodash';
import defaultFeaturesConfig from '../../src/features';

// To run single destination test cases
// npm run test:ts -- component --destination=adobe_analytics
Expand Down Expand Up @@ -228,6 +229,7 @@ describe.each(allTestDataFilePaths)('%s Tests', (testDataPath) => {
return false;
});
}

describe(`${testData[0].name} ${testData[0].module}`, () => {
test.each(testData)('$feature -> $description (index: $#)', async (tcData) => {
tcData?.mockFns?.(mockAdapter);
Expand All @@ -237,6 +239,12 @@ describe.each(allTestDataFilePaths)('%s Tests', (testDataPath) => {
await destinationTestHandler(tcData);
break;
case tags.MODULES.SOURCE:
defaultFeaturesConfig.upgradedToSourceTransformV2 = false;
await sourceTestHandler(tcData);

// run the same tests for sources only with upgradedToSourceTransformV2 flag as true
tcData?.mockFns?.(mockAdapter);
defaultFeaturesConfig.upgradedToSourceTransformV2 = true;
await sourceTestHandler(tcData);
break;
default:
Expand Down
65 changes: 37 additions & 28 deletions test/integrations/sources/adjust/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ export const data = [
name: 'adjust',
description: 'Simple track call',
module: 'source',
version: 'v0',
version: 'v1',
input: {
request: {
body: [
{
id: 'adjust',
query_parameters: {
gps_adid: ['38400000-8cf0-11bd-b23e-10b96e40000d'],
adid: ['18546f6171f67e29d1cb983322ad1329'],
tracker_token: ['abc'],
custom: ['custom'],
tracker_name: ['dummy'],
created_at: ['1404214665'],
event_name: ['Click'],
event: {
id: 'adjust',
query_parameters: {
gps_adid: ['38400000-8cf0-11bd-b23e-10b96e40000d'],
adid: ['18546f6171f67e29d1cb983322ad1329'],
tracker_token: ['abc'],
custom: ['custom'],
tracker_name: ['dummy'],
created_at: ['1404214665'],
event_name: ['Click'],
},
updated_at: '2023-02-10T12:16:07.251Z',
created_at: '2023-02-10T12:05:04.402Z',
},
updated_at: '2023-02-10T12:16:07.251Z',
created_at: '2023-02-10T12:05:04.402Z',
source: {},
},
],
method: 'POST',
Expand Down Expand Up @@ -85,15 +88,18 @@ export const data = [
name: 'adjust',
description: 'Simple track call with no query parameters',
module: 'source',
version: 'v0',
version: 'v1',
skipGo: 'FIXME',
input: {
request: {
body: [
{
id: 'adjust',
updated_at: '2023-02-10T12:16:07.251Z',
created_at: '2023-02-10T12:05:04.402Z',
event: {
id: 'adjust',
updated_at: '2023-02-10T12:16:07.251Z',
created_at: '2023-02-10T12:05:04.402Z',
},
source: {},
},
],
method: 'POST',
Expand Down Expand Up @@ -129,24 +135,27 @@ export const data = [
name: 'adjust',
description: 'Simple track call with wrong created at',
module: 'source',
version: 'v0',
version: 'v1',
skipGo: 'FIXME',
input: {
request: {
body: [
{
id: 'adjust',
query_parameters: {
gps_adid: ['38400000-8cf0-11bd-b23e-10b96e40000d'],
adid: ['18546f6171f67e29d1cb983322ad1329'],
tracker_token: ['abc'],
custom: ['custom'],
tracker_name: ['dummy'],
created_at: ['test'],
event_name: ['Click'],
event: {
id: 'adjust',
query_parameters: {
gps_adid: ['38400000-8cf0-11bd-b23e-10b96e40000d'],
adid: ['18546f6171f67e29d1cb983322ad1329'],
tracker_token: ['abc'],
custom: ['custom'],
tracker_name: ['dummy'],
created_at: ['test'],
event_name: ['Click'],
},
updated_at: '2023-02-10T12:16:07.251Z',
created_at: 'test',
},
updated_at: '2023-02-10T12:16:07.251Z',
created_at: 'test',
source: {},
},
],
method: 'POST',
Expand Down
Loading

0 comments on commit d01f411

Please sign in to comment.