1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00
joplin/packages/plugin-repo-cli/lib/checkIfPluginCanBeAdded.test.ts
2021-01-21 00:12:59 +00:00

94 lines
1.6 KiB
TypeScript

import checkIfPluginCanBeAdded from './checkIfPluginCanBeAdded';
describe('checkIfPluginCanBeAdded', () => {
test('should not add if already a plugin with this ID but different package name', () => {
const testCases = [
[
{
'test': {
id: 'test',
_npm_package_name: 'original',
},
},
{
id: 'test',
_npm_package_name: 'original',
},
true,
],
[
{
'test': {
id: 'test',
_npm_package_name: 'original',
},
},
{
id: 'test',
_npm_package_name: 'cantdothat',
},
false,
],
];
for (const t of testCases) {
const [existingManifests, manifest, shouldWork] = t;
let hasThrown = false;
try {
checkIfPluginCanBeAdded(existingManifests, manifest);
} catch (error) {
hasThrown = true;
}
expect(!hasThrown).toBe(shouldWork);
}
});
test('should not add if already a plugin with this ID but a different case', () => {
const testCases = [
[
{
'test': {
id: 'test',
_npm_package_name: 'original',
},
},
{
id: 'newone',
_npm_package_name: 'otherpackage',
},
true,
],
[
{
'test': {
id: 'test',
_npm_package_name: 'original',
},
},
{
id: 'Test',
_npm_package_name: 'original',
},
false,
],
];
for (const t of testCases) {
const [existingManifests, manifest, shouldWork] = t;
let hasThrown = false;
try {
checkIfPluginCanBeAdded(existingManifests, manifest);
} catch (error) {
hasThrown = true;
}
expect(!hasThrown).toBe(shouldWork);
}
});
});