Skip to content

Commit

Permalink
chore: test cases cover v2 spec respecting code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vinayteki95 committed Dec 12, 2024
1 parent 82e322d commit a8e7a40
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 47 deletions.
24 changes: 0 additions & 24 deletions test/apitests/service.api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,30 +543,6 @@ describe('Destination api tests', () => {
});

describe('Source api tests', () => {
// 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');
const response = await request(server)
Expand Down
71 changes: 48 additions & 23 deletions test/integrations/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import axios from 'axios';
import bodyParser from 'koa-bodyparser';
import { Command } from 'commander';
import { createHttpTerminator } from 'http-terminator';
import { MockHttpCallsData, TestCaseData } from './testTypes';
import { ExtendedTestCaseData, MockHttpCallsData, TestCaseData } from './testTypes';
import { applicationRoutes } from '../../src/routes/index';
import MockAxiosAdapter from 'axios-mock-adapter';
import {
Expand All @@ -25,6 +25,8 @@ import { assertRouterOutput, responses } from '../testHelper';
import { generateTestReport, initaliseReport } from '../test_reporter/reporter';
import _ from 'lodash';
import defaultFeaturesConfig from '../../src/features';
import { ControllerUtility } from '../../src/controllers/util';
import { FetchHandler } from '../../src/helpers/fetchHandlers';

// To run single destination test cases
// npm run test:ts -- component --destination=adobe_analytics
Expand Down Expand Up @@ -230,29 +232,52 @@ describe.each(allTestDataFilePaths)('%s Tests', (testDataPath) => {
});
}

describe(`${testData[0].name} ${testData[0].module}`, () => {
test.each(testData)('$feature -> $description (index: $#)', async (tcData) => {
tcData?.mockFns?.(mockAdapter);
const extendedTestData: ExtendedTestCaseData[] = testData.flatMap((tcData) => {
if (tcData.module === tags.MODULES.SOURCE) {
return [
{
tcData,
sourceTransformV2Flag: false,
descriptionSuffix: ' (sourceTransformV2Flag: false)',
},
{
tcData,
sourceTransformV2Flag: true,
descriptionSuffix: ' (sourceTransformV2Flag: true)',
},
];
}
return [{ tcData }];
});

switch (tcData.module) {
case tags.MODULES.DESTINATION:
await destinationTestHandler(tcData);
break;
case tags.MODULES.SOURCE:
defaultFeaturesConfig.upgradedToSourceTransformV2 = false;
await sourceTestHandler(tcData);
describe(`${testData[0].name} ${testData[0].module}`, () => {
test.each(extendedTestData)(
'$feature -> $description$descriptionSuffix (index: $#)',
async ({ tcData, sourceTransformV2Flag }) => {
tcData?.mockFns?.(mockAdapter);

// run the same tests for sources only with upgradedToSourceTransformV2 flag as true
tcData?.mockFns?.(mockAdapter);
defaultFeaturesConfig.upgradedToSourceTransformV2 = true;
await sourceTestHandler(tcData);
break;
default:
console.log('Invalid module');
// Intentionally fail the test case
expect(true).toEqual(false);
break;
}
});
switch (tcData.module) {
case tags.MODULES.DESTINATION:
await destinationTestHandler(tcData);
break;
case tags.MODULES.SOURCE:
tcData?.mockFns?.(mockAdapter);
testSetupSourceTransformV2(sourceTransformV2Flag);
await sourceTestHandler(tcData);
break;
default:
console.log('Invalid module');
// Intentionally fail the test case
expect(true).toEqual(false);
break;
}
},
);
});
});

const testSetupSourceTransformV2 = (flag) => {
defaultFeaturesConfig.upgradedToSourceTransformV2 = flag;
ControllerUtility['sourceVersionMap'] = new Map();
FetchHandler['sourceHandlerMap'] = new Map();
};
8 changes: 8 additions & 0 deletions test/integrations/testTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ export interface TestCaseData {
mockFns?: (mockAdapter: MockAdapter) => {};
}

export interface ExtendedTestCaseData {
// use this to add any new properties for dynamic test cases
// this will keep the base TestCaseData structure generic and intact
tcData: TestCaseData;
sourceTransformV2Flag?: boolean;
descriptionSuffix?: string;
}

export type MockFns = (mockAdapter: MockAdapter) => void;

export interface SrcTestCaseData {
Expand Down

0 comments on commit a8e7a40

Please sign in to comment.