@flusys/nestjs-shared 6.0.2 → 6.1.1
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/cjs/classes/api-controller.class.spec.js +684 -0
- package/cjs/classes/api-service.class.spec.js +809 -0
- package/cjs/classes/handle-custome-db.spec.js +82 -0
- package/cjs/classes/hybrid-cache.class.spec.js +168 -0
- package/cjs/classes/winston.logger.class.spec.js +330 -0
- package/cjs/decorators/api-response.decorator.spec.js +126 -0
- package/cjs/decorators/current-user.decorator.spec.js +74 -0
- package/cjs/decorators/log-action.decorator.spec.js +353 -0
- package/cjs/decorators/public.decorator.spec.js +50 -0
- package/cjs/decorators/require-permission.decorator.spec.js +147 -0
- package/cjs/exceptions/base-app.exception.spec.js +157 -0
- package/cjs/exceptions/permission.exception.spec.js +82 -0
- package/cjs/filters/global-exception.filter.spec.js +440 -0
- package/cjs/guards/jwt-auth.guard.spec.js +75 -0
- package/cjs/guards/optional-jwt-auth.guard.spec.js +55 -0
- package/cjs/guards/permission.guard.spec.js +358 -0
- package/cjs/interceptors/delete-empty-id-from-body.interceptor.spec.js +107 -0
- package/cjs/interceptors/idempotency.interceptor.spec.js +116 -0
- package/cjs/interceptors/response-meta.interceptor.spec.js +89 -0
- package/cjs/interceptors/set-user-field-on-body.interceptor.spec.js +128 -0
- package/cjs/interceptors/slug.interceptor.spec.js +110 -0
- package/cjs/middlewares/logger.middleware.spec.js +462 -0
- package/cjs/modules/cache/cache.module.spec.js +48 -0
- package/cjs/modules/datasource/multi-tenant-datasource.service.spec.js +381 -0
- package/cjs/modules/utils/utils.service.spec.js +169 -0
- package/cjs/utils/date-time.util.spec.js +84 -0
- package/cjs/utils/html-sanitizer.util.spec.js +76 -0
- package/cjs/utils/permission-cache-key.util.spec.js +88 -0
- package/cjs/utils/query-helpers.util.spec.js +209 -0
- package/cjs/utils/request.util.spec.js +249 -0
- package/cjs/utils/string.util.spec.js +63 -0
- package/fesm/classes/api-controller.class.spec.js +680 -0
- package/fesm/classes/api-service.class.spec.js +805 -0
- package/fesm/classes/handle-custome-db.spec.js +78 -0
- package/fesm/classes/hybrid-cache.class.spec.js +164 -0
- package/fesm/classes/winston.logger.class.spec.js +327 -0
- package/fesm/decorators/api-response.decorator.spec.js +122 -0
- package/fesm/decorators/current-user.decorator.spec.js +73 -0
- package/fesm/decorators/log-action.decorator.spec.js +349 -0
- package/fesm/decorators/public.decorator.spec.js +46 -0
- package/fesm/decorators/require-permission.decorator.spec.js +143 -0
- package/fesm/exceptions/base-app.exception.spec.js +153 -0
- package/fesm/exceptions/permission.exception.spec.js +78 -0
- package/fesm/filters/global-exception.filter.spec.js +436 -0
- package/fesm/guards/jwt-auth.guard.spec.js +71 -0
- package/fesm/guards/optional-jwt-auth.guard.spec.js +51 -0
- package/fesm/guards/permission.guard.spec.js +354 -0
- package/fesm/interceptors/delete-empty-id-from-body.interceptor.spec.js +103 -0
- package/fesm/interceptors/idempotency.interceptor.spec.js +112 -0
- package/fesm/interceptors/response-meta.interceptor.spec.js +85 -0
- package/fesm/interceptors/set-user-field-on-body.interceptor.spec.js +124 -0
- package/fesm/interceptors/slug.interceptor.spec.js +106 -0
- package/fesm/middlewares/logger.middleware.spec.js +459 -0
- package/fesm/modules/cache/cache.module.spec.js +44 -0
- package/fesm/modules/datasource/multi-tenant-datasource.service.spec.js +377 -0
- package/fesm/modules/utils/utils.service.spec.js +165 -0
- package/fesm/utils/date-time.util.spec.js +80 -0
- package/fesm/utils/html-sanitizer.util.spec.js +72 -0
- package/fesm/utils/permission-cache-key.util.spec.js +84 -0
- package/fesm/utils/query-helpers.util.spec.js +205 -0
- package/fesm/utils/request.util.spec.js +245 -0
- package/fesm/utils/string.util.spec.js +59 -0
- package/package.json +2 -2
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _core = require("@nestjs/core");
|
|
6
|
+
const _constants = require("../constants");
|
|
7
|
+
const _requirepermissiondecorator = require("./require-permission.decorator");
|
|
8
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
9
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
11
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
12
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13
|
+
}
|
|
14
|
+
function _ts_metadata(k, v) {
|
|
15
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
16
|
+
}
|
|
17
|
+
describe('permission decorators', ()=>{
|
|
18
|
+
const reflector = new _core.Reflector();
|
|
19
|
+
describe('RequirePermission', ()=>{
|
|
20
|
+
it('should set metadata with AND operator for multiple permissions', ()=>{
|
|
21
|
+
let Controller = class Controller {
|
|
22
|
+
handler() {}
|
|
23
|
+
};
|
|
24
|
+
_ts_decorate([
|
|
25
|
+
(0, _requirepermissiondecorator.RequirePermission)('user.read', 'user.write'),
|
|
26
|
+
_ts_metadata("design:type", Function),
|
|
27
|
+
_ts_metadata("design:paramtypes", []),
|
|
28
|
+
_ts_metadata("design:returntype", void 0)
|
|
29
|
+
], Controller.prototype, "handler", null);
|
|
30
|
+
const metadata = reflector.get(_constants.PERMISSIONS_KEY, Controller.prototype.handler);
|
|
31
|
+
expect(metadata).toEqual({
|
|
32
|
+
permissions: [
|
|
33
|
+
'user.read',
|
|
34
|
+
'user.write'
|
|
35
|
+
],
|
|
36
|
+
operator: 'AND'
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
it('should set metadata for a single permission', ()=>{
|
|
40
|
+
let Controller = class Controller {
|
|
41
|
+
handler() {}
|
|
42
|
+
};
|
|
43
|
+
_ts_decorate([
|
|
44
|
+
(0, _requirepermissiondecorator.RequirePermission)('user.read'),
|
|
45
|
+
_ts_metadata("design:type", Function),
|
|
46
|
+
_ts_metadata("design:paramtypes", []),
|
|
47
|
+
_ts_metadata("design:returntype", void 0)
|
|
48
|
+
], Controller.prototype, "handler", null);
|
|
49
|
+
const metadata = reflector.get(_constants.PERMISSIONS_KEY, Controller.prototype.handler);
|
|
50
|
+
expect(metadata).toEqual({
|
|
51
|
+
permissions: [
|
|
52
|
+
'user.read'
|
|
53
|
+
],
|
|
54
|
+
operator: 'AND'
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
it('should set metadata with an empty permissions array when called with no args', ()=>{
|
|
58
|
+
let Controller = class Controller {
|
|
59
|
+
handler() {}
|
|
60
|
+
};
|
|
61
|
+
_ts_decorate([
|
|
62
|
+
(0, _requirepermissiondecorator.RequirePermission)(),
|
|
63
|
+
_ts_metadata("design:type", Function),
|
|
64
|
+
_ts_metadata("design:paramtypes", []),
|
|
65
|
+
_ts_metadata("design:returntype", void 0)
|
|
66
|
+
], Controller.prototype, "handler", null);
|
|
67
|
+
const metadata = reflector.get(_constants.PERMISSIONS_KEY, Controller.prototype.handler);
|
|
68
|
+
expect(metadata).toEqual({
|
|
69
|
+
permissions: [],
|
|
70
|
+
operator: 'AND'
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
describe('RequireAnyPermission', ()=>{
|
|
75
|
+
it('should set metadata with OR operator', ()=>{
|
|
76
|
+
let Controller = class Controller {
|
|
77
|
+
handler() {}
|
|
78
|
+
};
|
|
79
|
+
_ts_decorate([
|
|
80
|
+
(0, _requirepermissiondecorator.RequireAnyPermission)('admin', 'manager'),
|
|
81
|
+
_ts_metadata("design:type", Function),
|
|
82
|
+
_ts_metadata("design:paramtypes", []),
|
|
83
|
+
_ts_metadata("design:returntype", void 0)
|
|
84
|
+
], Controller.prototype, "handler", null);
|
|
85
|
+
const metadata = reflector.get(_constants.PERMISSIONS_KEY, Controller.prototype.handler);
|
|
86
|
+
expect(metadata).toEqual({
|
|
87
|
+
permissions: [
|
|
88
|
+
'admin',
|
|
89
|
+
'manager'
|
|
90
|
+
],
|
|
91
|
+
operator: 'OR'
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
describe('RequirePermissionLogic', ()=>{
|
|
96
|
+
it('should set metadata with a raw string permission', ()=>{
|
|
97
|
+
let Controller = class Controller {
|
|
98
|
+
handler() {}
|
|
99
|
+
};
|
|
100
|
+
_ts_decorate([
|
|
101
|
+
(0, _requirepermissiondecorator.RequirePermissionLogic)('users.read'),
|
|
102
|
+
_ts_metadata("design:type", Function),
|
|
103
|
+
_ts_metadata("design:paramtypes", []),
|
|
104
|
+
_ts_metadata("design:returntype", void 0)
|
|
105
|
+
], Controller.prototype, "handler", null);
|
|
106
|
+
const metadata = reflector.get(_constants.PERMISSIONS_KEY, Controller.prototype.handler);
|
|
107
|
+
expect(metadata).toBe('users.read');
|
|
108
|
+
});
|
|
109
|
+
it('should set metadata with a complex logic tree', ()=>{
|
|
110
|
+
const logic = {
|
|
111
|
+
type: 'group',
|
|
112
|
+
operator: 'AND',
|
|
113
|
+
children: [
|
|
114
|
+
{
|
|
115
|
+
type: 'action',
|
|
116
|
+
actionId: 'users.read'
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
type: 'group',
|
|
120
|
+
operator: 'OR',
|
|
121
|
+
children: [
|
|
122
|
+
{
|
|
123
|
+
type: 'action',
|
|
124
|
+
actionId: 'admin'
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
type: 'action',
|
|
128
|
+
actionId: 'manager'
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
};
|
|
134
|
+
let Controller = class Controller {
|
|
135
|
+
handler() {}
|
|
136
|
+
};
|
|
137
|
+
_ts_decorate([
|
|
138
|
+
(0, _requirepermissiondecorator.RequirePermissionLogic)(logic),
|
|
139
|
+
_ts_metadata("design:type", Function),
|
|
140
|
+
_ts_metadata("design:paramtypes", []),
|
|
141
|
+
_ts_metadata("design:returntype", void 0)
|
|
142
|
+
], Controller.prototype, "handler", null);
|
|
143
|
+
const metadata = reflector.get(_constants.PERMISSIONS_KEY, Controller.prototype.handler);
|
|
144
|
+
expect(metadata).toEqual(logic);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _common = require("@nestjs/common");
|
|
6
|
+
const _messagekeys = require("../constants/message-keys");
|
|
7
|
+
const _baseappexception = require("./base-app.exception");
|
|
8
|
+
describe('BaseAppException', ()=>{
|
|
9
|
+
it('should default status to BAD_REQUEST when not provided', ()=>{
|
|
10
|
+
const exception = new _baseappexception.BaseAppException({
|
|
11
|
+
message: 'oops'
|
|
12
|
+
});
|
|
13
|
+
expect(exception.getStatus()).toBe(_common.HttpStatus.BAD_REQUEST);
|
|
14
|
+
});
|
|
15
|
+
it('should default messageKey to ERROR_MESSAGES.GENERIC when not provided', ()=>{
|
|
16
|
+
const exception = new _baseappexception.BaseAppException({
|
|
17
|
+
message: 'oops'
|
|
18
|
+
});
|
|
19
|
+
expect(exception.messageKey).toBe(_messagekeys.ERROR_MESSAGES.GENERIC);
|
|
20
|
+
});
|
|
21
|
+
it('should use the provided status, messageKey, messageVariables, errors, and metadata', ()=>{
|
|
22
|
+
const errors = [
|
|
23
|
+
{
|
|
24
|
+
field: 'name',
|
|
25
|
+
message: 'required'
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
const exception = new _baseappexception.BaseAppException({
|
|
29
|
+
message: 'Invalid',
|
|
30
|
+
messageKey: 'custom.key',
|
|
31
|
+
messageVariables: {
|
|
32
|
+
foo: 'bar'
|
|
33
|
+
},
|
|
34
|
+
status: _common.HttpStatus.UNPROCESSABLE_ENTITY,
|
|
35
|
+
errors,
|
|
36
|
+
metadata: {
|
|
37
|
+
extra: true
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
expect(exception.getStatus()).toBe(_common.HttpStatus.UNPROCESSABLE_ENTITY);
|
|
41
|
+
expect(exception.messageKey).toBe('custom.key');
|
|
42
|
+
expect(exception.messageVariables).toEqual({
|
|
43
|
+
foo: 'bar'
|
|
44
|
+
});
|
|
45
|
+
expect(exception.errors).toEqual(errors);
|
|
46
|
+
expect(exception.metadata).toEqual({
|
|
47
|
+
extra: true
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
it('should build an HttpException response body with success:false', ()=>{
|
|
51
|
+
const exception = new _baseappexception.BaseAppException({
|
|
52
|
+
message: 'oops',
|
|
53
|
+
messageKey: 'k'
|
|
54
|
+
});
|
|
55
|
+
expect(exception.getResponse()).toEqual({
|
|
56
|
+
success: false,
|
|
57
|
+
message: 'oops',
|
|
58
|
+
messageKey: 'k',
|
|
59
|
+
messageVariables: undefined,
|
|
60
|
+
errors: undefined
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe('NotFoundException', ()=>{
|
|
64
|
+
it('should build a message with id when id is provided', ()=>{
|
|
65
|
+
const exception = new _baseappexception.NotFoundException('User', 'uuid-1');
|
|
66
|
+
expect(exception.getStatus()).toBe(_common.HttpStatus.NOT_FOUND);
|
|
67
|
+
expect(exception.message).toBe('User with id "uuid-1" not found');
|
|
68
|
+
expect(exception.messageKey).toBe(_messagekeys.ERROR_MESSAGES.NOT_FOUND);
|
|
69
|
+
expect(exception.metadata).toEqual({
|
|
70
|
+
entity: 'User',
|
|
71
|
+
id: 'uuid-1'
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
it('should build a message without id when id is omitted', ()=>{
|
|
75
|
+
const exception = new _baseappexception.NotFoundException('User');
|
|
76
|
+
expect(exception.message).toBe('User not found');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe('ValidationException', ()=>{
|
|
80
|
+
it('should carry the validation errors and BAD_REQUEST status', ()=>{
|
|
81
|
+
const errors = [
|
|
82
|
+
{
|
|
83
|
+
field: 'email',
|
|
84
|
+
message: 'invalid format'
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
const exception = new _baseappexception.ValidationException(errors);
|
|
88
|
+
expect(exception.getStatus()).toBe(_common.HttpStatus.BAD_REQUEST);
|
|
89
|
+
expect(exception.messageKey).toBe(_messagekeys.ERROR_MESSAGES.VALIDATION);
|
|
90
|
+
expect(exception.errors).toEqual(errors);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe('UnauthorizedException', ()=>{
|
|
94
|
+
it('should use the default message when none is provided', ()=>{
|
|
95
|
+
const exception = new _baseappexception.UnauthorizedException();
|
|
96
|
+
expect(exception.getStatus()).toBe(_common.HttpStatus.UNAUTHORIZED);
|
|
97
|
+
expect(exception.message).toBe('Unauthorized access');
|
|
98
|
+
expect(exception.messageKey).toBe(_messagekeys.ERROR_MESSAGES.UNAUTHORIZED);
|
|
99
|
+
});
|
|
100
|
+
it('should use a custom message when provided', ()=>{
|
|
101
|
+
const exception = new _baseappexception.UnauthorizedException('Custom message');
|
|
102
|
+
expect(exception.message).toBe('Custom message');
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
describe('ForbiddenException', ()=>{
|
|
106
|
+
it('should default to "Access forbidden"', ()=>{
|
|
107
|
+
const exception = new _baseappexception.ForbiddenException();
|
|
108
|
+
expect(exception.getStatus()).toBe(_common.HttpStatus.FORBIDDEN);
|
|
109
|
+
expect(exception.message).toBe('Access forbidden');
|
|
110
|
+
expect(exception.messageKey).toBe(_messagekeys.ERROR_MESSAGES.FORBIDDEN);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe('ConflictException', ()=>{
|
|
114
|
+
it('should include the field in the message and metadata when provided', ()=>{
|
|
115
|
+
const exception = new _baseappexception.ConflictException('User', 'email');
|
|
116
|
+
expect(exception.getStatus()).toBe(_common.HttpStatus.CONFLICT);
|
|
117
|
+
expect(exception.message).toBe('User with this email already exists');
|
|
118
|
+
expect(exception.messageVariables).toEqual({
|
|
119
|
+
entity: 'User',
|
|
120
|
+
field: 'email'
|
|
121
|
+
});
|
|
122
|
+
expect(exception.metadata).toEqual({
|
|
123
|
+
entity: 'User',
|
|
124
|
+
field: 'email'
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
it('should omit the field when not provided', ()=>{
|
|
128
|
+
const exception = new _baseappexception.ConflictException('User');
|
|
129
|
+
expect(exception.message).toBe('User already exists');
|
|
130
|
+
expect(exception.messageVariables).toEqual({
|
|
131
|
+
entity: 'User'
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
describe('InternalServerException', ()=>{
|
|
136
|
+
it('should default to "Internal server error"', ()=>{
|
|
137
|
+
const exception = new _baseappexception.InternalServerException();
|
|
138
|
+
expect(exception.getStatus()).toBe(_common.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
139
|
+
expect(exception.message).toBe('Internal server error');
|
|
140
|
+
expect(exception.messageKey).toBe(_messagekeys.ERROR_MESSAGES.INTERNAL);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
describe('ServiceUnavailableException', ()=>{
|
|
144
|
+
it('should build a message including the service name', ()=>{
|
|
145
|
+
const exception = new _baseappexception.ServiceUnavailableException('Email');
|
|
146
|
+
expect(exception.getStatus()).toBe(_common.HttpStatus.SERVICE_UNAVAILABLE);
|
|
147
|
+
expect(exception.message).toBe('Email is temporarily unavailable');
|
|
148
|
+
expect(exception.messageKey).toBe(_messagekeys.ERROR_MESSAGES.SERVICE_UNAVAILABLE);
|
|
149
|
+
expect(exception.messageVariables).toEqual({
|
|
150
|
+
service: 'Email'
|
|
151
|
+
});
|
|
152
|
+
expect(exception.metadata).toEqual({
|
|
153
|
+
service: 'Email'
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _common = require("@nestjs/common");
|
|
6
|
+
const _messagekeys = require("../constants/message-keys");
|
|
7
|
+
const _permissionexception = require("./permission.exception");
|
|
8
|
+
describe('permission exceptions', ()=>{
|
|
9
|
+
describe('PermissionSystemUnavailableException', ()=>{
|
|
10
|
+
it('should be an InternalServerErrorException with the expected response body', ()=>{
|
|
11
|
+
const exception = new _permissionexception.PermissionSystemUnavailableException();
|
|
12
|
+
expect(exception).toBeInstanceOf(_common.InternalServerErrorException);
|
|
13
|
+
expect(exception.getResponse()).toMatchObject({
|
|
14
|
+
success: false,
|
|
15
|
+
message: 'Permission system temporarily unavailable',
|
|
16
|
+
messageKey: _messagekeys.ERROR_MESSAGES.PERMISSION_SYSTEM_UNAVAILABLE
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
describe('InsufficientPermissionsException', ()=>{
|
|
21
|
+
it('should default to AND operator and matching messageKey', ()=>{
|
|
22
|
+
const exception = new _permissionexception.InsufficientPermissionsException([
|
|
23
|
+
'user.create',
|
|
24
|
+
'user.update'
|
|
25
|
+
]);
|
|
26
|
+
expect(exception).toBeInstanceOf(_common.ForbiddenException);
|
|
27
|
+
expect(exception.getResponse()).toMatchObject({
|
|
28
|
+
success: false,
|
|
29
|
+
message: 'Insufficient permissions',
|
|
30
|
+
messageKey: _messagekeys.ERROR_MESSAGES.INSUFFICIENT_PERMISSIONS,
|
|
31
|
+
messageVariables: {
|
|
32
|
+
permissions: 'user.create, user.update'
|
|
33
|
+
},
|
|
34
|
+
missingPermissions: [
|
|
35
|
+
'user.create',
|
|
36
|
+
'user.update'
|
|
37
|
+
],
|
|
38
|
+
operator: 'AND'
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
it('should use the OR messageKey when operator is OR', ()=>{
|
|
42
|
+
const exception = new _permissionexception.InsufficientPermissionsException([
|
|
43
|
+
'admin',
|
|
44
|
+
'manager'
|
|
45
|
+
], 'OR');
|
|
46
|
+
expect(exception.getResponse()).toMatchObject({
|
|
47
|
+
messageKey: _messagekeys.ERROR_MESSAGES.INSUFFICIENT_PERMISSIONS_OR,
|
|
48
|
+
operator: 'OR'
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
it('should join a single missing permission without a separator', ()=>{
|
|
52
|
+
const exception = new _permissionexception.InsufficientPermissionsException([
|
|
53
|
+
'user.create'
|
|
54
|
+
]);
|
|
55
|
+
expect(exception.getResponse()).toMatchObject({
|
|
56
|
+
messageVariables: {
|
|
57
|
+
permissions: 'user.create'
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
it('should handle an empty missing-permissions list', ()=>{
|
|
62
|
+
const exception = new _permissionexception.InsufficientPermissionsException([]);
|
|
63
|
+
expect(exception.getResponse()).toMatchObject({
|
|
64
|
+
messageVariables: {
|
|
65
|
+
permissions: ''
|
|
66
|
+
},
|
|
67
|
+
missingPermissions: []
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe('NoPermissionsFoundException', ()=>{
|
|
72
|
+
it('should be a ForbiddenException with the expected response body', ()=>{
|
|
73
|
+
const exception = new _permissionexception.NoPermissionsFoundException();
|
|
74
|
+
expect(exception).toBeInstanceOf(_common.ForbiddenException);
|
|
75
|
+
expect(exception.getResponse()).toMatchObject({
|
|
76
|
+
success: false,
|
|
77
|
+
message: 'No permissions found',
|
|
78
|
+
messageKey: _messagekeys.ERROR_MESSAGES.NO_PERMISSIONS_FOUND
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|