-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-registry): get keychain by keychainId
Adds a utility method where I can just pass in the keychain ID and get back a plugin instance or an exception thrown if it was not found. Fixes #381 Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/cactus-core-api/src/test/typescript/unit/plugin-registry.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import test, { Test } from "tape"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
|
||
import { | ||
ICactusPlugin, | ||
IPluginKeychain, | ||
PluginAspect, | ||
PluginRegistry, | ||
} from "../../../main/typescript/public-api"; | ||
|
||
test("PluginRegistry", (tMain: Test) => { | ||
test("findOneByKeychainId() finds plugin by keychain ID", (t: Test) => { | ||
const keychainId = uuidv4(); | ||
|
||
const mockKeychainPlugin = { | ||
getKeychainId: () => keychainId, | ||
getAspect: () => PluginAspect.KEYCHAIN, | ||
} as IPluginKeychain; | ||
|
||
const pluginRegistry = new PluginRegistry({ | ||
plugins: [ | ||
mockKeychainPlugin, | ||
{ | ||
getAspect: () => PluginAspect.CONSORTIUM, | ||
} as ICactusPlugin, | ||
{ | ||
getAspect: () => PluginAspect.KV_STORAGE, | ||
} as ICactusPlugin, | ||
{ | ||
getAspect: () => PluginAspect.LEDGER_CONNECTOR, | ||
} as ICactusPlugin, | ||
], | ||
}); | ||
|
||
t.doesNotThrow(() => pluginRegistry.findOneByKeychainId(keychainId)); | ||
const keychainPlugin = pluginRegistry.findOneByKeychainId(keychainId); | ||
t.equal(keychainPlugin, mockKeychainPlugin, "Finds same object OK"); | ||
|
||
t.throws( | ||
() => pluginRegistry.findOneByKeychainId(""), | ||
/need keychainId arg as non-blank string/, | ||
"Check for keychain ID blankness OK" | ||
); | ||
t.throws( | ||
() => pluginRegistry.findOneByKeychainId("x"), | ||
/No keychain found for ID/, | ||
"Throws for keychain not found OK" | ||
); | ||
|
||
t.end(); | ||
}); | ||
|
||
tMain.end(); | ||
}); |