Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add test for combine tools script #3136

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7bbc0a8
tools test added
vishvamsinh28 Jul 28, 2024
527cf9f
tools test updated for errors
vishvamsinh28 Jul 29, 2024
878023a
tools test upadted
vishvamsinh28 Jul 31, 2024
aedbb7c
Merge branch 'master' into combineToolsTest
vishvamsinh28 Aug 9, 2024
86b914e
Merge branch 'master' into combineToolsTest
vishvamsinh28 Aug 31, 2024
be80885
refactor build-tools
vishvamsinh28 Aug 31, 2024
b04532e
Merge branch 'master' into combineToolsTest
vishvamsinh28 Sep 11, 2024
3ea1852
Merge branch 'master' into combineToolsTest
vishvamsinh28 Sep 20, 2024
1dfd188
87% coverage
vishvamsinh28 Sep 21, 2024
103d643
fewgw
vishvamsinh28 Sep 21, 2024
b3a87dd
fewgw
vishvamsinh28 Sep 21, 2024
8357f56
fewgwfwf
vishvamsinh28 Sep 21, 2024
db96f45
wf
vishvamsinh28 Sep 21, 2024
2b392d1
fwefgwe
vishvamsinh28 Sep 29, 2024
877990e
test update
vishvamsinh28 Sep 29, 2024
88b1491
test update
vishvamsinh28 Sep 29, 2024
dd90f3c
test update
vishvamsinh28 Sep 29, 2024
c347dbf
test update again
vishvamsinh28 Sep 29, 2024
71e4f13
coverage 98%
vishvamsinh28 Sep 29, 2024
03e0664
fefefge
vishvamsinh28 Sep 29, 2024
18e9d98
100% coverage
vishvamsinh28 Sep 29, 2024
b3ae94b
test cases for error added
vishvamsinh28 Sep 30, 2024
014fdb6
fixures
vishvamsinh28 Sep 30, 2024
e74251e
fixture update
vishvamsinh28 Sep 30, 2024
07a7dc3
fixutures again
vishvamsinh28 Sep 30, 2024
511c00f
Merge branch 'master' into combineToolsTest
vishvamsinh28 Sep 30, 2024
91ad534
Merge branch 'combineToolsTest' of https://github.com/vishvamsinh28/w…
vishvamsinh28 Sep 30, 2024
a78dfa1
idjwqf
vishvamsinh28 Sep 30, 2024
8577070
Merge branch 'master' into combineToolsTest
vishvamsinh28 Oct 4, 2024
57f4dc3
fwqefqe
vishvamsinh28 Oct 4, 2024
0f9052e
tests updated
vishvamsinh28 Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion scripts/build-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const fs = require('fs');
const { resolve } = require('path');

