forked from webalytic/webalytic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
log-processing: update unit test, add readme, exclude for nyc
- Loading branch information
1 parent
f9ccfe4
commit abd1593
Showing
12 changed files
with
318 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,6 @@ | |
], | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
} | ||
}, | ||
"editor.formatOnSave": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"extends": "@istanbuljs/nyc-config-typescript", | ||
"all": false, | ||
"check-coverage": true | ||
"check-coverage": true, | ||
"exclude": ["**/shared/**"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Webalytic/log-processing | ||
|
||
Service subscribe on events from log-collector service, handle all hits, create and update sessions, parse Geo, User-Agent etc.., and as result sending events **SessionCreated**, **SessionUpdated** | ||
|
||
--- | ||
## Package.json scripts | ||
|
||
```bash | ||
# Build shared code from protobuf specification | ||
yarn build | ||
|
||
# Start main process: consumer, handler and producer | ||
yarn start | ||
|
||
# Run test, unit + integration | ||
yarn test | ||
|
||
# Run unit test with coverage report | ||
yarn coverage | ||
|
||
# Check EsLint | ||
yarn lint | ||
|
||
# Check TypeScript | ||
yarn ts-check | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
import { createFastesValidationError } from '@webalytic/ms-tools/lib/errors' | ||
import { session } from '@shared/value-objects/session' | ||
import { SessionCreateProps } from './Session' | ||
import { HitType, HitDataSource } from '../../constants' | ||
|
||
// Todo: "import ... from ..." throw TypeError: fastest_validator_1.default is not a constructor | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const Validator = require('fastest-validator') | ||
|
||
const v = new Validator() | ||
const createSessionSchema = { | ||
resourceId: { type: 'uuid' }, | ||
clientId: { type: 'string', min: 1, max: 64 }, | ||
userId: { type: 'string', min: 0, max: 64 } | ||
} | ||
const createSessionCheck = v.compile(createSessionSchema) | ||
|
||
const createHitSchema = { | ||
time: { type: 'string', pattern: /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/ }, | ||
type: { type: 'string', enum: Object.values(HitType) }, | ||
dataSource: { type: 'string', enum: Object.values(HitDataSource), optional: true }, | ||
pageUrl: { type: 'url', empty: true }, | ||
eventCategory: { | ||
type: 'string', max: 64, optional: true | ||
}, | ||
eventAction: { | ||
type: 'string', max: 64, optional: true | ||
}, | ||
eventLabel: { | ||
type: 'string', max: 64, optional: true | ||
}, | ||
eventValue: { | ||
type: 'number', optional: true, min: 0, max: 4294967295 // UInt32 | ||
}, | ||
transactionId: { type: 'string', max: 64, optional: true }, | ||
transactionAffiliation: { type: 'string', max: 64, optional: true }, | ||
transactionRevenue: { type: 'number', max: 64, optional: true }, | ||
productAction: { type: 'string', max: 64, optional: true }, | ||
productsList: { | ||
type: 'array', | ||
items: { | ||
type: 'object', | ||
props: { | ||
productSku: { type: 'string', max: 64, optional: true }, | ||
productName: { type: 'string', max: 128, optional: true }, | ||
productBrand: { type: 'string', max: 128, optional: true }, | ||
productCategory: { type: 'string', max: 256, optional: true }, | ||
productVariant: { type: 'string', max: 128, optional: true }, | ||
productPrice: { | ||
type: 'number', optional: true, min: 0, max: 4294967295 // UInt32 | ||
}, | ||
productQuantity: { | ||
type: 'number', optional: true, positive: true, max: 4294967295 // UInt32 | ||
}, | ||
productCouponCode: { type: 'string', max: 128, optional: true } | ||
} | ||
}, | ||
default: [], | ||
optional: true | ||
} | ||
} | ||
const createHitCheck = v.compile(createHitSchema) | ||
|
||
export function createInputValidate(data: SessionCreateProps, hitProps: session.IHit): void{ | ||
const isValidSession = createSessionCheck(data) | ||
if (isValidSession !== true) throw createFastesValidationError(isValidSession) | ||
|
||
const isValidHit = createHitCheck(hitProps) | ||
if (isValidHit !== true) throw createFastesValidationError(isValidHit) | ||
} | ||
|
||
export function addHitInputValidatte(hitProps: session.IHit): void { | ||
const isValidHit = createHitCheck(hitProps) | ||
if (isValidHit !== true) throw createFastesValidationError(isValidHit) | ||
} |
Oops, something went wrong.