@hosterai/types 0.0.17 → 0.0.19
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/README.md +12 -9
- package/dist/decorators/all-or-none-validator.spec.d.ts +1 -0
- package/dist/decorators/all-or-none-validator.spec.js +91 -0
- package/dist/decorators/all-or-none.validator.d.ts +2 -0
- package/dist/decorators/all-or-none.validator.js +71 -0
- package/dist/decorators/at-least-one-non-empty-validator.spec.d.ts +1 -0
- package/dist/decorators/at-least-one-non-empty-validator.spec.js +79 -0
- package/dist/decorators/at-least-one-non-empty.validator.d.ts +2 -0
- package/dist/decorators/at-least-one-non-empty.validator.js +43 -0
- package/dist/decorators/is-of-allowed-types-validator.spec.d.ts +1 -0
- package/dist/decorators/is-of-allowed-types-validator.spec.js +188 -0
- package/dist/decorators/is-of-allowed-types.validator.d.ts +16 -0
- package/dist/decorators/is-of-allowed-types.validator.js +105 -0
- package/dist/decorators/is-one-of-validator.spec.d.ts +1 -0
- package/dist/decorators/is-one-of-validator.spec.js +51 -0
- package/dist/decorators/is-one-of.validator.d.ts +2 -0
- package/dist/decorators/is-one-of.validator.js +19 -0
- package/dist/decorators/is-plain-object-validator.spec.d.ts +1 -0
- package/dist/decorators/is-plain-object-validator.spec.js +46 -0
- package/dist/decorators/is-plain-object.validator.d.ts +2 -0
- package/dist/decorators/is-plain-object.validator.js +30 -0
- package/dist/decorators/is-property-forbidden-validator.spec.d.ts +1 -0
- package/dist/decorators/is-property-forbidden-validator.spec.js +62 -0
- package/dist/decorators/is-property-forbidden.validator.d.ts +2 -0
- package/dist/decorators/is-property-forbidden.validator.js +22 -0
- package/dist/decorators/is-regex-validator.spec.d.ts +1 -0
- package/dist/decorators/is-regex-validator.spec.js +46 -0
- package/dist/decorators/is-regex.validator.d.ts +2 -0
- package/dist/decorators/is-regex.validator.js +32 -0
- package/dist/decorators/min-less-or-equal-validator.spec.d.ts +1 -0
- package/dist/decorators/min-less-or-equal-validator.spec.js +60 -0
- package/dist/decorators/min-less-or-equal.validator.d.ts +2 -0
- package/dist/decorators/min-less-or-equal.validator.js +58 -0
- package/dist/decorators/unique-field-in-array-validator.spec.d.ts +1 -0
- package/dist/decorators/unique-field-in-array-validator.spec.js +39 -0
- package/dist/decorators/unique-field-in-array.validator.d.ts +6 -0
- package/dist/decorators/unique-field-in-array.validator.js +47 -0
- package/dist/dtos/action.dto.js +25 -1
- package/dist/dtos/admin-panel.dto.d.ts +38 -0
- package/dist/dtos/admin-panel.dto.js +241 -0
- package/dist/dtos/client-panel.dto.d.ts +24 -0
- package/dist/dtos/client-panel.dto.js +105 -0
- package/dist/dtos/company-data.dto.js +1 -1
- package/dist/dtos/field-option.dto.js +16 -0
- package/dist/dtos/field.dto.d.ts +2 -0
- package/dist/dtos/field.dto.js +112 -2
- package/dist/dtos/info.dto.d.ts +4 -79
- package/dist/dtos/info.dto.js +141 -0
- package/dist/dtos/menu.dto.d.ts +5 -6
- package/dist/dtos/menu.dto.js +108 -0
- package/dist/dtos/multilang-text.dto.js +1 -1
- package/dist/dtos/notification/notification-info.dto.js +42 -0
- package/dist/dtos/product/product-info.dto.js +73 -0
- package/dist/dtos/product/requests/product-downgradeable-request.dto.d.ts +18 -0
- package/dist/dtos/product/requests/product-downgradeable-request.dto.js +37 -0
- package/dist/dtos/product/requests/product-upgradeable-request.dto.d.ts +18 -0
- package/dist/dtos/product/requests/product-upgradeable-request.dto.js +37 -0
- package/dist/dtos/product/responses/product-downgradeable-response.dto.d.ts +22 -0
- package/dist/dtos/product/responses/product-downgradeable-response.dto.js +11 -0
- package/dist/dtos/product/responses/product-upgradeable-response.dto.d.ts +22 -0
- package/dist/dtos/product/responses/product-upgradeable-response.dto.js +11 -0
- package/dist/dtos/settings.dto.d.ts +14 -0
- package/dist/dtos/settings.dto.js +81 -0
- package/dist/dtos/tab.dto.js +32 -0
- package/dist/dtos/unit.dto.js +47 -0
- package/dist/index.d.ts +23 -7
- package/dist/index.js +26 -7
- package/dist/openapi/schemas/components.schemas.d.ts +991 -0
- package/dist/openapi/schemas/components.schemas.js +2552 -0
- package/dist/transformers/menu.transformer.d.ts +2 -0
- package/dist/transformers/menu.transformer.js +16 -0
- package/dist/transformers/settings.transformer.d.ts +1 -0
- package/dist/transformers/settings.transformer.js +15 -0
- package/dist/validators/action-validator.spec.d.ts +1 -0
- package/dist/validators/action-validator.spec.js +67 -0
- package/dist/validators/admin-panel-more-actions-validator.spec.d.ts +1 -0
- package/dist/validators/admin-panel-more-actions-validator.spec.js +129 -0
- package/dist/validators/admin-panel-more-actions.validator.d.ts +2 -0
- package/dist/validators/admin-panel-more-actions.validator.js +11 -0
- package/dist/validators/admin-panel-tabs-validator.spec.d.ts +1 -0
- package/dist/validators/admin-panel-tabs-validator.spec.js +39 -0
- package/dist/validators/admin-panel-tabs.validator.d.ts +2 -0
- package/dist/validators/admin-panel-tabs.validator.js +11 -0
- package/dist/validators/admin-panel-validator.spec.d.ts +1 -0
- package/dist/validators/admin-panel-validator.spec.js +112 -0
- package/dist/validators/admin-panel.validator.d.ts +2 -0
- package/dist/validators/admin-panel.validator.js +14 -0
- package/dist/validators/client-data-validator.spec.d.ts +1 -0
- package/dist/validators/client-data-validator.spec.js +35 -0
- package/dist/validators/client-panel-validator.spec.d.ts +1 -0
- package/dist/validators/client-panel-validator.spec.js +51 -0
- package/dist/validators/client-panel.validator.d.ts +2 -0
- package/dist/validators/client-panel.validator.js +14 -0
- package/dist/validators/company-data-validator.spec.d.ts +1 -0
- package/dist/validators/company-data-validator.spec.js +73 -0
- package/dist/validators/field-option-validator.spec.d.ts +1 -0
- package/dist/validators/field-option-validator.spec.js +28 -0
- package/dist/validators/field-option.validator.d.ts +2 -0
- package/dist/validators/field-option.validator.js +11 -0
- package/dist/validators/field-validator.spec.d.ts +1 -0
- package/dist/validators/field-validator.spec.js +102 -0
- package/dist/validators/jwt-validator.spec.d.ts +2 -0
- package/dist/validators/jwt-validator.spec.js +43 -0
- package/dist/validators/menu-with-submenu-validator.spec.d.ts +1 -0
- package/dist/validators/menu-with-submenu-validator.spec.js +52 -0
- package/dist/validators/menu-with-submenu.validator.d.ts +2 -0
- package/dist/validators/menu-with-submenu.validator.js +11 -0
- package/dist/validators/menu-with-url-validator.spec.d.ts +1 -0
- package/dist/validators/menu-with-url-validator.spec.js +70 -0
- package/dist/validators/menu-with-url.validator.d.ts +2 -0
- package/dist/validators/menu-with-url.validator.js +11 -0
- package/dist/validators/multilang-text-validator.spec.d.ts +1 -0
- package/dist/validators/multilang-text-validator.spec.js +33 -0
- package/dist/validators/notification-info-validator.spec.d.ts +1 -0
- package/dist/validators/notification-info-validator.spec.js +82 -0
- package/dist/validators/notification-info.validator.d.ts +7 -0
- package/dist/validators/notification-info.validator.js +16 -0
- package/dist/validators/notification-request-validator.spec.d.ts +1 -0
- package/dist/validators/notification-request-validator.spec.js +115 -0
- package/dist/validators/product-create-request-validator.spec.d.ts +2 -0
- package/dist/validators/product-create-request-validator.spec.js +44 -0
- package/dist/validators/product-delete-request-validator.spec.d.ts +1 -0
- package/dist/validators/product-delete-request-validator.spec.js +40 -0
- package/dist/validators/product-downgradable-request-validator.spec.d.ts +1 -0
- package/dist/validators/product-downgradable-request-validator.spec.js +40 -0
- package/dist/validators/product-downgrade-request-validator.spec.d.ts +1 -0
- package/dist/validators/product-downgrade-request-validator.spec.js +46 -0
- package/dist/validators/product-downgradeable-request-validator.d.ts +8 -0
- package/dist/validators/product-downgradeable-request-validator.js +17 -0
- package/dist/validators/product-info-validator.spec.d.ts +1 -0
- package/dist/validators/product-info-validator.spec.js +259 -0
- package/dist/validators/product-info.validator.d.ts +2 -0
- package/dist/validators/product-info.validator.js +11 -0
- package/dist/validators/product-renew-request-validator.spec.d.ts +1 -0
- package/dist/validators/product-renew-request-validator.spec.js +40 -0
- package/dist/validators/product-suspend-request-validator.spec.d.ts +1 -0
- package/dist/validators/product-suspend-request-validator.spec.js +40 -0
- package/dist/validators/product-unsuspend-request-validator.spec.d.ts +1 -0
- package/dist/validators/product-unsuspend-request-validator.spec.js +40 -0
- package/dist/validators/product-upgradable-request-validator.spec.d.ts +1 -0
- package/dist/validators/product-upgradable-request-validator.spec.js +40 -0
- package/dist/validators/product-upgrade-request-validator.spec.d.ts +1 -0
- package/dist/validators/product-upgrade-request-validator.spec.js +46 -0
- package/dist/validators/product-upgradeable-request-validator.d.ts +8 -0
- package/dist/validators/product-upgradeable-request-validator.js +17 -0
- package/dist/validators/product-validate-attributes-request-validator.spec.d.ts +1 -0
- package/dist/validators/product-validate-attributes-request-validator.spec.js +27 -0
- package/dist/validators/receiver-email-validator.spec.d.ts +1 -0
- package/dist/validators/receiver-email-validator.spec.js +32 -0
- package/dist/validators/receiver-push-validator.spec.d.ts +1 -0
- package/dist/validators/receiver-push-validator.spec.js +31 -0
- package/dist/validators/receiver-sms-validator.spec.d.ts +1 -0
- package/dist/validators/receiver-sms-validator.spec.js +29 -0
- package/dist/validators/sender-email-validator.spec.d.ts +2 -0
- package/dist/validators/sender-email-validator.spec.js +62 -0
- package/dist/validators/sender-push-validator.spec.d.ts +1 -0
- package/dist/validators/sender-push-validator.spec.js +38 -0
- package/dist/validators/sender-sms-validator.spec.d.ts +1 -0
- package/dist/validators/sender-sms-validator.spec.js +22 -0
- package/dist/validators/settings-with-tabs-validator.spec.d.ts +1 -0
- package/dist/validators/settings-with-tabs-validator.spec.js +29 -0
- package/dist/validators/settings-with-tabs.validator.d.ts +2 -0
- package/dist/validators/settings-with-tabs.validator.js +11 -0
- package/dist/validators/settings-with-url-validator.spec.d.ts +1 -0
- package/dist/validators/settings-with-url-validator.spec.js +29 -0
- package/dist/validators/settings-with-url.validator.d.ts +2 -0
- package/dist/validators/settings-with-url.validator.js +11 -0
- package/dist/validators/unit-validator.spec.d.ts +1 -0
- package/dist/validators/unit-validator.spec.js +27 -0
- package/dist/validators/unit.validator.d.ts +2 -0
- package/dist/validators/unit.validator.js +11 -0
- package/package.json +4 -1
- package/dist/dtos/info/info-notification.dto.d.ts +0 -5
- package/dist/dtos/info/info-notification.dto.js +0 -7
- package/dist/dtos/info/info.dto.d.ts +0 -196
- package/dist/dtos/info/info.dto.js +0 -278
- package/dist/dtos/notification/notification-request.dto.d.ts +0 -20
- package/dist/dtos/notification/notification-request.dto.js +0 -31
- package/dist/dtos/receiver/receiver-email.dto.d.ts +0 -20
- package/dist/dtos/receiver/receiver-email.dto.js +0 -39
- package/dist/dtos/receiver/receiver-push.dto.d.ts +0 -15
- package/dist/dtos/receiver/receiver-push.dto.js +0 -31
- package/dist/dtos/receiver/receiver-sms.dto.d.ts +0 -11
- package/dist/dtos/receiver/receiver-sms.dto.js +0 -26
- package/dist/dtos/request.dto.d.ts +0 -20
- package/dist/dtos/request.dto.js +0 -31
- package/dist/dtos/sender/sender-email.dto.d.ts +0 -25
- package/dist/dtos/sender/sender-email.dto.js +0 -46
- package/dist/dtos/sender/sender-push.dto.d.ts +0 -31
- package/dist/dtos/sender/sender-push.dto.js +0 -50
- package/dist/dtos/sender/sender-sms.dto.d.ts +0 -15
- package/dist/dtos/sender/sender-sms.dto.js +0 -30
- package/dist/enums/message-type.enum.d.ts +0 -5
- package/dist/enums/message-type.enum.js +0 -9
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const field_option_validator_1 = require("./field-option.validator");
|
|
4
|
+
describe('validateFieldOptionDto', () => {
|
|
5
|
+
test.each([
|
|
6
|
+
// valid
|
|
7
|
+
[{ key: 'option1', value: 'Option 1' }, true],
|
|
8
|
+
[{ key: 'option2', value: 'Option 2', disabled: true }, true],
|
|
9
|
+
[{ key: 'option3', value: 'Option 3', disabled: false }, true],
|
|
10
|
+
// missing required
|
|
11
|
+
[{ value: 'Missing key' }, false],
|
|
12
|
+
[{ key: 'missingValue' }, false],
|
|
13
|
+
// wrong types
|
|
14
|
+
[{ key: 123, value: 'Valid string' }, false],
|
|
15
|
+
[{ key: 'validKey', value: 456 }, false],
|
|
16
|
+
[{ key: 'key', value: 'value', disabled: 'yes' }, false],
|
|
17
|
+
// disabled optional omitted
|
|
18
|
+
[{ key: 'noDisabled', value: 'Yes' }, true],
|
|
19
|
+
])('validates %# - %# %#', (input, expectedValid) => {
|
|
20
|
+
const errors = (0, field_option_validator_1.validateFieldOptionDto)(input);
|
|
21
|
+
if (expectedValid) {
|
|
22
|
+
expect(errors.length).toBe(0);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateFieldOptionDto = validateFieldOptionDto;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const field_option_dto_1 = require("../dtos/field-option.dto");
|
|
7
|
+
function validateFieldOptionDto(data) {
|
|
8
|
+
const dto = (0, class_transformer_1.plainToInstance)(field_option_dto_1.FieldOptionDto, data);
|
|
9
|
+
const errors = (0, class_validator_1.validateSync)(dto);
|
|
10
|
+
return errors;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const field_validator_1 = require("./field-validator");
|
|
5
|
+
const field_type_enum_1 = require("../enums/field-type.enum");
|
|
6
|
+
const language_enum_1 = require("../enums/language.enum");
|
|
7
|
+
const baseValidDto = {
|
|
8
|
+
id: 'test-id',
|
|
9
|
+
label: [{ language: language_enum_1.LanguageEnum.EN, text: 'Test Label' }],
|
|
10
|
+
value: 'test-value',
|
|
11
|
+
type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
|
|
12
|
+
required: true,
|
|
13
|
+
disabled: false,
|
|
14
|
+
hidden: false,
|
|
15
|
+
upgradable: false,
|
|
16
|
+
};
|
|
17
|
+
describe('FieldDto Validator', () => {
|
|
18
|
+
describe('Valid cases', () => {
|
|
19
|
+
it('should return no errors for a valid DTO', () => {
|
|
20
|
+
expect((0, field_validator_1.validateFieldDto)(baseValidDto)).toHaveLength(0);
|
|
21
|
+
});
|
|
22
|
+
it('should return no errors for a valid DTO with optional error messages', () => {
|
|
23
|
+
const dto = {
|
|
24
|
+
...baseValidDto,
|
|
25
|
+
regexValidationErrorMessage: [{ language: language_enum_1.LanguageEnum.EN, text: 'Invalid format' }],
|
|
26
|
+
remoteValidationErrorMessage: [{ language: language_enum_1.LanguageEnum.EN, text: 'Invalid value' }],
|
|
27
|
+
};
|
|
28
|
+
expect((0, field_validator_1.validateFieldDto)(dto)).toHaveLength(0);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe('Missing required fields', () => {
|
|
32
|
+
it('should return errors for all missing required fields (except upgradable)', () => {
|
|
33
|
+
const errors = (0, field_validator_1.validateFieldDto)({});
|
|
34
|
+
const requiredProps = ['id', 'label', 'value', 'type', 'required', 'disabled', 'hidden'];
|
|
35
|
+
for (const prop of requiredProps) {
|
|
36
|
+
expect(errors.some(e => e.property === prop)).toBe(true);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
it('should return error if value is missing', () => {
|
|
40
|
+
const dto = { ...baseValidDto };
|
|
41
|
+
delete dto.value;
|
|
42
|
+
const errors = (0, field_validator_1.validateFieldDto)(dto);
|
|
43
|
+
expect(errors.some(e => e.property === 'value')).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe('Invalid field values', () => {
|
|
47
|
+
it.each([
|
|
48
|
+
[{ ...baseValidDto, type: 'not-a-valid-type' }, 'type'],
|
|
49
|
+
[{}, 'id'],
|
|
50
|
+
[{ ...baseValidDto, regexValidation: 'regex', regexValidationErrorMessage: 'not-an-array' }, 'regexValidationErrorMessage'],
|
|
51
|
+
[{ ...baseValidDto, triggersRemoteValidation: true, remoteValidationErrorMessage: 'not-an-array' }, 'remoteValidationErrorMessage'],
|
|
52
|
+
])('should return error for invalid %s', (dto, expectedProp) => {
|
|
53
|
+
const errors = (0, field_validator_1.validateFieldDto)(dto);
|
|
54
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
55
|
+
expect(errors.some(e => e.property === expectedProp)).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe('Invalid `value` field', () => {
|
|
59
|
+
it.each([
|
|
60
|
+
[true, 'boolean'],
|
|
61
|
+
[null, 'null'],
|
|
62
|
+
[undefined, 'undefined'],
|
|
63
|
+
[{}, 'object'],
|
|
64
|
+
[[], 'array'],
|
|
65
|
+
])('should return error if value is invalid type (%s)', (invalidValue, _label) => {
|
|
66
|
+
const dto = { ...baseValidDto, value: invalidValue };
|
|
67
|
+
const errors = (0, field_validator_1.validateFieldDto)(dto);
|
|
68
|
+
expect(errors.some(e => e.property === 'value')).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
it('should return error if value is empty string when required', () => {
|
|
71
|
+
const dto = { ...baseValidDto, value: '' };
|
|
72
|
+
const errors = (0, field_validator_1.validateFieldDto)(dto);
|
|
73
|
+
expect(errors.some(e => e.property === 'value')).toBe(true);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
describe('Repeatable constraints (AllOrNone and Min<=Max)', () => {
|
|
77
|
+
it('should fail when only reapetableMin is present', () => {
|
|
78
|
+
const dto = { ...baseValidDto, reapetableMin: 1 };
|
|
79
|
+
const errors = (0, field_validator_1.validateFieldDto)(dto);
|
|
80
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
81
|
+
// Class-level error; ensure at least one constraint exists
|
|
82
|
+
expect(errors.some(e => e.constraints && (e.constraints['AllOrNone'] || Object.values(e.constraints).some(msg => msg.includes('All of'))))).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
it('should fail when only reapetableMax is present', () => {
|
|
85
|
+
const dto = { ...baseValidDto, reapetableMax: 2 };
|
|
86
|
+
const errors = (0, field_validator_1.validateFieldDto)(dto);
|
|
87
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
88
|
+
expect(errors.some(e => e.constraints && (e.constraints['AllOrNone'] || Object.values(e.constraints).some(msg => msg.includes('All of'))))).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
it('should pass when both present and reapetableMin <= reapetableMax', () => {
|
|
91
|
+
const dto = { ...baseValidDto, reapetableMin: 1, reapetableMax: 2 };
|
|
92
|
+
const errors = (0, field_validator_1.validateFieldDto)(dto);
|
|
93
|
+
expect(errors).toHaveLength(0);
|
|
94
|
+
});
|
|
95
|
+
it('should fail when both present and reapetableMin > reapetableMax', () => {
|
|
96
|
+
const dto = { ...baseValidDto, reapetableMin: 3, reapetableMax: 2 };
|
|
97
|
+
const errors = (0, field_validator_1.validateFieldDto)(dto);
|
|
98
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
99
|
+
expect(errors.some(e => e.constraints && (e.constraints['MinLessOrEqualMax'] || Object.values(e.constraints).some(msg => msg.includes('must be less than or equal'))))).toBe(true);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const jwt_validator_1 = require("./jwt-validator");
|
|
6
|
+
const roles_enum_1 = require("../enums/roles.enum");
|
|
7
|
+
describe('JwtDto Validator', () => {
|
|
8
|
+
it('should return no errors for valid DTO', () => {
|
|
9
|
+
const validDto = {
|
|
10
|
+
jwt: {
|
|
11
|
+
integrationId: '123',
|
|
12
|
+
companyId: '456',
|
|
13
|
+
acceptedRoles: [roles_enum_1.RolesEnum.FULL_ACCESS],
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
const errors = (0, jwt_validator_1.validateJwtDto)(validDto);
|
|
17
|
+
expect(errors).toHaveLength(0);
|
|
18
|
+
});
|
|
19
|
+
it('should return error when nested jwt object is missing', () => {
|
|
20
|
+
const invalidDto = {
|
|
21
|
+
// Missing jwt object
|
|
22
|
+
};
|
|
23
|
+
const errors = (0, jwt_validator_1.validateJwtDto)(invalidDto);
|
|
24
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
25
|
+
expect(errors.some((e) => e.property === 'jwt')).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
it('should return error when required fields in jwt are missing', () => {
|
|
28
|
+
var _a;
|
|
29
|
+
const invalidDto = {
|
|
30
|
+
jwt: {
|
|
31
|
+
// Missing integrationId and companyId
|
|
32
|
+
acceptedRoles: [roles_enum_1.RolesEnum.FULL_ACCESS],
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
const errors = (0, jwt_validator_1.validateJwtDto)(invalidDto);
|
|
36
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
37
|
+
// As the validation is on the nested object, the error will be in the children
|
|
38
|
+
const jwtErrors = (_a = errors[0]) === null || _a === void 0 ? void 0 : _a.children;
|
|
39
|
+
expect(jwtErrors).toBeDefined();
|
|
40
|
+
expect(jwtErrors.some((e) => e.property === 'integrationId')).toBe(true);
|
|
41
|
+
expect(jwtErrors.some((e) => e.property === 'companyId')).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const menu_with_submenu_validator_1 = require("./menu-with-submenu.validator");
|
|
5
|
+
describe('validateMenuDto', () => {
|
|
6
|
+
test.each([
|
|
7
|
+
['valid data with submenu',
|
|
8
|
+
{
|
|
9
|
+
type: 'with-submenu',
|
|
10
|
+
icon: 'https://example.com/icon.png',
|
|
11
|
+
label: 'Menu Label',
|
|
12
|
+
submenu: [
|
|
13
|
+
{ label: 'Submenu 1', url: 'https://example.com/sub1' }
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
true
|
|
17
|
+
],
|
|
18
|
+
['missing required icon',
|
|
19
|
+
{
|
|
20
|
+
type: 'with-submenu',
|
|
21
|
+
label: 'Menu Label',
|
|
22
|
+
submenu: [{ label: 'Submenu 1', url: 'https://example.com/sub1' }],
|
|
23
|
+
},
|
|
24
|
+
false
|
|
25
|
+
],
|
|
26
|
+
['missing submenu',
|
|
27
|
+
{
|
|
28
|
+
type: 'with-submenu',
|
|
29
|
+
icon: 'https://example.com/icon.png',
|
|
30
|
+
label: 'Menu Label',
|
|
31
|
+
},
|
|
32
|
+
false
|
|
33
|
+
],
|
|
34
|
+
['submenu with missing label',
|
|
35
|
+
{
|
|
36
|
+
type: 'with-submenu',
|
|
37
|
+
icon: 'https://example.com/icon.png',
|
|
38
|
+
label: 'Menu Label',
|
|
39
|
+
submenu: [{ url: 'https://example.com/sub1' }],
|
|
40
|
+
},
|
|
41
|
+
false
|
|
42
|
+
],
|
|
43
|
+
])('%s', (_, input, expectedValid) => {
|
|
44
|
+
const errors = (0, menu_with_submenu_validator_1.validateMenuWithSubmenuDto)(input);
|
|
45
|
+
if (expectedValid) {
|
|
46
|
+
expect(errors.length).toBe(0);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateMenuWithSubmenuDto = validateMenuWithSubmenuDto;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const menu_dto_1 = require("../dtos/menu.dto");
|
|
7
|
+
function validateMenuWithSubmenuDto(data) {
|
|
8
|
+
const dto = (0, class_transformer_1.plainToInstance)(menu_dto_1.MenuDtoWithSubmenu, data);
|
|
9
|
+
const errors = (0, class_validator_1.validateSync)(dto);
|
|
10
|
+
return errors;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const menu_with_url_validator_1 = require("./menu-with-url.validator");
|
|
5
|
+
describe('validateMenuWithUrlDto', () => {
|
|
6
|
+
it('passes with valid minimal object', () => {
|
|
7
|
+
const data = {
|
|
8
|
+
type: 'only-url',
|
|
9
|
+
icon: 'https://example.com/icon.png',
|
|
10
|
+
label: 'Dashboard',
|
|
11
|
+
url: 'https://example.com/page',
|
|
12
|
+
};
|
|
13
|
+
const errors = (0, menu_with_url_validator_1.validateMenuWithUrlDto)(data);
|
|
14
|
+
expect(errors.length).toBe(0);
|
|
15
|
+
});
|
|
16
|
+
it('fails if type is incorrect', () => {
|
|
17
|
+
const data = {
|
|
18
|
+
type: 'invalid-type',
|
|
19
|
+
icon: 'https://example.com/icon.png',
|
|
20
|
+
label: 'Dashboard',
|
|
21
|
+
url: 'https://example.com/page',
|
|
22
|
+
};
|
|
23
|
+
const errors = (0, menu_with_url_validator_1.validateMenuWithUrlDto)(data);
|
|
24
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
25
|
+
expect(errors.some(e => { var _a; return (_a = e.constraints) === null || _a === void 0 ? void 0 : _a.isIn; })).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
it('fails if icon is not a string', () => {
|
|
28
|
+
const data = {
|
|
29
|
+
type: 'only-url',
|
|
30
|
+
icon: 12345, // not a string
|
|
31
|
+
label: 'Dashboard',
|
|
32
|
+
url: 'https://example.com/page',
|
|
33
|
+
};
|
|
34
|
+
const errors = (0, menu_with_url_validator_1.validateMenuWithUrlDto)(data);
|
|
35
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
36
|
+
expect(errors.some(e => { var _a; return (_a = e.constraints) === null || _a === void 0 ? void 0 : _a.isString; })).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
it('fails if label is missing', () => {
|
|
39
|
+
const data = {
|
|
40
|
+
type: 'only-url',
|
|
41
|
+
icon: 'https://example.com/icon.png',
|
|
42
|
+
url: 'https://example.com/page',
|
|
43
|
+
};
|
|
44
|
+
const errors = (0, menu_with_url_validator_1.validateMenuWithUrlDto)(data);
|
|
45
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
46
|
+
expect(errors.some(e => { var _a; return (_a = e.constraints) === null || _a === void 0 ? void 0 : _a.isNotEmpty; })).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
it('fails if url is missing or invalid', () => {
|
|
49
|
+
const invalids = [
|
|
50
|
+
{ type: 'only-url', icon: 12345, label: 'Dashboard' }, // icon not a string
|
|
51
|
+
{ type: 'only-url', icon: 'https://example.com/icon.png', label: 'Dashboard', url: 'invalid-url' },
|
|
52
|
+
];
|
|
53
|
+
for (const data of invalids) {
|
|
54
|
+
const errors = (0, menu_with_url_validator_1.validateMenuWithUrlDto)(data);
|
|
55
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
56
|
+
expect(errors.some(e => { var _a, _b, _c; return ((_a = e.constraints) === null || _a === void 0 ? void 0 : _a.isUrl) || ((_b = e.constraints) === null || _b === void 0 ? void 0 : _b.isString) || ((_c = e.constraints) === null || _c === void 0 ? void 0 : _c.isDefined); })).toBe(true);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
it('fails if submenu is present', () => {
|
|
60
|
+
const data = {
|
|
61
|
+
type: 'only-url',
|
|
62
|
+
icon: 'https://example.com/icon.png',
|
|
63
|
+
label: 'Dashboard',
|
|
64
|
+
url: 'https://example.com/page',
|
|
65
|
+
submenu: [],
|
|
66
|
+
};
|
|
67
|
+
const errors = (0, menu_with_url_validator_1.validateMenuWithUrlDto)(data);
|
|
68
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateMenuWithUrlDto = validateMenuWithUrlDto;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const menu_dto_1 = require("../dtos/menu.dto");
|
|
7
|
+
function validateMenuWithUrlDto(data) {
|
|
8
|
+
const dto = (0, class_transformer_1.plainToInstance)(menu_dto_1.MenuDtoWithUrl, data);
|
|
9
|
+
const errors = (0, class_validator_1.validateSync)(dto);
|
|
10
|
+
return errors;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const multilang_text_validator_1 = require("./multilang-text-validator");
|
|
5
|
+
const language_enum_1 = require("../enums/language.enum");
|
|
6
|
+
describe('MultilangTextDto Validator', () => {
|
|
7
|
+
it('should return no errors for valid DTO', () => {
|
|
8
|
+
const validDto = {
|
|
9
|
+
language: language_enum_1.LanguageEnum.EN,
|
|
10
|
+
text: 'Hello World',
|
|
11
|
+
};
|
|
12
|
+
const errors = (0, multilang_text_validator_1.validateMultilangTextDto)(validDto);
|
|
13
|
+
expect(errors).toHaveLength(0);
|
|
14
|
+
});
|
|
15
|
+
it('should return error for invalid language', () => {
|
|
16
|
+
const invalidDto = {
|
|
17
|
+
language: 'not-a-language',
|
|
18
|
+
text: 'Hello World',
|
|
19
|
+
};
|
|
20
|
+
const errors = (0, multilang_text_validator_1.validateMultilangTextDto)(invalidDto);
|
|
21
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
22
|
+
expect(errors.some((e) => e.property === 'language')).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
it('should return error for missing text', () => {
|
|
25
|
+
const invalidDto = {
|
|
26
|
+
language: language_enum_1.LanguageEnum.EN,
|
|
27
|
+
// Missing text
|
|
28
|
+
};
|
|
29
|
+
const errors = (0, multilang_text_validator_1.validateMultilangTextDto)(invalidDto);
|
|
30
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
31
|
+
expect(errors.some((e) => e.property === 'text')).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const notification_info_validator_1 = require("./notification-info.validator");
|
|
5
|
+
const notification_message_type_enum_1 = require("../enums/notification/notification-message-type.enum");
|
|
6
|
+
const actions_enum_1 = require("../enums/actions.enum");
|
|
7
|
+
const language_enum_1 = require("../enums/language.enum");
|
|
8
|
+
describe('NotificationInfoDto Validator', () => {
|
|
9
|
+
const validUnit = { id: "ram", unitDescription: "MB", intervalDescription: "month" };
|
|
10
|
+
const testCases = [
|
|
11
|
+
{
|
|
12
|
+
description: 'should return no errors for valid DTO',
|
|
13
|
+
dto: {
|
|
14
|
+
type: notification_message_type_enum_1.NotificationMessageTypeEnum.EMAIL,
|
|
15
|
+
title: 'Valid Title',
|
|
16
|
+
supportedActions: [actions_enum_1.ActionsEnum.CREATE],
|
|
17
|
+
supportedLanguages: [language_enum_1.LanguageEnum.EN],
|
|
18
|
+
payPerUseUnits: [validUnit]
|
|
19
|
+
},
|
|
20
|
+
expectedErrorsLength: 0
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
description: 'should return error for missing type',
|
|
24
|
+
dto: {
|
|
25
|
+
title: 'Valid Title',
|
|
26
|
+
supportedActions: [actions_enum_1.ActionsEnum.CREATE],
|
|
27
|
+
supportedLanguages: [language_enum_1.LanguageEnum.EN],
|
|
28
|
+
payPerUseUnits: [validUnit]
|
|
29
|
+
},
|
|
30
|
+
expectedErrorsLength: 1
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
description: 'should return error for invalid payPerUseUnits',
|
|
34
|
+
dto: {
|
|
35
|
+
type: notification_message_type_enum_1.NotificationMessageTypeEnum.EMAIL,
|
|
36
|
+
title: 'Valid Title',
|
|
37
|
+
supportedActions: [actions_enum_1.ActionsEnum.CREATE],
|
|
38
|
+
supportedLanguages: [language_enum_1.LanguageEnum.EN],
|
|
39
|
+
payPerUseUnits: [{ id: "", unitDescription: "", intervalDescription: "" }] // Invalid unit
|
|
40
|
+
},
|
|
41
|
+
expectedErrorsLength: 1
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
testCases.forEach(({ description, dto, expectedErrorsLength }) => {
|
|
45
|
+
it(description, async () => {
|
|
46
|
+
const errors = await (0, notification_info_validator_1.validateNotificationInfoDto)(dto);
|
|
47
|
+
expect(errors).toHaveLength(expectedErrorsLength);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
const validationErrorTestCases = [
|
|
51
|
+
{
|
|
52
|
+
description: 'should return ValidationError for missing title',
|
|
53
|
+
dto: {
|
|
54
|
+
type: notification_message_type_enum_1.NotificationMessageTypeEnum.EMAIL,
|
|
55
|
+
supportedActions: [actions_enum_1.ActionsEnum.CREATE],
|
|
56
|
+
supportedLanguages: [language_enum_1.LanguageEnum.EN],
|
|
57
|
+
payPerUseUnits: [validUnit]
|
|
58
|
+
},
|
|
59
|
+
expectedErrors: ['title']
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
description: 'should return ValidationError for invalid payPerUseUnits',
|
|
63
|
+
dto: {
|
|
64
|
+
type: notification_message_type_enum_1.NotificationMessageTypeEnum.EMAIL,
|
|
65
|
+
title: 'Valid Title',
|
|
66
|
+
supportedActions: [actions_enum_1.ActionsEnum.CREATE],
|
|
67
|
+
supportedLanguages: [language_enum_1.LanguageEnum.EN],
|
|
68
|
+
payPerUseUnits: [{ id: "", unitDescription: "", intervalDescription: "" }]
|
|
69
|
+
},
|
|
70
|
+
expectedErrors: ['payPerUseUnits']
|
|
71
|
+
}
|
|
72
|
+
];
|
|
73
|
+
validationErrorTestCases.forEach(({ description, dto, expectedErrors }) => {
|
|
74
|
+
it(description, async () => {
|
|
75
|
+
const errors = await (0, notification_info_validator_1.validateNotificationInfoDto)(dto);
|
|
76
|
+
const errorProperties = errors.map(error => error.property);
|
|
77
|
+
expectedErrors.forEach(expectedError => {
|
|
78
|
+
expect(errorProperties).toContain(expectedError);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ValidationError } from 'class-validator';
|
|
2
|
+
/**
|
|
3
|
+
* Validates a NotificationInfoDto object.
|
|
4
|
+
* @param dto The NotificationInfoDto object to validate.
|
|
5
|
+
* @returns An array of validation errors, if any.
|
|
6
|
+
*/
|
|
7
|
+
export declare function validateNotificationInfoDto(dto: object): ValidationError[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateNotificationInfoDto = validateNotificationInfoDto;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const notification_info_dto_1 = require("../dtos/notification/notification-info.dto");
|
|
7
|
+
/**
|
|
8
|
+
* Validates a NotificationInfoDto object.
|
|
9
|
+
* @param dto The NotificationInfoDto object to validate.
|
|
10
|
+
* @returns An array of validation errors, if any.
|
|
11
|
+
*/
|
|
12
|
+
function validateNotificationInfoDto(dto) {
|
|
13
|
+
const notificationInfoDto = (0, class_transformer_1.plainToInstance)(notification_info_dto_1.NotificationInfoDto, dto);
|
|
14
|
+
const errors = (0, class_validator_1.validateSync)(notificationInfoDto);
|
|
15
|
+
return errors;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const notification_request_validator_1 = require("./notification-request-validator");
|
|
5
|
+
describe('NotificationRequestDto Validator', () => {
|
|
6
|
+
// Valid test case
|
|
7
|
+
it('should return no errors for valid DTO', () => {
|
|
8
|
+
const validDto = {
|
|
9
|
+
notificationId: 'test-notification-123',
|
|
10
|
+
sender: {
|
|
11
|
+
// Using EmailSenderDto as an example
|
|
12
|
+
email: 'test@example.com',
|
|
13
|
+
name: 'Test Sender',
|
|
14
|
+
},
|
|
15
|
+
receiver: {
|
|
16
|
+
// Using EmailReceiverDto as an example
|
|
17
|
+
email: 'recipient@example.com',
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
const errors = (0, notification_request_validator_1.validateNotificationRequestDto)(validDto);
|
|
21
|
+
expect(errors).toHaveLength(0);
|
|
22
|
+
});
|
|
23
|
+
// Invalid test cases
|
|
24
|
+
describe('notificationId validation', () => {
|
|
25
|
+
it('should return error when notificationId is missing', () => {
|
|
26
|
+
const invalidDto = {
|
|
27
|
+
sender: { email: 'test@example.com', name: 'Test Sender' },
|
|
28
|
+
receiver: { email: 'recipient@example.com' },
|
|
29
|
+
};
|
|
30
|
+
const errors = (0, notification_request_validator_1.validateNotificationRequestDto)(invalidDto);
|
|
31
|
+
expect(errors).toHaveLength(1);
|
|
32
|
+
expect(errors[0].property).toBe('notificationId');
|
|
33
|
+
expect(errors[0].constraints).toHaveProperty('isNotEmpty');
|
|
34
|
+
});
|
|
35
|
+
it('should return error when notificationId is not a string', () => {
|
|
36
|
+
const invalidDto = {
|
|
37
|
+
notificationId: 123, // Number instead of string
|
|
38
|
+
sender: { email: 'test@example.com', name: 'Test Sender' },
|
|
39
|
+
receiver: { email: 'recipient@example.com' },
|
|
40
|
+
};
|
|
41
|
+
const errors = (0, notification_request_validator_1.validateNotificationRequestDto)(invalidDto);
|
|
42
|
+
expect(errors).toHaveLength(1);
|
|
43
|
+
expect(errors[0].property).toBe('notificationId');
|
|
44
|
+
expect(errors[0].constraints).toHaveProperty('isString');
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe('sender validation', () => {
|
|
48
|
+
it('should return error when sender is missing', () => {
|
|
49
|
+
const invalidDto = {
|
|
50
|
+
notificationId: 'test-notification-123',
|
|
51
|
+
receiver: { email: 'recipient@example.com' },
|
|
52
|
+
};
|
|
53
|
+
const errors = (0, notification_request_validator_1.validateNotificationRequestDto)(invalidDto);
|
|
54
|
+
expect(errors).toHaveLength(1);
|
|
55
|
+
expect(errors[0].property).toBe('sender');
|
|
56
|
+
expect(errors[0].constraints).toHaveProperty('isNotEmpty');
|
|
57
|
+
});
|
|
58
|
+
it('should return error when sender is not an object', () => {
|
|
59
|
+
const invalidDto = {
|
|
60
|
+
notificationId: 'test-notification-123',
|
|
61
|
+
sender: 'not-an-object',
|
|
62
|
+
receiver: { email: 'recipient@example.com' },
|
|
63
|
+
};
|
|
64
|
+
const errors = (0, notification_request_validator_1.validateNotificationRequestDto)(invalidDto);
|
|
65
|
+
expect(errors).toHaveLength(1);
|
|
66
|
+
expect(errors[0].property).toBe('sender');
|
|
67
|
+
expect(errors[0].constraints).toHaveProperty('isObject');
|
|
68
|
+
});
|
|
69
|
+
it('should return error when sender is null', () => {
|
|
70
|
+
const invalidDto = {
|
|
71
|
+
notificationId: 'test-notification-123',
|
|
72
|
+
sender: null,
|
|
73
|
+
receiver: { email: 'recipient@example.com' },
|
|
74
|
+
};
|
|
75
|
+
const errors = (0, notification_request_validator_1.validateNotificationRequestDto)(invalidDto);
|
|
76
|
+
expect(errors).toHaveLength(1);
|
|
77
|
+
expect(errors[0].property).toBe('sender');
|
|
78
|
+
expect(errors[0].constraints).toHaveProperty('isObject');
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe('receiver validation', () => {
|
|
82
|
+
it('should return error when receiver is missing', () => {
|
|
83
|
+
const invalidDto = {
|
|
84
|
+
notificationId: 'test-notification-123',
|
|
85
|
+
sender: { email: 'test@example.com', name: 'Test Sender' },
|
|
86
|
+
};
|
|
87
|
+
const errors = (0, notification_request_validator_1.validateNotificationRequestDto)(invalidDto);
|
|
88
|
+
expect(errors).toHaveLength(1);
|
|
89
|
+
expect(errors[0].property).toBe('receiver');
|
|
90
|
+
expect(errors[0].constraints).toHaveProperty('isNotEmpty');
|
|
91
|
+
});
|
|
92
|
+
it('should return error when receiver is not an object', () => {
|
|
93
|
+
const invalidDto = {
|
|
94
|
+
notificationId: 'test-notification-123',
|
|
95
|
+
sender: { email: 'test@example.com', name: 'Test Sender' },
|
|
96
|
+
receiver: 'invalid-receiver',
|
|
97
|
+
};
|
|
98
|
+
const errors = (0, notification_request_validator_1.validateNotificationRequestDto)(invalidDto);
|
|
99
|
+
expect(errors).toHaveLength(1);
|
|
100
|
+
expect(errors[0].property).toBe('receiver');
|
|
101
|
+
expect(errors[0].constraints).toHaveProperty('isObject');
|
|
102
|
+
});
|
|
103
|
+
it('should return error when receiver is null', () => {
|
|
104
|
+
const invalidDto = {
|
|
105
|
+
notificationId: 'test-notification-123',
|
|
106
|
+
sender: { email: 'test@example.com', name: 'Test Sender' },
|
|
107
|
+
receiver: null,
|
|
108
|
+
};
|
|
109
|
+
const errors = (0, notification_request_validator_1.validateNotificationRequestDto)(invalidDto);
|
|
110
|
+
expect(errors).toHaveLength(1);
|
|
111
|
+
expect(errors[0].property).toBe('receiver');
|
|
112
|
+
expect(errors[0].constraints).toHaveProperty('isObject');
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|