Skip to content

Commit

Permalink
feat: add browserLocationHrefPipe (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
pismenskiy authored Dec 1, 2022
1 parent 47ce5d1 commit 7b8f53d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/main/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export { createHttpPipeFallback } from './pipes/httpFallback'
export { createMaskerPipe, panMaskerPipe } from './pipes/masker'
export { createHttpBatchPipe } from './pipes/httpBatch'
export { createDeviceInfoPipe } from './pipes/deviceInfo'
export { createBrowserLocationHrefPipe } from './pipes/browserLocationHref'
export * from './interfaces'
export * from './pipes/index'

Expand Down Expand Up @@ -80,6 +81,4 @@ export {
createFrontLogProxyTransmitter,
}

export type {
IClientEventDtoFlp
}
export type { IClientEventDtoFlp }
14 changes: 14 additions & 0 deletions src/main/ts/pipes/browserLocationHref.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { IPromise } from '@qiwi/substrate'

import { IPipe, IPipeOutput, ITransmittable } from '../interfaces'
import { clone, set } from '../utils/index'

export const type = 'browser-location-href'

export const createBrowserLocationHrefPipe = (): IPipe => ({
type,
execute({ data }: ITransmittable): IPromise<IPipeOutput> {
const output = set(clone(data), 'meta.location', window.location.href)
return Promise.resolve([null, output])
},
})
2 changes: 2 additions & 0 deletions src/main/ts/pipes/flp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IClientEventDto, LogLevel } from '@qiwi/substrate'

import { IPipe, ITransmittable, TPipeline } from '../interfaces'
import { identity } from '../utils/index'
import { createBrowserLocationHrefPipe } from './browserLocationHref'
import { createDeviceInfoPipe } from './deviceInfo'
import { createHttpBatchPipe, IHttpBatchPipeOpts } from './httpBatch'
import { panMaskerPipe } from './masker'
Expand Down Expand Up @@ -82,5 +83,6 @@ export const createFlpPipeline = ({
panMaskerPipe,
eventifyPipe,
createDeviceInfoPipe(),
createBrowserLocationHrefPipe(),
createHttpBatchPipe({ url, batchUrl, headers, method }),
]
5 changes: 4 additions & 1 deletion src/test/ts/createFrontLogProxyTransmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ global.window = {
navigator: {
userAgent: '',
},
// @ts-ignore
location: {
href: 'https://github.com/qiwi/event-transmitter',
},
}

// @ts-ignore
Expand All @@ -35,7 +39,6 @@ test('createFrontLogProxyTransmitter correctly call fetch with data', async () =
code: '211',
tags: ['frontend', 'qiwi'],
})

res.details.appContextId = ''
res.details.clientId = ''

Expand Down
18 changes: 18 additions & 0 deletions src/test/ts/pipes/browserLocationHref.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test } from 'uvu'
import * as assert from 'uvu/assert'

import { createBrowserLocationHrefPipe } from '../../../main/ts/index'

test('browserLocationHref is returned by factory', async () => {
const browserLocationHrefPipe = createBrowserLocationHrefPipe()
const res = await browserLocationHrefPipe.execute(
{ data: {}, err: null, meta: { history: [] } },
() => { /* noop */ },
)
assert.equal(res, [
null,
{ meta: { location: 'https://github.com/qiwi/event-transmitter' } },
])
})

test.run()

0 comments on commit 7b8f53d

Please sign in to comment.