Skip to content

Commit

Permalink
ALL-9118 - Upgrade Node, NPM and other libraries
Browse files Browse the repository at this point in the history
tests sonar refactoring
  • Loading branch information
martintatum committed Dec 20, 2024
1 parent d02f245 commit 2529d93
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions tests/commands.test.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
import { describe, expect } from '@jest/globals'
import { exec } from 'child_process'
import { spawnSync } from 'child_process'

function runCommand(cmd: string, callback: (error: Error | null, stdout: string, stderr: string) => void): void {
exec(cmd, (error, stdout, stderr) => {
callback(error, stdout, stderr)
})
function runCommand(cmd: string, args: string[]): string {
const result = spawnSync(cmd, args, { shell: false, encoding: 'utf-8' })
return result.output.toString()
}

describe('Generic Commands Tests', () => {
it('should display help when no parameter is provided', done => {
runCommand('yarn start', (error, stdout, stderr) => {
expect(stderr).toBe('')
expect(stdout).toContain('Tatum KMS - Key Management System for Tatum-powered apps.')
expect(stdout).toContain('Usage')
done()
})
it('should display help when no parameter is provided', async () => {
const result = runCommand('yarn', ['start'])
expect(result).toContain('Tatum KMS - Key Management System for Tatum-powered apps.')
expect(result).toContain('Usage')
})
})

const chains: [string][] = [['ABC'], ['XYZ']]

describe('Chain-specific Commands Tests', () => {
chains.forEach(([chain]) => {
it(`should not generate wallet for ${chain} and end up with error`, done => {
runCommand(`yarn start generatewallet ${chain}`, (error, stdout, stderr) => {
expect(stderr).toContain('Error: Unsupported blockchain')
done()
})
it(`should not generate wallet for ${chain} and end up with error`, async () => {
const result = runCommand('yarn', ['start', 'generatewallet', `${chain}`])
expect(result).toContain('Error: Unsupported blockchain.')
})
})
})

0 comments on commit 2529d93

Please sign in to comment.