const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPath) => {

try {
let githubExtractData = await getData();
let automatedTools = await convertTools(githubExtractData);
Expand All @@ -13,8 +14,9 @@ const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPa
automatedToolsPath,
JSON.stringify(automatedTools, null, ' ')
);

await combineTools(automatedTools, require(manualToolsPath), toolsPath, tagsPath);

} catch (err) {
throw new Error(`An error occurred while building tools: ${err.message}`);
}
Expand Down
56 changes: 30 additions & 26 deletions scripts/tools/combine-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,37 +106,41 @@ const getFinalTool = async (toolObject) => {
// Combine the automated tools and manual tools list into single JSON object file, and
// lists down all the language and technology tags in one JSON file.
const combineTools = async (automatedTools, manualTools, toolsPath, tagsPath) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does tagspath signify??

for (const key in automatedTools) {
let finalToolsList = [];
if (automatedTools[key].toolsList.length) {
for (const tool of automatedTools[key].toolsList) {
finalToolsList.push(await getFinalTool(tool))
try {
for (const key in automatedTools) {
let finalToolsList = [];
if (automatedTools[key].toolsList.length) {
for (const tool of automatedTools[key].toolsList) {
finalToolsList.push(await getFinalTool(tool))
}
}
}
if (manualTools[key] && manualTools[key].toolsList.length) {
for (const tool of manualTools[key].toolsList) {
let isAsyncAPIrepo;
const isValid = await validate(tool)
if (isValid) {
if (tool?.links?.repoUrl) {
const url = new URL(tool.links.repoUrl)
isAsyncAPIrepo = url.href.startsWith("https://github.com/asyncapi/")
} else isAsyncAPIrepo = false
let toolObject = await createToolObject(tool, "", "", isAsyncAPIrepo)
finalToolsList.push(await getFinalTool(toolObject))
} else {
console.error('Script is not failing, it is just dropping errors for further investigation');
console.error(`Invalid ${tool.title} .asyncapi-tool file.`);
console.error(`Located in manual-tools.json file`);
console.error('Validation errors:', JSON.stringify(validate.errors, null, 2));
if (manualTools[key] && manualTools[key].toolsList.length) {
for (const tool of manualTools[key].toolsList) {
let isAsyncAPIrepo;
const isValid = await validate(tool)
if (isValid) {
if (tool?.links?.repoUrl) {
const url = new URL(tool.links.repoUrl)
isAsyncAPIrepo = url.href.startsWith("https://github.com/asyncapi/")
} else isAsyncAPIrepo = false
let toolObject = await createToolObject(tool, "", "", isAsyncAPIrepo)
finalToolsList.push(await getFinalTool(toolObject))
} else {
console.error('Script is not failing, it is just dropping errors for further investigation');
console.error(`Invalid ${tool.title} .asyncapi-tool file.`);
console.error(`Located in manual-tools.json file`);
console.error('Validation errors:', JSON.stringify(validate.errors, null, 2));
}
}
}
finalToolsList.sort((tool, anotherTool) => tool.title.localeCompare(anotherTool.title));
finalTools[key].toolsList = finalToolsList
}
finalToolsList.sort((tool, anotherTool) => tool.title.localeCompare(anotherTool.title));
finalTools[key].toolsList = finalToolsList
fs.writeFileSync(toolsPath, JSON.stringify(finalTools));
fs.writeFileSync(tagsPath, JSON.stringify({ languages: languageList, technologies: technologyList }),)
} 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 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix this linter error

212 changes: 212 additions & 0 deletions tests/fixtures/combineToolsData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
const expectedDataT1 = {
languages: [
{
name: 'JavaScript',
color: 'bg-[#57f281]',
borderColor: 'border-[#37f069]'
},
{
name: 'Python',
color: 'bg-[#3572A5]',
borderColor: 'border-[#3572A5]'
}
],
technologies: [
{
name: 'Node.js',
color: 'bg-[#61d0f2]',
borderColor: 'border-[#40ccf7]'
},
{
name: 'Flask',
color: 'bg-[#000000]',
borderColor: 'border-[#FFFFFF]'
}
]
};

const manualToolsWithMissingData = [
{
title: 'Tool C',
filters: {},
links: { repoUrl: 'https://github.com/asyncapi/tool-c' }
}
];

const manualToolsToSort = {
category1: {
description: 'Sample Category',
toolsList: [
{
title: 'Tool Z',
filters: { language: 'JavaScript' },
links: { repoUrl: 'https://github.com/asyncapi/tool-z' }
},
{
title: 'Tool A',
filters: { language: 'Python' },
links: { repoUrl: 'https://github.com/asyncapi/tool-a' }
}
]
}
};

const toolWithMultipleLanguages = {
title: 'Multi-Language Tool',
filters: {
language: ['JavaScript', 'Python', 'NewLanguage'],
technology: ['Node.js']
},
links: { repoUrl: 'https://github.com/example/multi-language-tool' }
};

const automatedToolsT5 = {
'category1': {
description: 'Category 1 Description',
toolsList: [toolWithMultipleLanguages]
}
};

const invalidToolT4 = { title: 'Invalid Tool' };

const automatedToolsT4 = {
'category1': {
description: 'Category 1 Description',
toolsList: []
}
};
const manualToolsT4 = {
'category1': {
toolsList: [invalidToolT4]
}
};

const toolWithNewTagsT6 = {
title: 'New Tags Tool',
filters: {
language: 'NewLanguage',
technology: ['NewTechnology']
},
links: { repoUrl: 'https://github.com/example/new-tags-tool' }
};

const automatedToolsT6 = {
'category1': {
description: 'Category 1 Description',
toolsList: [toolWithNewTagsT6]
}
};

const toolWithNewLanguageT7 = {
title: 'New Language Tool',
filters: {
language: 'Go',
technology: ['Node.js']
},
links: { repoUrl: 'https://github.com/example/new-language-tool' }
};

const automatedToolsT7 = {
'category1': {
description: 'Category 1 Description',
toolsList: [toolWithNewLanguageT7]
}
};

const validToolT8 = {
title: 'Valid Tool',
filters: {
language: 'JavaScript',
technology: ['Node.js']
},
links: { repoUrl: 'https://github.com/asyncapi/valid-tool' }
};

const automatedToolsT8 = {
category1: {
description: 'Category 1 Description',
toolsList: []
}
};

const manualToolsT8 = {
category1: {
toolsList: [validToolT8]
}
};

const toolWithoutRepoUrlT9 = {
title: 'Tool Without Repo',
filters: {
language: 'Python',
technology: ['Flask']
},
links: {}
};

const automatedToolsT9 = {
category1: {
description: 'Category 1 Description',
toolsList: []
}
};

const manualToolsT9 = {
category1: {
toolsList: [toolWithoutRepoUrlT9]
}
};

const invalidAutomatedToolsT10 = {
invalidCategory: {
description: 'Invalid Category Description',
toolsList: []
}
};

const manualToolsWithInvalidURLT11 = {
category1: {
toolsList: [
{
title: 'Tool with Invalid URL',
filters: { language: 'JavaScript' },
links: { repoUrl: 'invalid-url' }
}
]
}
};

const circularTool = {
title: 'Circular Tool',
filters: {
language: 'JavaScript',
technology: ['Node.js']
},
links: { repoUrl: 'https://github.com/asyncapi/circular-tool' }
};

const automatedToolsT12 = {
category1: {
description: 'Category 1',
toolsList: [circularTool]
}
};

module.exports = {
expectedDataT1,
manualToolsWithMissingData,
manualToolsToSort,
automatedToolsT5,
automatedToolsT4,
manualToolsT4,
automatedToolsT6,
automatedToolsT7,
automatedToolsT8,
manualToolsT8,
automatedToolsT9,
manualToolsT9,
circularTool,
automatedToolsT12,
invalidAutomatedToolsT10,
manualToolsWithInvalidURLT11
}
17 changes: 17 additions & 0 deletions tests/fixtures/tools/automated-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"category1": {
"description": "Sample Category",
"toolsList": [
{
"title": "Tool B",
"filters": {
"language": "Python",
"technology": ["Flask"]
},
"links": {
"repoUrl": "https://github.com/asyncapi/tool-b"
}
}
]
}
}
12 changes: 12 additions & 0 deletions tests/fixtures/tools/manual-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"title": "Tool A",
"filters": {
"language": "JavaScript",
"technology": ["Node.js"]
},
"links": {
"repoUrl": "https://github.com/asyncapi/tool-a"
}
}
]
Loading
Loading