From e52878cdbd48b09bc92b65b14d53f6153b6e2280 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 5 Aug 2024 14:35:48 +0530 Subject: [PATCH] Update authorities list command and add tests --- README.md | 4 +- src/cmds/registry-cmds/authority-cmds/list.ts | 12 ++++-- test/cli.test.ts | 41 +++++++++++++++++++ 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c45fa04..a5c6825 100644 --- a/README.md +++ b/README.md @@ -354,13 +354,13 @@ $ laconic registry authority reserve kube.laconic --owner laconic15za32wly5exgcr Get all the authorities: ```bash -$ laconic registry authority get +$ laconic registry authority list ``` Get all the authorities by owner: ```bash -$ laconic registry authority get --owner laconic1zayjut6pd4xy9dguut56v55hktzmeq6r777hmd +$ laconic registry authority list --owner laconic1zayjut6pd4xy9dguut56v55hktzmeq6r777hmd ``` Set name: diff --git a/src/cmds/registry-cmds/authority-cmds/list.ts b/src/cmds/registry-cmds/authority-cmds/list.ts index cf7e018..b92b59d 100644 --- a/src/cmds/registry-cmds/authority-cmds/list.ts +++ b/src/cmds/registry-cmds/authority-cmds/list.ts @@ -5,13 +5,17 @@ import { Registry } from '@cerc-io/registry-sdk'; import { getConfig, getConnectionInfo, queryOutput } from '../../../util'; -export const command = 'list [owner]'; +export const command = 'list'; export const desc = 'List authorities (optionally by owner).'; -export const handler = async (argv: Arguments) => { - const owner = argv.owner as string || ''; +export const builder = { + owner: { + type: 'string' + } +}; +export const handler = async (argv: Arguments) => { const { services: { registry: registryConfig } } = getConfig(argv.config as string); const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig); assert(rpcEndpoint, 'Invalid registry RPC endpoint.'); @@ -19,7 +23,7 @@ export const handler = async (argv: Arguments) => { assert(chainId, 'Invalid registry Chain ID.'); const registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); - const result = await registry.getAuthorities(owner); + const result = await registry.getAuthorities(argv.owner as string); queryOutput(result, argv.output); }; diff --git a/test/cli.test.ts b/test/cli.test.ts index 8ab2e7e..8718bb2 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -478,6 +478,47 @@ describe('Test laconic CLI commands', () => { expect(authorityOutputObj.length).toEqual(1); expect(authorityOutputObj[0]).toMatchObject(expectedAuthority); }); + + test('laconic registry authority list', async () => { + const result = spawnSync('laconic', ['registry', 'authority', 'list']); + const authoritiesOutputObj = checkResultAndRetrieveOutput(result); + + // Expected authorities + const expectedAuthorities = [ + { name: 'echo.laconic', entry: { ownerAddress: testAccount, status: 'active' } }, + { name: 'kube.laconic', entry: { ownerAddress: testAccount2, status: 'active' } }, + { name: 'laconic', entry: { ownerAddress: testAccount, status: 'active' } } + ]; + + // Expected output + expect(authoritiesOutputObj.length).toEqual(3); + expect(authoritiesOutputObj).toMatchObject(expectedAuthorities); + }); + + test('laconic registry authority list --owner ', async () => { + let result = spawnSync('laconic', ['registry', 'authority', 'list', '--owner', testAccount]); + const authoritiesByOwner1 = checkResultAndRetrieveOutput(result); + + // Expected output + const expectedAuthoritiesByOwner1 = [ + { name: 'echo.laconic', entry: { ownerAddress: testAccount, status: 'active' } }, + { name: 'laconic', entry: { ownerAddress: testAccount, status: 'active' } } + ]; + + expect(authoritiesByOwner1.length).toEqual(2); + expect(authoritiesByOwner1).toMatchObject(expectedAuthoritiesByOwner1); + + result = spawnSync('laconic', ['registry', 'authority', 'list', '--owner', testAccount2]); + const authoritiesByOwner2 = checkResultAndRetrieveOutput(result); + + // Expected output + const expectedAuthoritiesByOwner2 = [ + { name: 'kube.laconic', entry: { ownerAddress: testAccount2, status: 'active' } } + ]; + + expect(authoritiesByOwner2.length).toEqual(1); + expect(authoritiesByOwner2).toMatchObject(expectedAuthoritiesByOwner2); + }); }); describe('Name operations', () => {