From a8e7a40d94a59b8e4ecc3bbcb6b677f938aedfbd Mon Sep 17 00:00:00 2001 From: Vinay Teki Date: Thu, 12 Dec 2024 13:08:40 +0530 Subject: [PATCH] chore: test cases cover v2 spec respecting code coverage --- test/apitests/service.api.test.ts | 24 ---------- test/integrations/component.test.ts | 71 +++++++++++++++++++---------- test/integrations/testTypes.ts | 8 ++++ 3 files changed, 56 insertions(+), 47 deletions(-) diff --git a/test/apitests/service.api.test.ts b/test/apitests/service.api.test.ts index 523476017e..d69d568355 100644 --- a/test/apitests/service.api.test.ts +++ b/test/apitests/service.api.test.ts @@ -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) diff --git a/test/integrations/component.test.ts b/test/integrations/component.test.ts index 9f1bfd238f..b077c31694 100644 --- a/test/integrations/component.test.ts +++ b/test/integrations/component.test.ts @@ -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 { @@ -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 @@ -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(); +}; diff --git a/test/integrations/testTypes.ts b/test/integrations/testTypes.ts index 3c5cf60600..dbd02e2217 100644 --- a/test/integrations/testTypes.ts +++ b/test/integrations/testTypes.ts @@ -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 {