ensured that all entry aliases meets the allowed aliases + refactored the test method

This commit is contained in:
Niels Lyngsø
2019-10-29 14:54:31 +01:00
parent 338c4b7bcf
commit 0c29d57ef9

View File

@@ -61,6 +61,16 @@ function clipboardService(notificationsService, eventsService, localStorageServi
return shallowCloneData;
}
var isEntryCompatible = function(entry, type, allowedAliases) {
return entry.type === type
&&
(
(entry.alias && allowedAliases.filter(allowedAlias => allowedAlias === entry.alias).length > 0)
||
(entry.aliases && entry.aliases.filter(entryAlias => allowedAliases.filter(allowedAlias => allowedAlias === entryAlias).length > 0).length === entry.aliases.length)
);
}
var service = {};
@@ -195,15 +205,7 @@ function clipboardService(notificationsService, eventsService, localStorageServi
// Find entries that are fulfilling the criteria for this nodeType and nodeTypesAliases.
var filteretEntries = storage.entries.filter(
(entry) => {
return (
entry.type === type
&&
(
(entry.alias && allowedAliases.filter(allowedAlias => allowedAlias === entry.alias).length > 0)
||
(entry.aliases && entry.aliases.filter(entryAlias => allowedAliases.filter(allowedAlias => allowedAlias === entryAlias).length > 0).length > 0)
)
);
return isEntryCompatible(entry, type, allowedAliases);
}
);
@@ -243,15 +245,7 @@ function clipboardService(notificationsService, eventsService, localStorageServi
// Find entries that are NOT fulfilling the criteria for this nodeType and nodeTypesAliases.
var filteretEntries = storage.entries.filter(
(entry) => {
return !(
entry.type === type
&&
(
(entry.alias && allowedAliases.filter(allowedAlias => allowedAlias === entry.alias).length > 0)
||
(entry.aliases && entry.aliases.filter(entryAlias => allowedAliases.filter(allowedAlias => allowedAlias === entryAlias).length > 0).length > 0)
)
);
return !isEntryCompatible(entry, type, allowedAliases);
}
);