mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-30 10:36:35 +02:00
94 lines
1.6 KiB
TypeScript
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);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
});
|