From 9f2f8ef091a990e2e721eb92e7150a52db94b06e Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Thu, 5 Mar 2020 13:39:58 +0300 Subject: [PATCH] style: linting --- src/main/ts/pipes/flp.ts | 14 +++++--------- src/main/ts/pipes/index.ts | 2 +- src/test/ts/pipes/flp.ts | 27 +++++++++------------------ 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/main/ts/pipes/flp.ts b/src/main/ts/pipes/flp.ts index 72aabde..518874f 100644 --- a/src/main/ts/pipes/flp.ts +++ b/src/main/ts/pipes/flp.ts @@ -1,7 +1,7 @@ -import {IClientEventDto, LogLevel} from '@qiwi/substrate' -import {IPipe, ITransmittable, TPipeline} from '../interfaces' -import {panMaskerPipe} from './masker' -import {createHttpPipe, IHttpPipeOpts} from './http' +import { IClientEventDto, LogLevel } from '@qiwi/substrate' +import { IPipe, ITransmittable, TPipeline } from '../interfaces' +import { panMaskerPipe } from './masker' +import { createHttpPipe, IHttpPipeOpts } from './http' const DEFAULT_LEVEL = LogLevel.INFO @@ -17,19 +17,15 @@ export const eventifyPipe: IPipe = { if (data === null || data === undefined) { return [new Error('Event message must not be empty'), null] - - } else if (typeof data === 'string' || typeof data === 'string') { + } else if (typeof data === 'string' || typeof data === 'number') { event.level = DEFAULT_LEVEL event.message = '' + data - } else if (data instanceof Error) { event.message = data.message event.level = LogLevel.ERROR // TODO process stack trace - } else if (Array.isArray(data)) { return [new Error('Event batches are not supported yet'), null] - } else if (typeof data === 'object') { Object.assign(event, data) } diff --git a/src/main/ts/pipes/index.ts b/src/main/ts/pipes/index.ts index 8a0a762..3be305f 100644 --- a/src/main/ts/pipes/index.ts +++ b/src/main/ts/pipes/index.ts @@ -20,7 +20,7 @@ export const execute = async (transmittable: ITransmittable, pipeline: TPipeline return [null, null] } - const next = once(([_err, data]: IPipeOutput) => execute({...transmittable, data}, pipeline.slice(1), prefix + 1, pipelineId)) + const next = once(([err, data]: IPipeOutput) => execute({ ...transmittable, data, err }, pipeline.slice(1), prefix + 1, pipelineId)) return pipe.execute(transmittable, next).then(async (output) => { transmittable.meta.history.push({ diff --git a/src/test/ts/pipes/flp.ts b/src/test/ts/pipes/flp.ts index d4221e5..2736ab8 100644 --- a/src/test/ts/pipes/flp.ts +++ b/src/test/ts/pipes/flp.ts @@ -1,26 +1,18 @@ -import {eventifyPipe, createFlpPipeline} from '../../../main/ts/pipes/flp' -import {createTransmittable, createTransmitter} from '../../../main/ts' -import {HttpMethod} from '@qiwi/substrate' +import { eventifyPipe, createFlpPipeline } from '../../../main/ts/pipes/flp' +import { createTransmittable, createTransmitter } from '../../../main/ts' +import { HttpMethod } from '@qiwi/substrate' import 'cross-fetch/polyfill' -describe('eventifyPipe', () => { - const noop = () => { /* noop */ } +const noop = () => { /* noop */ } +describe('eventifyPipe', () => { const cases: Array<[string, any, any, any]> = [ - ['processes string input', 'foo', null, { - level: 'info', - message: 'foo', - meta: {}, - }], - ['processes error as input', new Error('foobar'), null, { - level: 'error', - message: 'foobar', - meta: {}, - }], + ['processes string input', 'foo', null, { level: 'info', message: 'foo', meta: {} }], + ['processes error as input', new Error('foobar'), null, { level: 'error', message: 'foobar', meta: {} }], ['returns err if no arg passed', undefined, new Error('Event message must not be empty'), null], ['does not processes arrays', [], new Error('Event batches are not supported yet'), null], - ['assures message not to be empty', '', new Error('Event message must not be empty'), null], + ['assures message not to be empty', '', new Error('Event message must not be empty'), null] ] cases.forEach(([name, input, err, data]) => { @@ -31,7 +23,6 @@ describe('eventifyPipe', () => { }) describe('flpPipeline', () => { - it('createFlpPipeline factory returns a pipeline', () => { expect(createFlpPipeline({ url: 'https://reqres.in/api/users/2', method: HttpMethod.GET })).toEqual(expect.any(Array)) }) @@ -53,7 +44,7 @@ describe('flpPipeline', () => { body: JSON.stringify({ message: '0000 **** **** 0000', meta: {}, - level: 'info', + level: 'info' }), headers: { 'Content-Type': 'application/json'