Skip to content

Commit

Permalink
List Transformation Tests (#119)
Browse files Browse the repository at this point in the history
* CHORE: an example test for listTransforming.

* LintTransformation tests added

* Remove logs

* Remove logs

---------

Co-authored-by: Paulius Michelevicius <[email protected]>
  • Loading branch information
nitro-marky and n3op2 authored Sep 11, 2023
1 parent 47f00f8 commit a31b8c9
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
118 changes: 118 additions & 0 deletions src/lib/process/_tests_/unit.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/process/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit a31b8c9

Please sign in to comment.