@hosterai/types 0.0.16 → 0.0.18
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 +14 -9
- 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/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 +4 -1
- package/dist/dtos/admin-panel.dto.d.ts +38 -0
- package/dist/dtos/admin-panel.dto.js +150 -0
- package/dist/dtos/client-panel.dto.d.ts +24 -0
- package/dist/dtos/client-panel.dto.js +75 -0
- package/dist/dtos/company-data.dto.js +1 -1
- package/dist/dtos/field.dto.js +32 -0
- package/dist/dtos/info.dto.d.ts +6 -81
- package/dist/dtos/info.dto.js +79 -0
- package/dist/dtos/menu.dto.d.ts +3 -4
- package/dist/dtos/menu.dto.js +75 -0
- package/dist/dtos/multilang-text.dto.js +1 -1
- package/dist/dtos/notification/notification-info.dto.js +25 -0
- package/dist/dtos/product/product-info.dto.js +46 -0
- package/dist/dtos/settings.dto.d.ts +14 -0
- package/dist/dtos/settings.dto.js +59 -0
- package/dist/dtos/tab.dto.js +20 -0
- package/dist/dtos/unit.dto.js +28 -0
- package/dist/enums/actions.enum.d.ts +2 -1
- package/dist/enums/actions.enum.js +12 -12
- package/dist/enums/events.enum.d.ts +2 -0
- package/dist/enums/events.enum.js +2 -0
- package/dist/enums/roles.enum.d.ts +2 -2
- package/dist/enums/roles.enum.js +2 -2
- package/dist/index.d.ts +22 -7
- package/dist/index.js +22 -7
- 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 +76 -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-info-validator.spec.d.ts +1 -0
- package/dist/validators/product-info-validator.spec.js +172 -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-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 +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateAdminPanelDto = validateAdminPanelDto;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const admin_panel_dto_1 = require("../dtos/admin-panel.dto");
|
|
7
|
+
async function validateAdminPanelDto(data) {
|
|
8
|
+
const dto = (0, class_transformer_1.plainToInstance)(admin_panel_dto_1.AdminPanelDto, data);
|
|
9
|
+
const errors = await (0, class_validator_1.validate)(dto, {
|
|
10
|
+
whitelist: true, // strips unknown props
|
|
11
|
+
forbidNonWhitelisted: true, // throws error if unknown props present
|
|
12
|
+
});
|
|
13
|
+
return errors;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const client_data_validator_1 = require("./client-data-validator");
|
|
5
|
+
const country_enum_1 = require("../enums/country.enum");
|
|
6
|
+
describe('validateClientDataDto', () => {
|
|
7
|
+
it('should return no errors for a valid client data object', async () => {
|
|
8
|
+
const validClientData = {
|
|
9
|
+
email: 'test@example.com',
|
|
10
|
+
firstName: 'John',
|
|
11
|
+
lastName: 'Doe',
|
|
12
|
+
telephone: '+14155552671',
|
|
13
|
+
address1: '123 Main St',
|
|
14
|
+
postcode: '12345',
|
|
15
|
+
city: 'Anytown',
|
|
16
|
+
country: country_enum_1.CountryEnum.UNITED_STATES,
|
|
17
|
+
};
|
|
18
|
+
const errors = await (0, client_data_validator_1.validateClientDataDto)(validClientData);
|
|
19
|
+
expect(errors.length).toBe(0);
|
|
20
|
+
});
|
|
21
|
+
it('should return errors for an invalid client data object', async () => {
|
|
22
|
+
const invalidClientData = {
|
|
23
|
+
email: 'not-an-email',
|
|
24
|
+
firstName: '', // empty
|
|
25
|
+
lastName: 'Doe',
|
|
26
|
+
telephone: '123', // invalid
|
|
27
|
+
address1: '123 Main St',
|
|
28
|
+
postcode: '12345',
|
|
29
|
+
city: 'Anytown',
|
|
30
|
+
country: 'invalid-country',
|
|
31
|
+
};
|
|
32
|
+
const errors = await (0, client_data_validator_1.validateClientDataDto)(invalidClientData);
|
|
33
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const client_panel_validator_1 = require("./client-panel.validator"); // your validation function
|
|
5
|
+
const validAction = { icon: 'add', openMethod: 'ajax_call', url: 'https://example.com/action' };
|
|
6
|
+
const minimalValidMenuDtoWithUrl = {
|
|
7
|
+
type: 'only-url',
|
|
8
|
+
icon: 'https://example.com/icon.png',
|
|
9
|
+
label: 'Client Menu',
|
|
10
|
+
url: 'https://example.com/menu',
|
|
11
|
+
};
|
|
12
|
+
const minimalValidMenuDtoWithSubmenu = {
|
|
13
|
+
type: 'with-submenu',
|
|
14
|
+
icon: 'https://example.com/icon.png',
|
|
15
|
+
label: 'Client Menu',
|
|
16
|
+
submenu: [
|
|
17
|
+
{ url: 'https://example.com/sub1', label: 'Submenu 1' },
|
|
18
|
+
{ url: 'https://example.com/sub2', label: 'Submenu 2' },
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
describe('ClientPanelDto full validation', () => {
|
|
22
|
+
test.each([
|
|
23
|
+
// Empty object is invalid (all optional)
|
|
24
|
+
['invalid minimal empty object', {}, false],
|
|
25
|
+
// Tabs tests
|
|
26
|
+
['invalid empty tabs object', { tabs: {} }, false],
|
|
27
|
+
['invalid tabs with empty item array', { tabs: { item: [] } }, false],
|
|
28
|
+
['valid tabs with one item', { tabs: { item: [{ label: 'Tab 1', url: 'https://example.com/tab1' }] } }, true],
|
|
29
|
+
// MoreActions tests
|
|
30
|
+
['invalid empty moreActions object', { moreActions: {} }, false],
|
|
31
|
+
['invalid moreActions with empty item array', { moreActions: { item: [] } }, false],
|
|
32
|
+
['valid moreActions with one item', { moreActions: { item: [validAction] } }, true],
|
|
33
|
+
// Menu tests
|
|
34
|
+
['valid menu with URL type', { menu: minimalValidMenuDtoWithUrl }, true],
|
|
35
|
+
['valid menu with submenu type', { menu: minimalValidMenuDtoWithSubmenu }, true],
|
|
36
|
+
['invalid menu missing required fields', { menu: { type: 'only-url' } }, false],
|
|
37
|
+
['invalid menu unknown type', { menu: { type: 'unknown', icon: 'https://icon.png', label: 'Label', url: 'https://example.com' } }, false],
|
|
38
|
+
['invalid menu with extra property', { menu: { ...minimalValidMenuDtoWithUrl, extra: 'not allowed' } }, false],
|
|
39
|
+
['invalid menu with submenu on URL menu', { menu: { ...minimalValidMenuDtoWithUrl, submenu: [{ url: 'https://example.com', label: 'Sub' }] } }, false],
|
|
40
|
+
// Invalid extra property on root DTO
|
|
41
|
+
['invalid extra property on root', { extra: 'not allowed' }, false],
|
|
42
|
+
])('%s', async (_desc, input, expectedValid) => {
|
|
43
|
+
const errors = await (0, client_panel_validator_1.validateClientPanelDto)(input);
|
|
44
|
+
if (expectedValid) {
|
|
45
|
+
expect(errors.length).toBe(0);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateClientPanelDto = validateClientPanelDto;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const client_panel_dto_1 = require("../dtos/client-panel.dto");
|
|
7
|
+
async function validateClientPanelDto(data) {
|
|
8
|
+
const dto = (0, class_transformer_1.plainToInstance)(client_panel_dto_1.ClientPanelDto, data);
|
|
9
|
+
const errors = await (0, class_validator_1.validate)(dto, {
|
|
10
|
+
whitelist: true,
|
|
11
|
+
forbidNonWhitelisted: true,
|
|
12
|
+
});
|
|
13
|
+
return errors;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const company_data_validator_1 = require("./company-data-validator");
|
|
5
|
+
const country_enum_1 = require("../enums/country.enum");
|
|
6
|
+
const language_enum_1 = require("../enums/language.enum");
|
|
7
|
+
describe('CompanyDataDto Validator', () => {
|
|
8
|
+
it('should return no errors for valid DTO', () => {
|
|
9
|
+
const validDto = {
|
|
10
|
+
id: '123',
|
|
11
|
+
name: 'Test Company',
|
|
12
|
+
emails: ['test@example.com'],
|
|
13
|
+
invoiceEmail: 'invoice@example.com',
|
|
14
|
+
privacyPolicyUrl: 'https://example.com/privacy',
|
|
15
|
+
defaultLanguage: language_enum_1.LanguageEnum.EN,
|
|
16
|
+
languages: [language_enum_1.LanguageEnum.EN, language_enum_1.LanguageEnum.FR],
|
|
17
|
+
telephone: '+12133734253',
|
|
18
|
+
address1: '123 Main St',
|
|
19
|
+
postcode: '12345',
|
|
20
|
+
city: 'Test City',
|
|
21
|
+
country: country_enum_1.CountryEnum.UNITED_STATES,
|
|
22
|
+
};
|
|
23
|
+
const errors = (0, company_data_validator_1.validateCompanyDataDto)(validDto);
|
|
24
|
+
expect(errors).toHaveLength(0);
|
|
25
|
+
});
|
|
26
|
+
it('should return error when required fields are missing', () => {
|
|
27
|
+
const invalidDto = {
|
|
28
|
+
// Missing required fields
|
|
29
|
+
};
|
|
30
|
+
const errors = (0, company_data_validator_1.validateCompanyDataDto)(invalidDto);
|
|
31
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
32
|
+
expect(errors.some((e) => e.property === 'id')).toBe(true);
|
|
33
|
+
expect(errors.some((e) => e.property === 'name')).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
it('should return error for invalid email format', () => {
|
|
36
|
+
const invalidDto = {
|
|
37
|
+
id: '123',
|
|
38
|
+
name: 'Test Company',
|
|
39
|
+
emails: ['not-an-email'],
|
|
40
|
+
invoiceEmail: 'invoice@example.com',
|
|
41
|
+
privacyPolicyUrl: 'http://example.com/privacy',
|
|
42
|
+
defaultLanguage: language_enum_1.LanguageEnum.EN,
|
|
43
|
+
languages: [language_enum_1.LanguageEnum.EN, language_enum_1.LanguageEnum.FR],
|
|
44
|
+
telephone: '+12133734253',
|
|
45
|
+
address1: '123 Main St',
|
|
46
|
+
postcode: '12345',
|
|
47
|
+
city: 'Test City',
|
|
48
|
+
country: country_enum_1.CountryEnum.UNITED_STATES,
|
|
49
|
+
};
|
|
50
|
+
const errors = (0, company_data_validator_1.validateCompanyDataDto)(invalidDto);
|
|
51
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
52
|
+
expect(errors.some((e) => e.property === 'emails')).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
it('should return error for invalid URL format', () => {
|
|
55
|
+
const invalidDto = {
|
|
56
|
+
id: '123',
|
|
57
|
+
name: 'Test Company',
|
|
58
|
+
emails: ['test@example.com'],
|
|
59
|
+
invoiceEmail: 'invoice@example.com',
|
|
60
|
+
privacyPolicyUrl: 'not-a-url',
|
|
61
|
+
defaultLanguage: language_enum_1.LanguageEnum.EN,
|
|
62
|
+
languages: [language_enum_1.LanguageEnum.EN, language_enum_1.LanguageEnum.FR],
|
|
63
|
+
telephone: '+12133734253',
|
|
64
|
+
address1: '123 Main St',
|
|
65
|
+
postcode: '12345',
|
|
66
|
+
city: 'Test City',
|
|
67
|
+
country: country_enum_1.CountryEnum.UNITED_STATES,
|
|
68
|
+
};
|
|
69
|
+
const errors = (0, company_data_validator_1.validateCompanyDataDto)(invalidDto);
|
|
70
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
71
|
+
expect(errors.some((e) => e.property === 'privacyPolicyUrl')).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -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,76 @@
|
|
|
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
|
+
});
|
|
@@ -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';
|