Skip to content

Commit

Permalink
Fixed broken tests caused by simpleOutputTransform -> transformVerifi…
Browse files Browse the repository at this point in the history
…ed naming change.
  • Loading branch information
mbrich committed Jun 4, 2024
1 parent a2e5477 commit 48d5553
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/transform/verified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ export async function transformVerified<DataT = unknown, TransformedT = unknown>
const fate = new Fate<TransformedT | null>();

if (!base) {
return fate.setErrorCode(schemaError('missing_argument', 'simpleOutputTransform', 'base'));
return fate.setErrorCode(schemaError('missing_argument', 'transformVerified', 'base'));
}

const log = base.makeLog('simpleOutputTransform');
const log = base.makeLog('transformVerified');

if (!input) {
return fate.setErrorCode(schemaError('missing_argument', 'simpleOutputTransform', 'input'));
return fate.setErrorCode(schemaError('missing_argument', 'transformVerified', 'input'));
}

try {
Expand Down Expand Up @@ -81,7 +81,7 @@ export async function transformVerified<DataT = unknown, TransformedT = unknown>
const msg = e instanceof Error ? e.message : 'unknown_err_type';
fate.error(e);
log.error(`Exception: ${msg}.`);
fate.setErrorCode(schemaError('exception', 'simpleOutputTransform', `Error: ${msg}`));
fate.setErrorCode(schemaError('exception', 'transformVerified', `Error: ${msg}`));
}

return fate;
Expand Down
28 changes: 12 additions & 16 deletions tests/simple/output/transform.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Levels, Log} from '@toreda/log';
import {simpleOutputTransform} from '../../../src/transform/verified';
import {transformVerified} from '../../../src/transform/verified';
import {schemaError} from '../../../src';

const EMPTY_OBJECT = {};
const EMPTY_STRING = '';

describe('simpleOutputTransform', () => {
describe('transformVerified', () => {
let base: Log;
let input: Map<string, any>;

Expand All @@ -24,42 +24,38 @@ describe('simpleOutputTransform', () => {

describe('Input Validation', () => {
it(`should fail with code when input arg is undefined`, async () => {
const result = await simpleOutputTransform(undefined as any, base);
const result = await transformVerified(undefined as any, base);

expect(result.ok()).toBe(false);
expect(result.errorCode()).toBe(
schemaError('missing_argument', 'simpleOutputTransform', 'input')
);
expect(result.errorCode()).toBe(schemaError('missing_argument', 'transformVerified', 'input'));
});

it(`should fail with code when input arg is null`, async () => {
const result = await simpleOutputTransform(null as any, base);
const result = await transformVerified(null as any, base);

expect(result.ok()).toBe(false);
expect(result.errorCode()).toBe(
schemaError('missing_argument', 'simpleOutputTransform', 'input')
);
expect(result.errorCode()).toBe(schemaError('missing_argument', 'transformVerified', 'input'));
});

it(`should fail with code when base arg is undefined`, async () => {
const result = await simpleOutputTransform(input, undefined as any);
const result = await transformVerified(input, undefined as any);

expect(result.ok()).toBe(false);
expect(result.errorCode()).toBe(schemaError('missing_argument', 'simpleOutputTransform', 'base'));
expect(result.errorCode()).toBe(schemaError('missing_argument', 'transformVerified', 'base'));
});

it(`should fail with code when base arg is null`, async () => {
const result = await simpleOutputTransform(input, null as any);
const result = await transformVerified(input, null as any);

expect(result.ok()).toBe(false);
expect(result.errorCode()).toBe(schemaError('missing_argument', 'simpleOutputTransform', 'base'));
expect(result.errorCode()).toBe(schemaError('missing_argument', 'transformVerified', 'base'));
});
});

describe('Output Transformation', () => {
it(`should return an empty object when input map is empty`, async () => {
expect(input.size).toBe(0);
const result = await simpleOutputTransform(input, base);
const result = await transformVerified(input, base);

expect(result.errorCode()).toBe(EMPTY_STRING);
expect(result.ok()).toBe(true);
Expand All @@ -80,7 +76,7 @@ describe('simpleOutputTransform', () => {
input.set('c', c);
input.set('d', d);

const result = await simpleOutputTransform(input, base);
const result = await transformVerified(input, base);
expect(result.errorCode()).toBe(EMPTY_STRING);
expect(result.ok()).toBe(true);
expect(result.data).toEqual({
Expand Down

0 comments on commit 48d5553

Please sign in to comment.