Skip to content

Commit

Permalink
feat: add lookup for param names and details
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Jun 16, 2021
1 parent df28867 commit 964877b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/governance/src/param-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ const buildParamManager = paramDesc => {
const { bindings, types } = parse(paramDesc);

const publicFacet = {
lookup(name) {
return bindings.get(name);
},
lookup: name => bindings.get(name),
getDetails: name => ({
name,
value: bindings.get(name),
type: types.get(name),
}),
definedNames: () => bindings.keys(),
};

const manager = {
Expand Down
31 changes: 31 additions & 0 deletions packages/governance/test/test-param-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,34 @@ test('params one any', async t => {
manager.update('stuff', 18.1);
t.deepEqual(publicFacet.lookup('stuff'), 18.1);
});

test('params keys', async t => {
const fooHandle = makeHandle('foo');
const { publicFacet, manager } = buildParamManager([
{
name: 'stuff',
value: fooHandle,
type: ParamType.ANY,
},
{
name: 'bigint',
value: 314159n,
type: ParamType.BIGINT,
},
]);
t.deepEqual(publicFacet.lookup('stuff'), fooHandle);
manager.update('stuff', 18.1);
t.deepEqual(publicFacet.lookup('stuff'), 18.1);

t.deepEqual(publicFacet.getDetails('stuff'), {
name: 'stuff',
value: 18.1,
type: ParamType.ANY,
});
t.deepEqual(publicFacet.getDetails('bigint'), {
name: 'bigint',
value: 314159n,
type: ParamType.BIGINT,
});
t.deepEqual(publicFacet.definedNames(), ['stuff', 'bigint']);
});

0 comments on commit 964877b

Please sign in to comment.