Skip to content

Commit

Permalink
tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Oct 4, 2024
1 parent 57f4dc3 commit 0f9052e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
3 changes: 0 additions & 3 deletions scripts/tools/combine-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const schema = require("./tools-schema.json");
const Ajv = require("ajv")
const addFormats = require("ajv-formats")
const Fuse = require("fuse.js");
const { error } = require("console");
const ajv = new Ajv()
addFormats(ajv, ["uri"])
const validate = ajv.compile(schema)
Expand Down Expand Up @@ -142,8 +141,6 @@ const combineTools = async (automatedTools, manualTools, toolsPath, tagsPath) =>
} catch (err) {
throw new Error(`Error combining tools: ${err}`);
}
fs.writeFileSync(toolsPath,JSON.stringify(finalTools));
fs.writeFileSync(tagsPath,JSON.stringify({ languages: languageList, technologies: technologyList }),)
}

module.exports = { combineTools }
7 changes: 0 additions & 7 deletions tests/fixtures/combineToolsData.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,6 @@ const automatedToolsT12 = {
}
};

const invalidManualToolsT13 = {
category1: {
toolsList: [{ title: 'Invalid Tool' }]
}
};

module.exports = {
expectedDataT1,
manualToolsWithMissingData,
Expand All @@ -211,7 +205,6 @@ module.exports = {
manualToolsT8,
automatedToolsT9,
manualToolsT9,
invalidManualToolsT13,
circularTool,
automatedToolsT12,
invalidAutomatedToolsT10,
Expand Down
25 changes: 13 additions & 12 deletions tests/tools/combine-tools.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ const {
manualToolsT8,
automatedToolsT9,
manualToolsT9,
invalidManualToolsT13,
automatedToolsT12,
invalidAutomatedToolsT10,
manualToolsWithInvalidURLT11,
circularTool
} = require('../fixtures/combineToolsData')
} = require('../fixtures/combineToolsData');

jest.mock('ajv', () => {
return jest.fn().mockImplementation(() => ({
Expand Down Expand Up @@ -209,51 +208,53 @@ describe('combineTools function', () => {
});

it('should throw an error when fs.writeFileSync fails', async () => {
let error;
let invalidPath = "this/is/not/valid"

try {
await combineTools(automatedTools, manualTools, invalidPath, invalidPath);
} catch (err) {
error = err;
expect(err.message).toMatch(/ENOENT|EACCES/);
}
expect(error).toBeDefined();
});

it('should throw an error when there is an invalid category', async () => {
let error;

try {
await combineTools(invalidAutomatedToolsT10, manualTools, toolsPath, tagsPath);
} catch (err) {
error = err;
expect(err.message).toContain('Error combining tools');
}
expect(error).toBeDefined();
});

it('should throw an error when URL parsing fails', async () => {
let error;

try {
await combineTools(automatedTools, manualToolsWithInvalidURLT11, toolsPath, tagsPath);
} catch (err) {
error = err;
expect(err.message).toContain('Invalid URL');
}
expect(error).toBeDefined();
});

it('should handle errors when processing tools with circular references', async () => {

let error;
circularTool.circular = circularTool;

try {
await combineTools(automatedToolsT12, {}, toolsPath, tagsPath);
} catch (err) {
error = err;
expect(err.message).toContain('Converting circular structure to JSON');
}
});

it('should throw an error when invalid manualTools data is passed', async () => {

try {
await combineTools(automatedTools, invalidManualToolsT13, toolsPath, tagsPath);
} catch (err) {
expect(err.message).toBe('Error processing tool: Cannot read property \'language\' of undefined');
}
expect(error).toBeDefined();
});

});

0 comments on commit 0f9052e

Please sign in to comment.