-
-
Notifications
You must be signed in to change notification settings - Fork 692
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
Changes from 66 commits
7bbc0a8
527cf9f
878023a
aedbb7c
86b914e
be80885
b04532e
3ea1852
1dfd188
103d643
b3a87dd
8357f56
db96f45
2b392d1
877990e
88b1491
dd90f3c
c347dbf
71e4f13
03e0664
18e9d98
b3ae94b
014fdb6
e74251e
07a7dc3
511c00f
91ad534
a78dfa1
8577070
57f4dc3
0f9052e
a8ab07c
a454c8d
b7bf6c9
f95ecce
acb1ec3
61ac558
906a873
5c4c192
6940c12
aeabab2
db33c88
820de27
b16fca9
995b9bd
4a4dcb7
bd6424d
233efdd
4b13fc8
0489f2d
774da3f
7c24517
7279d79
2eccf52
7601440
9afb39b
464b1dc
496de09
2419f06
11fcfe6
7536a96
5164452
ca72a7f
65fcfbd
302b332
1698ce2
31c66ec
3ea3753
fa11169
7a55807
0a7e3c2
993310e
97905ba
94f362c
9d3aa7c
05b14a2
8587110
1cc25cb
40dcc54
5d23088
fca4dcc
98f3238
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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) => { | ||||||||||||||||||||||||||
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]?.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 | ||||||||||||||||||||||||||
akshatnema marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||
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)); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve validation error logging structure The current error logging could be more structured and consistent. -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));
+console.error({
+ message: 'Tool validation failed',
+ tool: tool.title,
+ source: 'manual-tools.json',
+ errors: validate.errors,
+ note: 'Script continues execution, error logged for investigation'
+}); 📝 Committable suggestion
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JeelRajodiya Kindly take a note of this. We have to improve error handling for this function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
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 }),) | ||||||||||||||||||||||||||
akshatnema marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||
} 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 } | ||||||||||||||||||||||||||
module.exports = { combineTools } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
const expectedDataT1 = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vishvamsinh28 This file has indentation errors. Kindly fix it. |
||
languages: [ | ||
{ | ||
name: 'JavaScript', | ||
color: 'bg-[#57f281]', | ||
borderColor: 'border-[#37f069]' | ||
}, | ||
{ | ||
name: 'Python', | ||
color: 'bg-[#3572A5]', | ||
borderColor: 'border-[#3572A5]' | ||
} | ||
], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we directly use tagsData instead of creating this duplicate data? |
||
technologies: [ | ||
{ | ||
name: 'Node.js', | ||
color: 'bg-[#61d0f2]', | ||
borderColor: 'border-[#40ccf7]' | ||
}, | ||
{ | ||
name: 'Flask', | ||
color: 'bg-[#000000]', | ||
borderColor: 'border-[#FFFFFF]' | ||
} | ||
] | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider reusing The color and border color data for languages and technologies appears to be duplicated from Example approach: const { tagsData } = require('../path/to/tagsData');
const expectedDataT1 = {
languages: tagsData.languages.map(({ name, color, borderColor }) => ({
name,
color,
borderColor
})).filter(lang => ['JavaScript', 'Python'].includes(lang.name)),
technologies: tagsData.technologies.map(({ name, color, borderColor }) => ({
name,
color,
borderColor
})).filter(tech => ['Node.js', 'Flask'].includes(tech.name))
}; 🧰 Tools🪛 eslint[error] 2-2: Delete (prettier/prettier) [error] 3-3: Delete (prettier/prettier) [error] 4-4: Replace (prettier/prettier) [error] 5-5: Replace (prettier/prettier) [error] 6-6: Delete (prettier/prettier) [error] 7-7: Replace (prettier/prettier) [error] 8-8: Replace (prettier/prettier) [error] 9-9: Replace (prettier/prettier) [error] 10-10: Replace (prettier/prettier) [error] 11-11: Delete (prettier/prettier) [error] 12-12: Delete (prettier/prettier) [error] 13-13: Delete (prettier/prettier) [error] 14-14: Delete (prettier/prettier) [error] 15-15: Delete (prettier/prettier) [error] 16-16: Replace (prettier/prettier) [error] 17-17: Delete (prettier/prettier) [error] 18-18: Replace (prettier/prettier) [error] 19-19: Replace (prettier/prettier) [error] 20-20: Replace (prettier/prettier) [error] 21-21: Replace (prettier/prettier) [error] 22-22: Replace (prettier/prettier) [error] 23-23: Delete (prettier/prettier) [error] 24-24: Replace (prettier/prettier) [error] 25-25: Delete (prettier/prettier) |
||
|
||
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 | ||
} |
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"] | ||
akshatnema marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
"links": { | ||
"repoUrl": "https://github.com/asyncapi/tool-b" | ||
} | ||
} | ||
] | ||
} | ||
} |
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" | ||
} | ||
} | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does
tagspath
signify??