Skip to content

Commit

Permalink
store type in expected for faster execution
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwalguptaofficial committed Dec 7, 2019
1 parent f90ad0f commit 59cdbf5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
11 changes: 8 additions & 3 deletions dist/fort.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/fort.js.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/handlers/route_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GenericShield, GenericGuard } from "../generics";
import { isNull } from "../utils";
import { RouteInfo } from "../models";
import { IRouteInfo } from "../interfaces";
import { getDataType } from "../helpers";

const routerCollection: {
[controllerName: string]: RouteInfo
Expand Down Expand Up @@ -183,6 +184,12 @@ export class RouteHandler {
}

static addExpected(type: string, className: string, workerName: string, expectedValue: any) {

for (const prop in expectedValue) {
const propValue = expectedValue[prop];
expectedValue[prop] = getDataType(propValue);
}

const isQuery = type === 'query';
const pattern = workerName.toLowerCase();
const router = routerCollection[className];
Expand Down
5 changes: 2 additions & 3 deletions src/helpers/compar_expected_and_remove_unnecessary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { DATA_TYPE } from "../enums/data_type";
export const compareExpectedAndRemoveUnnecessary = (expected, actual, isQuery) => {
const result = {};
for (const prop in expected) {
const expectedType = getDataType(expected[prop]);
if (isQuery === true && expectedType === DATA_TYPE.Number) {
if (isQuery === true && expected[prop] === DATA_TYPE.Number) {
result[prop] = Number(actual[prop]);
if (isNaN(result[prop]) === true) {
return null;
Expand All @@ -14,7 +13,7 @@ export const compareExpectedAndRemoveUnnecessary = (expected, actual, isQuery) =
else {
result[prop] = actual[prop];
}
if (expectedType !== getDataType(result[prop])) {
if (expected[prop] !== getDataType(result[prop])) {
return null;
}
}
Expand Down

0 comments on commit 59cdbf5

Please sign in to comment.