@autofleet/sheilta 1.2.1 → 1.2.3-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/formatter/index.d.ts +4 -12
- package/lib/formatter/index.js +6 -30
- package/lib/formatter/index.test.js +5 -54
- package/lib/middleware/index.d.ts +1 -3
- package/lib/middleware/index.js +9 -23
- package/lib/operators/index.js +0 -2
- package/lib/utils.d.ts +1 -10
- package/lib/utils.js +2 -25
- package/lib/validations/index.d.ts +2 -5
- package/lib/validations/index.js +14 -49
- package/lib/validations/index.test.js +0 -50
- package/package.json +1 -1
package/lib/formatter/index.d.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
declare type OrderItem = string | [string, string];
|
|
2
2
|
declare type SequelizeOrder = string | OrderItem[];
|
|
3
|
-
declare const
|
|
4
|
-
order
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
include?: any[];
|
|
8
|
-
}, model?: any) => {
|
|
9
|
-
order: SequelizeOrder[];
|
|
10
|
-
page: any;
|
|
11
|
-
perPage: any;
|
|
12
|
-
include: any;
|
|
13
|
-
};
|
|
14
|
-
export default formatPayload;
|
|
3
|
+
export declare const formatOrder: ({ order, }: {
|
|
4
|
+
order?: any[];
|
|
5
|
+
}) => SequelizeOrder[] | undefined;
|
|
6
|
+
export {};
|
package/lib/formatter/index.js
CHANGED
|
@@ -1,39 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatOrder = void 0;
|
|
3
4
|
const utils_1 = require("../utils");
|
|
4
5
|
const DESCENDING_KEY = 'DESC';
|
|
5
|
-
|
|
6
|
+
exports.formatOrder = ({ order = [], }) => (order.length === 0 ? undefined :
|
|
6
7
|
order.map((o) => {
|
|
7
|
-
const formattedOrder = [utils_1.extractAttributeNameFromOrder(o, associationModels)];
|
|
8
8
|
const isOrderDescOrder = utils_1.isOrderDesc(o);
|
|
9
|
-
|
|
10
|
-
? o.split(utils_1.ORDER_PREFIX)[1]
|
|
11
|
-
: o, associationModels);
|
|
12
|
-
if (isOrderAssociation) {
|
|
13
|
-
formattedOrder.push(utils_1.extractAssociatedAttributeNameFromOrder(o));
|
|
14
|
-
}
|
|
9
|
+
let column = o;
|
|
15
10
|
if (isOrderDescOrder) {
|
|
16
|
-
|
|
11
|
+
column = utils_1.extractAttributeNameFromOrder(o);
|
|
12
|
+
return [column, DESCENDING_KEY];
|
|
17
13
|
}
|
|
18
|
-
return
|
|
14
|
+
return [column];
|
|
19
15
|
}));
|
|
20
|
-
const formatPage = page => page || utils_1.PAGE_DEFAULT;
|
|
21
|
-
const formatPerPage = perPage => perPage || utils_1.PER_PAGE_DEFAULT;
|
|
22
|
-
const formatInclude = (include, associationsMap = {}) => include.map(i => associationsMap[i.model]);
|
|
23
|
-
const formatPayload = ({ order, page = utils_1.PAGE_DEFAULT, perPage = utils_1.PER_PAGE_DEFAULT, include = [], }, model) => {
|
|
24
|
-
const associationModels = Object.keys((model === null || model === void 0 ? void 0 : model.associations) || {});
|
|
25
|
-
const formattedOrder = formatOrder({
|
|
26
|
-
order,
|
|
27
|
-
associationModels,
|
|
28
|
-
});
|
|
29
|
-
const formattedInclude = formatInclude(include, model === null || model === void 0 ? void 0 : model.associations);
|
|
30
|
-
const formattedPage = formatPage(page);
|
|
31
|
-
const formattedPerPage = formatPerPage(perPage);
|
|
32
|
-
return {
|
|
33
|
-
order: formattedOrder,
|
|
34
|
-
page: formattedPage,
|
|
35
|
-
perPage: formattedPerPage,
|
|
36
|
-
include: formattedInclude,
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
exports.default = formatPayload;
|
|
@@ -1,66 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const _1 =
|
|
3
|
+
const _1 = require(".");
|
|
7
4
|
describe('formatting test', () => {
|
|
8
5
|
it('check order formatting', () => {
|
|
9
|
-
const
|
|
6
|
+
const payload = _1.formatOrder({
|
|
10
7
|
order: ['startTime', '-endTime'],
|
|
11
8
|
});
|
|
12
|
-
expect(JSON.stringify(
|
|
9
|
+
expect(JSON.stringify(payload)).toBe(JSON.stringify([['startTime'], ['endTime', 'DESC']]));
|
|
13
10
|
});
|
|
14
11
|
it('check order formatting', () => {
|
|
15
|
-
const
|
|
12
|
+
const payload = _1.formatOrder({
|
|
16
13
|
order: ['startTime', 'endTime'],
|
|
17
14
|
});
|
|
18
|
-
expect(JSON.stringify(
|
|
19
|
-
});
|
|
20
|
-
it('check order formatting - by included model', () => {
|
|
21
|
-
const { order } = _1.default({
|
|
22
|
-
order: ['status.name'],
|
|
23
|
-
}, {
|
|
24
|
-
rawAttributes: {
|
|
25
|
-
startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
|
|
26
|
-
},
|
|
27
|
-
associations: {
|
|
28
|
-
status: {},
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
expect(JSON.stringify(order)).toBe(JSON.stringify([['status', 'name']]));
|
|
32
|
-
});
|
|
33
|
-
it('check order formatting - by included model descending', () => {
|
|
34
|
-
const { order } = _1.default({
|
|
35
|
-
order: ['-status.name'],
|
|
36
|
-
}, {
|
|
37
|
-
rawAttributes: {
|
|
38
|
-
startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
|
|
39
|
-
},
|
|
40
|
-
associations: {
|
|
41
|
-
status: {},
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
expect(JSON.stringify(order)).toBe(JSON.stringify([['status', 'name', 'DESC']]));
|
|
45
|
-
});
|
|
46
|
-
it('check order formatting - by json field', () => {
|
|
47
|
-
const { order } = _1.default({
|
|
48
|
-
order: ['status.name'],
|
|
49
|
-
}, {
|
|
50
|
-
rawAttributes: {
|
|
51
|
-
startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', json: '',
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
expect(JSON.stringify(order)).toBe(JSON.stringify([['status.name']]));
|
|
55
|
-
});
|
|
56
|
-
it('check order formatting - by json field descending', () => {
|
|
57
|
-
const { order } = _1.default({
|
|
58
|
-
order: ['-status.name'],
|
|
59
|
-
}, {
|
|
60
|
-
rawAttributes: {
|
|
61
|
-
startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', json: '',
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
expect(JSON.stringify(order)).toBe(JSON.stringify([['status.name', 'DESC']]));
|
|
15
|
+
expect(JSON.stringify(payload)).toBe(JSON.stringify([['startTime'], ['endTime']]));
|
|
65
16
|
});
|
|
66
17
|
});
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
export declare const newQueryValidationMiddleware: (inner?: string) => (model: any) => (req: any, res: any, next: any) => Promise<any>;
|
|
2
|
-
export declare const newQueryFormatMiddleware: (inner?: string) => (model: any) => (req: any, res: any, next: any) => Promise<any>;
|
|
3
1
|
export declare const queryValidationMiddleware: (model: any) => (req: any, res: any, next: any) => Promise<any>;
|
|
4
|
-
export declare const queryFormatMiddleware: (
|
|
2
|
+
export declare const queryFormatMiddleware: () => (req: any, res: any, next: any) => Promise<any>;
|
package/lib/middleware/index.js
CHANGED
|
@@ -8,24 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.queryFormatMiddleware = exports.queryValidationMiddleware =
|
|
12
|
+
exports.queryFormatMiddleware = exports.queryValidationMiddleware = void 0;
|
|
16
13
|
const errors_1 = require("@autofleet/errors");
|
|
17
|
-
const formatter_1 =
|
|
14
|
+
const formatter_1 = require("../formatter");
|
|
18
15
|
const validations_1 = require("../validations");
|
|
19
|
-
exports.
|
|
20
|
-
const { query, attributes, order,
|
|
16
|
+
exports.queryValidationMiddleware = model => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const { query, attributes, order, } = req.body;
|
|
21
18
|
try {
|
|
22
19
|
validations_1.validatePayload({
|
|
23
20
|
query,
|
|
24
21
|
attributes,
|
|
25
22
|
order,
|
|
26
|
-
page,
|
|
27
|
-
perPage,
|
|
28
|
-
include,
|
|
29
23
|
}, model);
|
|
30
24
|
return next();
|
|
31
25
|
}
|
|
@@ -41,19 +35,11 @@ exports.newQueryValidationMiddleware = (inner = 'body') => model => (req, res, n
|
|
|
41
35
|
});
|
|
42
36
|
}
|
|
43
37
|
});
|
|
44
|
-
exports.
|
|
45
|
-
const { order,
|
|
46
|
-
const
|
|
38
|
+
exports.queryFormatMiddleware = () => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const { order, } = req.body;
|
|
40
|
+
const formattedOrder = formatter_1.formatOrder({
|
|
47
41
|
order,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
include,
|
|
51
|
-
}, model);
|
|
52
|
-
req[inner].order = formattedOrder;
|
|
53
|
-
req[inner].page = formattedPage;
|
|
54
|
-
req[inner].perPage = formattedPerPage;
|
|
55
|
-
req[inner].include = formattedInclude;
|
|
42
|
+
});
|
|
43
|
+
req.body.order = formattedOrder;
|
|
56
44
|
return next();
|
|
57
45
|
});
|
|
58
|
-
exports.queryValidationMiddleware = exports.newQueryValidationMiddleware();
|
|
59
|
-
exports.queryFormatMiddleware = exports.newQueryFormatMiddleware();
|
package/lib/operators/index.js
CHANGED
package/lib/utils.d.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
1
|
export declare const ORDER_PREFIX = "-";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const PER_PAGE_DEFAULT = 20;
|
|
4
|
-
export declare const PAGE_DEFAULT = 1;
|
|
5
|
-
export declare const PER_PAGE_MAX_LIMIT = 100;
|
|
6
|
-
export declare const PER_PAGE_MIN_LIMIT = 1;
|
|
7
|
-
export declare const PAGE_MIN = 1;
|
|
8
|
-
export declare const isOrderByAssociation: (attributeName: any, associatedModels: any) => boolean;
|
|
9
|
-
export declare const extractAttributeNameFromOrder: (order: any, associationModels: any) => string;
|
|
2
|
+
export declare const extractAttributeNameFromOrder: (order: any) => string;
|
|
10
3
|
export declare const isOrderDesc: (order: any) => boolean;
|
|
11
|
-
export declare const throwBadRequestError: (message: string) => never;
|
|
12
|
-
export declare const extractAssociatedAttributeNameFromOrder: (order: any) => string;
|
package/lib/utils.js
CHANGED
|
@@ -1,29 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const errors_1 = require("@autofleet/errors");
|
|
3
|
+
exports.isOrderDesc = exports.extractAttributeNameFromOrder = exports.ORDER_PREFIX = void 0;
|
|
5
4
|
exports.ORDER_PREFIX = '-';
|
|
6
|
-
exports.
|
|
7
|
-
exports.PER_PAGE_DEFAULT = 20;
|
|
8
|
-
exports.PAGE_DEFAULT = 1;
|
|
9
|
-
exports.PER_PAGE_MAX_LIMIT = 100;
|
|
10
|
-
exports.PER_PAGE_MIN_LIMIT = 1;
|
|
11
|
-
exports.PAGE_MIN = 1;
|
|
12
|
-
exports.isOrderByAssociation = (attributeName, associatedModels) => attributeName.includes(exports.ASSOCIATION_PREFIX)
|
|
13
|
-
&& associatedModels.includes(attributeName.split(exports.ASSOCIATION_PREFIX)[0]);
|
|
14
|
-
exports.extractAttributeNameFromOrder = (order, associationModels) => {
|
|
15
|
-
let formattedOrder = order;
|
|
16
|
-
if (order.includes(exports.ORDER_PREFIX)) {
|
|
17
|
-
// eslint-disable-next-line prefer-destructuring
|
|
18
|
-
formattedOrder = formattedOrder.split(exports.ORDER_PREFIX)[1];
|
|
19
|
-
}
|
|
20
|
-
if (exports.isOrderByAssociation(formattedOrder, associationModels)) {
|
|
21
|
-
[formattedOrder] = formattedOrder.split(exports.ASSOCIATION_PREFIX);
|
|
22
|
-
}
|
|
23
|
-
return formattedOrder;
|
|
24
|
-
};
|
|
5
|
+
exports.extractAttributeNameFromOrder = (order) => order.split(exports.ORDER_PREFIX)[1];
|
|
25
6
|
exports.isOrderDesc = (order) => order.includes(exports.ORDER_PREFIX);
|
|
26
|
-
exports.throwBadRequestError = (message) => {
|
|
27
|
-
throw new errors_1.BadRequest([{ message }], null);
|
|
28
|
-
};
|
|
29
|
-
exports.extractAssociatedAttributeNameFromOrder = (order) => order.split(exports.ASSOCIATION_PREFIX)[1];
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
export declare const validatePayload: ({ query, order, attributes,
|
|
1
|
+
export declare const validatePayload: ({ query, order, attributes, }: {
|
|
2
2
|
query?: {};
|
|
3
3
|
order?: any[];
|
|
4
4
|
attributes?: any[];
|
|
5
|
-
|
|
6
|
-
page?: number;
|
|
7
|
-
perPage?: number;
|
|
8
|
-
}, model?: any) => boolean;
|
|
5
|
+
}, model: any) => boolean;
|
package/lib/validations/index.js
CHANGED
|
@@ -4,34 +4,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.validatePayload = void 0;
|
|
7
|
+
const errors_1 = require("@autofleet/errors");
|
|
7
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
9
|
const utils_1 = require("../utils");
|
|
9
10
|
const operators_1 = require("../operators");
|
|
10
11
|
const validateOperator = (operator) => operators_1.OPERATORS.includes(operator.split(operators_1.OPERATOR_PREFIX)[1]);
|
|
11
12
|
const validateQueryAttribute = (attribute, modelAttributes) => modelAttributes.includes(attribute);
|
|
12
|
-
const validateSingleOrder = (currentOrder, rawAttributes
|
|
13
|
+
const validateSingleOrder = (currentOrder, rawAttributes) => {
|
|
13
14
|
const isOrderDescOrder = utils_1.isOrderDesc(currentOrder);
|
|
14
15
|
if (isOrderDescOrder && currentOrder[0] !== utils_1.ORDER_PREFIX) {
|
|
15
|
-
|
|
16
|
+
throw new errors_1.BadRequest(`${utils_1.ORDER_PREFIX} must be only at the beginning of the word`, null);
|
|
16
17
|
}
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
[formattedOrderString] = formattedOrderString.split(utils_1.ASSOCIATION_PREFIX);
|
|
23
|
-
}
|
|
24
|
-
if (!(rawAttributes.includes(formattedOrderString) || isOrderAssociation)) {
|
|
25
|
-
utils_1.throwBadRequestError(`${currentOrder} is invalid`);
|
|
18
|
+
const formattedOrderString = isOrderDescOrder ?
|
|
19
|
+
utils_1.extractAttributeNameFromOrder(currentOrder) :
|
|
20
|
+
currentOrder;
|
|
21
|
+
if (!rawAttributes.includes(formattedOrderString)) {
|
|
22
|
+
throw new errors_1.BadRequest(`${currentOrder} is invalid`, null);
|
|
26
23
|
}
|
|
27
24
|
};
|
|
28
25
|
const validateSingleAttribute = (currentAttribute, rawAttributes) => {
|
|
29
26
|
if (!rawAttributes.includes(currentAttribute)) {
|
|
30
|
-
|
|
27
|
+
throw new errors_1.BadRequest(`${currentAttribute} is invalid`, null);
|
|
31
28
|
}
|
|
32
29
|
};
|
|
33
|
-
const validateOrderAttributes = (order, rawAttributes
|
|
34
|
-
order.map(o => validateSingleOrder(o, rawAttributes
|
|
30
|
+
const validateOrderAttributes = (order, rawAttributes) => {
|
|
31
|
+
order.map(o => validateSingleOrder(o, rawAttributes));
|
|
35
32
|
};
|
|
36
33
|
const validateAttributes = (attributes, rawAttributes) => {
|
|
37
34
|
attributes.map(a => validateSingleAttribute(a, rawAttributes));
|
|
@@ -51,37 +48,12 @@ const validateQueryPayload = (query, rawAttributes) => {
|
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
50
|
else {
|
|
54
|
-
|
|
51
|
+
throw new errors_1.BadRequest(`invalid key: ${key}`, null);
|
|
55
52
|
}
|
|
56
53
|
});
|
|
57
54
|
};
|
|
58
|
-
|
|
59
|
-
if (page < utils_1.PAGE_MIN) {
|
|
60
|
-
utils_1.throwBadRequestError('Page must be greater than 0');
|
|
61
|
-
}
|
|
62
|
-
if (perPage > utils_1.PER_PAGE_MAX_LIMIT || perPage < utils_1.PER_PAGE_MIN_LIMIT) {
|
|
63
|
-
utils_1.throwBadRequestError(`PerPage must be between ${utils_1.PER_PAGE_MIN_LIMIT} to ${utils_1.PER_PAGE_MAX_LIMIT}`);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
const validateIncludePayload = (include, associations) => {
|
|
67
|
-
const associationsKeys = Object.keys(associations);
|
|
68
|
-
include.forEach((i) => {
|
|
69
|
-
validateQueryAttribute(i.model, associationsKeys);
|
|
70
|
-
const { rawAttributes } = associations[i.model].target;
|
|
71
|
-
if (include.where) {
|
|
72
|
-
validateQueryPayload(i.where, rawAttributes);
|
|
73
|
-
}
|
|
74
|
-
if (include.order) {
|
|
75
|
-
validateOrderAttributes(i.order, rawAttributes);
|
|
76
|
-
}
|
|
77
|
-
if (!lodash_1.default.isNil(include.required) && !lodash_1.default.isBoolean(include.required)) {
|
|
78
|
-
utils_1.throwBadRequestError('include.required must be a boolean');
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
exports.validatePayload = ({ query = {}, order = [], attributes = [], include = [], page = utils_1.PAGE_DEFAULT, perPage = utils_1.PER_PAGE_DEFAULT, }, model) => {
|
|
55
|
+
exports.validatePayload = ({ query = {}, order = [], attributes = [], }, model) => {
|
|
83
56
|
const rawAttributes = Object.keys(model.rawAttributes);
|
|
84
|
-
const associationModels = Object.keys((model === null || model === void 0 ? void 0 : model.associations) || {});
|
|
85
57
|
if (!attributes || attributes.length === 0) {
|
|
86
58
|
// eslint-disable-next-line no-param-reassign
|
|
87
59
|
attributes = rawAttributes;
|
|
@@ -89,14 +61,7 @@ exports.validatePayload = ({ query = {}, order = [], attributes = [], include =
|
|
|
89
61
|
else {
|
|
90
62
|
validateAttributes(attributes, rawAttributes);
|
|
91
63
|
}
|
|
92
|
-
validateOrderAttributes(order, rawAttributes
|
|
64
|
+
validateOrderAttributes(order, rawAttributes);
|
|
93
65
|
validateQueryPayload(query, rawAttributes);
|
|
94
|
-
if (include.length) {
|
|
95
|
-
validateIncludePayload(include, model === null || model === void 0 ? void 0 : model.associations);
|
|
96
|
-
}
|
|
97
|
-
validatePagination({
|
|
98
|
-
page,
|
|
99
|
-
perPage,
|
|
100
|
-
});
|
|
101
66
|
return true;
|
|
102
67
|
};
|
|
@@ -78,54 +78,4 @@ describe('validations test', () => {
|
|
|
78
78
|
expect(error.statusCode).toBe(400);
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
|
-
it('check order validation - order by included model', () => {
|
|
82
|
-
const payload = _1.validatePayload({ order: ['status.title'] }, {
|
|
83
|
-
rawAttributes: {
|
|
84
|
-
startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
|
|
85
|
-
},
|
|
86
|
-
associations: {
|
|
87
|
-
status: {},
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
expect(payload).toBe(true);
|
|
91
|
-
});
|
|
92
|
-
it('check order validation - order by included model descending', () => {
|
|
93
|
-
const payload = _1.validatePayload({ order: ['-status.title'] }, {
|
|
94
|
-
rawAttributes: {
|
|
95
|
-
startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '',
|
|
96
|
-
},
|
|
97
|
-
associations: {
|
|
98
|
-
status: {},
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
expect(payload).toBe(true);
|
|
102
|
-
});
|
|
103
|
-
it('check order validation - order by json field', () => {
|
|
104
|
-
const payload = _1.validatePayload({ order: ['status.title'] }, {
|
|
105
|
-
rawAttributes: {
|
|
106
|
-
startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', status: '',
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
expect(payload).toBe(true);
|
|
110
|
-
});
|
|
111
|
-
it('check order validation - order by json field desc', () => {
|
|
112
|
-
const payload = _1.validatePayload({ order: ['-status.title'] }, {
|
|
113
|
-
rawAttributes: {
|
|
114
|
-
startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', status: '',
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
expect(payload).toBe(true);
|
|
118
|
-
});
|
|
119
|
-
it('check order validation - try order by json field that doesnt exist', () => {
|
|
120
|
-
try {
|
|
121
|
-
_1.validatePayload({ order: ['-stas.title'] }, {
|
|
122
|
-
rawAttributes: {
|
|
123
|
-
startTime: '', endTime: '', currencySymbol: '', currencyCode: '', startStationId: '', status: '',
|
|
124
|
-
},
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
expect(error.statusCode).toBe(400);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
81
|
});
|