Skip to content

Commit

Permalink
style: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Mar 5, 2020
1 parent a66f59f commit 9f2f8ef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
14 changes: 5 additions & 9 deletions src/main/ts/pipes/flp.ts
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/ts/pipes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
27 changes: 9 additions & 18 deletions src/test/ts/pipes/flp.ts
Original file line number Diff line number Diff line change
@@ -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]) => {
Expand All @@ -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))
})
Expand All @@ -53,7 +44,7 @@ describe('flpPipeline', () => {
body: JSON.stringify({
message: '0000 **** **** 0000',
meta: {},
level: 'info',
level: 'info'
}),
headers: {
'Content-Type': 'application/json'
Expand Down

0 comments on commit 9f2f8ef

Please sign in to comment.