diff --git a/package-lock.json b/package-lock.json index c497f6b..a75de1b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@digicatapult/dscp-process-management", - "version": "1.7.47", + "version": "1.7.48", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@digicatapult/dscp-process-management", - "version": "1.7.47", + "version": "1.7.48", "license": "Apache-2.0", "dependencies": { "@polkadot/api": "^10.9.1", diff --git a/package.json b/package.json index 6d55467..3b042dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@digicatapult/dscp-process-management", - "version": "1.7.47", + "version": "1.7.48", "description": "DSCP Process Management Flow", "main": "./lib/index.js", "bin": { diff --git a/src/lib/process/_tests_/unit.test.ts b/src/lib/process/_tests_/unit.test.ts index 46b3f4e..c451c57 100644 --- a/src/lib/process/_tests_/unit.test.ts +++ b/src/lib/process/_tests_/unit.test.ts @@ -1,6 +1,12 @@ import { expect } from 'chai' + import { HexError } from '../../types/error.js' import { utf8ToHex } from '../hex.js' +import { listTransforming } from '../index.js' + +import sample from '../../../../tests/fixtures/processes.js' + +const defaultPolkadot: Process.CLIOptions = { port: '9044', user: 'alice', host: 'localhost' } describe('utf8ToHex', () => { it('converts a utf8 string to hexadecimal', () => { @@ -12,6 +18,118 @@ describe('utf8ToHex', () => { }) }) +describe('listTranforming', () => { + it('returns all transformed processes without a program (--verbose=false)', async () => { + let processes: Process.RawPayload[] + const enriched: Process.RawPayload = { + ...sample[0], + id: '123', + status: 'Enabled', + createdAtHash: 'abc', + initialU8aLength: '32', + } + + const res = await listTransforming([enriched], processes, { ...defaultPolkadot, verbose: false }) + + expect(res[0]).to.deep.contain({ + id: '123', + status: 'Enabled', + version: 1, + }) + }) + + it('returns all transformed processes with a program (--verbose=true)', async () => { + let processes: Process.RawPayload[] + const enriched: Process.RawPayload = { + ...sample[0], + id: '123', + status: 'Disabled', + createdAtHash: 'abc', + initialU8aLength: '32', + } + + const res = await listTransforming([enriched], processes, { ...defaultPolkadot, verbose: true}) + + expect(res[0]).to.deep.contain({ + id: '123', + status: 'Disabled', + version: 1, + }) + }) + + it('returns all options active', async () => { + let processes: Process.RawPayload[] + const enriched: Process.RawPayload = { + ...sample[0], + id: '123', + status: 'Enabled', + createdAtHash: 'abc', + initialU8aLength: '32', + } + + const res = await listTransforming([enriched], processes, { ...defaultPolkadot, active: true}) + + expect(res[0]).to.deep.contain({ + id: '123', + status: 'Enabled', + version: 1, + }) + }) + + it('returns all options disabled but with active true', async () => { + let processes: Process.RawPayload[] + const enriched: Process.RawPayload = { + ...sample[0], + id: '123', + status: 'Disabled', + createdAtHash: 'abc', + initialU8aLength: '32', + } + + const res = await listTransforming([enriched], processes, { ...defaultPolkadot, active: true}) + + expect(res[0]).to.equal(undefined) + }) + + it('returns all options disabled', async () => { + let processes: Process.RawPayload[] + const enriched: Process.RawPayload = { + ...sample[0], + id: '123', + status: 'Disabled', + createdAtHash: 'abc', + initialU8aLength: '32', + } + + const res = await listTransforming([enriched], processes, { ...defaultPolkadot}) + + expect(res[0]).to.deep.contain({ + id: '123', + status: 'Disabled', + version: 1, + }) + }) + + it('returns all options active with status enabled', async () => { + let processes: Process.RawPayload[] + const enriched: Process.RawPayload = { + ...sample[0], + id: '123', + status: 'Disabled', + createdAtHash: 'abc', + initialU8aLength: '32', + } + + const res = await listTransforming([enriched], processes, { ...defaultPolkadot, active: false}) + + expect(res[0]).to.deep.contain({ + id: '123', + status: 'Disabled', + version: 1, + }) + }) +}) + /* TODO will update with other due to this being covered in integration test suites describe('createProcessTransaction', () => { describe('if POSIX is invalid', () => { diff --git a/src/lib/process/index.ts b/src/lib/process/index.ts index c26aba7..296ed42 100644 --- a/src/lib/process/index.ts +++ b/src/lib/process/index.ts @@ -56,7 +56,7 @@ export const loadProcesses = async ({ export const listTransforming = async ( res: Process.RawPayload[], - processes: Process.RawPayload[], + processes: Process.RawPayload[], options: Process.CLIOptions) => { if (options.active) { processes = res.filter(({ status }) => status === 'Enabled')