Skip to content

Commit 20bdee3

Browse files
committed
Add test for duplication check
1 parent ee2f82c commit 20bdee3

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

plugins.test.js

+23-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs');
22

3-
let plugins = fs.readFileSync('./plugins.json').toString();
3+
const plugins = fs.readFileSync('./plugins.json').toString();
44

55
// helper function
66
const countPluginKey = (plugins, key) => plugins
@@ -12,15 +12,32 @@ describe('plugins', () => {
1212
});
1313

1414
it('should have all required keys', () => {
15-
plugins = JSON.parse(plugins);
16-
const pluginsCount = plugins.length;
15+
const parsed = JSON.parse(plugins);
16+
const pluginsCount = parsed.length;
1717

18-
const nameCount = countPluginKey(plugins, 'name');
19-
const descriptionCount = countPluginKey(plugins, 'description');
20-
const githubUrlCount = countPluginKey(plugins, 'githubUrl');
18+
const nameCount = countPluginKey(parsed, 'name');
19+
const descriptionCount = countPluginKey(parsed, 'description');
20+
const githubUrlCount = countPluginKey(parsed, 'githubUrl');
2121

2222
expect(nameCount).toBe(pluginsCount);
2323
expect(descriptionCount).toBe(pluginsCount);
2424
expect(githubUrlCount).toBe(pluginsCount);
2525
});
26+
27+
it('should be unique', () => {
28+
const parsed = JSON.parse(plugins);
29+
const pluginsCount = parsed.length;
30+
31+
// create an array only containing the plugin names
32+
const pluginNames = parsed.map((plugin) => plugin.name);
33+
34+
const uniquePlugins = [];
35+
pluginNames.forEach((plugin) => {
36+
if (uniquePlugins.indexOf(plugin) === -1) uniquePlugins.push(plugin)
37+
});
38+
39+
const uniquePluginsCount = uniquePlugins.length;
40+
41+
expect(pluginsCount).toBe(uniquePluginsCount);
42+
});
2643
});

0 commit comments

Comments
 (0)