Skip to content

Commit

Permalink
fixtures updated
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Sep 21, 2024
1 parent c858834 commit c816f66
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions tests/build-tools.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,81 @@ describe('buildTools', () => {
writeFileSync(toolsPath, JSON.stringify(initialToolsData));
});

afterAll(() => {
rmSync(testDir, { recursive: true, force: true });
});

beforeEach(() => {
jest.clearAllMocks();
});

it('should extract, convert, combine tools, and write to file', async () => {

getData.mockResolvedValue(mockExtractData);
convertTools.mockResolvedValue(mockConvertedData);
combineTools.mockResolvedValue(true);

await buildTools(automatedToolsPath, manualToolsPath, toolsPath, tagsPath);

const automatedToolsContent = readFileSync(automatedToolsPath, 'utf8');
expect(JSON.parse(automatedToolsContent)).toEqual(mockConvertedData);

const manualToolsData = JSON.parse(readFileSync(manualToolsPath, 'utf8'));
const tagsData = JSON.parse(readFileSync(tagsPath, 'utf8'));
expect(combineTools).toHaveBeenCalledWith(mockConvertedData, manualToolsData, toolsPath, tagsPath);

const toolsContent = readFileSync(toolsPath, 'utf8');
expect(toolsContent).toBeDefined();
expect(tagsData).toBeDefined();
});

it('should handle getData error', async () => {
getData.mockRejectedValue(new Error('Extract error'));

try {
await buildTools(automatedToolsPath, manualToolsPath, toolsPath, tagsPath);
} catch (err) {
expect(err.message).toContain('Extract error');
}
});

it('should handle convertTools error', async () => {

getData.mockResolvedValue(mockExtractData);
convertTools.mockRejectedValue(new Error('Convert error'));

try {
await buildTools(automatedToolsPath, manualToolsPath, toolsPath, tagsPath);
} catch (err) {
expect(err.message).toContain('Convert error');
}
});

it('should handle combineTools error', async () => {

getData.mockResolvedValue(mockExtractData);
convertTools.mockResolvedValue(mockConvertedData);
combineTools.mockRejectedValue(new Error('Combine Tools error'));

try {
await buildTools(automatedToolsPath, manualToolsPath, toolsPath, tagsPath);
} catch (err) {
expect(err.message).toContain('Combine Tools error');
}
});

it('should handle file write errors', async () => {

getData.mockResolvedValue(mockExtractData);
convertTools.mockResolvedValue(mockConvertedData);
combineTools.mockResolvedValue(true);

const invalidPath = '/invalid_dir/tools.json';

try {
await buildTools(invalidPath, manualToolsPath, toolsPath, tagsPath);
} catch (err) {
expect(err.message).toMatch(/ENOENT|EACCES/);
}
});
});

0 comments on commit c816f66

Please sign in to comment.