Skip to content

Commit

Permalink
fix: unnecessary line removal
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Nov 11, 2024
1 parent 42428b4 commit 91710fc
Showing 1 changed file with 47 additions and 25 deletions.
72 changes: 47 additions & 25 deletions test/integrations/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,42 @@ import {
RouterTransformationResponseListSchema,
} from '../../src/types/zodTypes';

const getDataFilesFromDir = (dir: string): string[] => {
// Look for data.ts files recursively in the directory
return globSync('**/data.ts', {
cwd: dir,
absolute: true,
});
};

const getNetworkFilesFromDir = (dir: string): string[] => {
// Look for network.ts files recursively in the directory
return globSync('**/network.ts', {
cwd: dir,
absolute: true,
});
};

const generateAlphanumericId = (size = 36) =>
[...Array(size)].map(() => ((Math.random() * size) | 0).toString(size)).join('');
export const getTestDataFilePaths = (dirPath: string, opts: OptionValues): string[] => {
const globPattern = join(dirPath, '**', 'data.ts');
let testFilePaths = globSync(globPattern);
let filteredTestFilePaths: string[] = testFilePaths;

const destinationOrSource = opts.destination || opts.source;
if (destinationOrSource) {
filteredTestFilePaths = testFilePaths.filter(
(testFile) => destinationOrSource && testFile.includes(`${destinationOrSource}/`),
);
export const getTestDataFilePaths = (rootDir: string, opts: any) => {
const paths: string[] = [];
if (opts.destination) {
// Existing destination logic
const destinationPath = join(rootDir, 'destinations', opts.destination);
paths.push(...getDataFilesFromDir(destinationPath));
} else if (opts.source) {
// New source logic
const sourcePath = join(rootDir, 'sources', opts.source);
paths.push(...getDataFilesFromDir(sourcePath));
} else {
// Get all test files if no specific integration is specified
const destinationsPath = join(rootDir, 'destinations');
const sourcesPath = join(rootDir, 'sources');
paths.push(...getDataFilesFromDir(destinationsPath));
paths.push(...getDataFilesFromDir(sourcesPath));
}
if (opts.feature) {
filteredTestFilePaths = filteredTestFilePaths.filter((testFile) =>
testFile.includes(opts.feature),
);
}
return filteredTestFilePaths;
return paths;
};

export const getTestData = (filePath): TestCaseData[] => {
Expand All @@ -48,17 +65,22 @@ export const getMockHttpCallsData = (filePath): MockHttpCallsData[] => {
return require(filePath).networkCallsData as MockHttpCallsData[];
};

export const getAllTestMockDataFilePaths = (dirPath: string, destination: string): string[] => {
const globPattern = join(dirPath, '**', 'network.ts');
let testFilePaths = globSync(globPattern);
export const getAllTestMockDataFilePaths = (
rootDir: string,
destination?: string,
source?: string,
) => {
const paths: string[] = [];
if (destination) {
const commonTestFilePaths = testFilePaths.filter((testFile) =>
testFile.includes('test/integrations/common'),
);
testFilePaths = testFilePaths.filter((testFile) => testFile.includes(destination));
testFilePaths = [...commonTestFilePaths, ...testFilePaths];
// Existing destination logic
const destinationPath = join(rootDir, 'destinations', destination);
paths.push(...getNetworkFilesFromDir(destinationPath));
} else if (source) {
// New source logic
const sourcePath = join(rootDir, 'sources', source);
paths.push(...getNetworkFilesFromDir(sourcePath));
}
return testFilePaths;
return paths;
};

export const addMock = (mock: MockAdapter, axiosMock: MockHttpCallsData) => {
Expand Down

0 comments on commit 91710fc

Please sign in to comment.