From 055f903ce2206c3ac783fb68c9c12015709876c4 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 24 Jan 2024 12:47:38 +0530 Subject: [PATCH] Add a test for status command --- test/cli.test.ts | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/test/cli.test.ts b/test/cli.test.ts index a0f512c..aa96e70 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -4,6 +4,7 @@ describe('Test laconic CLI commands', () => { beforeAll(async () => { // TODO: Install laconic binary (create symlink in path) // TODO: Create a temp directory to run the tests in and cd into that + // TODO: Create the required config }); afterAll(async () => { @@ -22,7 +23,44 @@ describe('Test laconic CLI commands', () => { expect(result.status).toBe(1); }); + // TODO: Test subcommands describe('laconic ', () => { - // TODO: Test subcommands + test('laconic cns', async () => { + const result = spawnSync('laconic', ['cns']); + + const output = result.stdout.toString().trim(); + const errorOutput = result.stderr.toString().trim(); + + // Expect error with usage string + expect(output).toBe(''); + expect(errorOutput).toContain('laconic cns'); + expect(errorOutput).toContain('CNS tools'); + expect(errorOutput).toContain('Commands:'); + expect(result.status).toBe(1); + }); + + describe('laconic cns ', () => { + test('laconic cns status', async () => { + const result = spawnSync('laconic', ['cns', 'status']); + + const output = result.stdout.toString().trim(); + const outputObj = JSON.parse(output); + const errorOutput = result.stderr.toString().trim(); + + // Expect output object to have CNS status props + expect(outputObj).toHaveProperty('version'); + expect(outputObj).toHaveProperty('node'); + expect(outputObj).toHaveProperty('node.network', 'laconic_9000-1'); + expect(outputObj).toHaveProperty('sync'); + expect(outputObj).toHaveProperty('validator'); + expect(outputObj).toHaveProperty('validators'); + expect(outputObj).toHaveProperty('num_peers'); + expect(outputObj).toHaveProperty('peers'); + expect(outputObj).toHaveProperty('disk_usage'); + + expect(errorOutput).toBe(''); + expect(result.status).toBe(0); + }); + }); }); });