@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.
Files changed (154) hide show
  1. package/README.md +14 -9
  2. package/dist/decorators/at-least-one-non-empty-validator.spec.d.ts +1 -0
  3. package/dist/decorators/at-least-one-non-empty-validator.spec.js +79 -0
  4. package/dist/decorators/at-least-one-non-empty.validator.d.ts +2 -0
  5. package/dist/decorators/at-least-one-non-empty.validator.js +43 -0
  6. package/dist/decorators/is-of-allowed-types-validator.spec.d.ts +1 -0
  7. package/dist/decorators/is-of-allowed-types-validator.spec.js +188 -0
  8. package/dist/decorators/is-of-allowed-types.validator.d.ts +16 -0
  9. package/dist/decorators/is-of-allowed-types.validator.js +105 -0
  10. package/dist/decorators/is-one-of-validator.spec.d.ts +1 -0
  11. package/dist/decorators/is-one-of-validator.spec.js +51 -0
  12. package/dist/decorators/is-one-of.validator.d.ts +2 -0
  13. package/dist/decorators/is-one-of.validator.js +19 -0
  14. package/dist/decorators/is-plain-object-validator.spec.d.ts +1 -0
  15. package/dist/decorators/is-plain-object-validator.spec.js +46 -0
  16. package/dist/decorators/is-plain-object.validator.d.ts +2 -0
  17. package/dist/decorators/is-plain-object.validator.js +30 -0
  18. package/dist/decorators/is-property-forbidden-validator.spec.d.ts +1 -0
  19. package/dist/decorators/is-property-forbidden-validator.spec.js +62 -0
  20. package/dist/decorators/is-property-forbidden.validator.d.ts +2 -0
  21. package/dist/decorators/is-property-forbidden.validator.js +22 -0
  22. package/dist/decorators/is-regex-validator.spec.d.ts +1 -0
  23. package/dist/decorators/is-regex-validator.spec.js +46 -0
  24. package/dist/decorators/is-regex.validator.d.ts +2 -0
  25. package/dist/decorators/is-regex.validator.js +32 -0
  26. package/dist/decorators/unique-field-in-array-validator.spec.d.ts +1 -0
  27. package/dist/decorators/unique-field-in-array-validator.spec.js +39 -0
  28. package/dist/decorators/unique-field-in-array.validator.d.ts +6 -0
  29. package/dist/decorators/unique-field-in-array.validator.js +47 -0
  30. package/dist/dtos/action.dto.js +4 -1
  31. package/dist/dtos/admin-panel.dto.d.ts +38 -0
  32. package/dist/dtos/admin-panel.dto.js +150 -0
  33. package/dist/dtos/client-panel.dto.d.ts +24 -0
  34. package/dist/dtos/client-panel.dto.js +75 -0
  35. package/dist/dtos/company-data.dto.js +1 -1
  36. package/dist/dtos/field.dto.js +32 -0
  37. package/dist/dtos/info.dto.d.ts +6 -81
  38. package/dist/dtos/info.dto.js +79 -0
  39. package/dist/dtos/menu.dto.d.ts +3 -4
  40. package/dist/dtos/menu.dto.js +75 -0
  41. package/dist/dtos/multilang-text.dto.js +1 -1
  42. package/dist/dtos/notification/notification-info.dto.js +25 -0
  43. package/dist/dtos/product/product-info.dto.js +46 -0
  44. package/dist/dtos/settings.dto.d.ts +14 -0
  45. package/dist/dtos/settings.dto.js +59 -0
  46. package/dist/dtos/tab.dto.js +20 -0
  47. package/dist/dtos/unit.dto.js +28 -0
  48. package/dist/enums/actions.enum.d.ts +2 -1
  49. package/dist/enums/actions.enum.js +12 -12
  50. package/dist/enums/events.enum.d.ts +2 -0
  51. package/dist/enums/events.enum.js +2 -0
  52. package/dist/enums/roles.enum.d.ts +2 -2
  53. package/dist/enums/roles.enum.js +2 -2
  54. package/dist/index.d.ts +22 -7
  55. package/dist/index.js +22 -7
  56. package/dist/transformers/menu.transformer.d.ts +2 -0
  57. package/dist/transformers/menu.transformer.js +16 -0
  58. package/dist/transformers/settings.transformer.d.ts +1 -0
  59. package/dist/transformers/settings.transformer.js +15 -0
  60. package/dist/validators/action-validator.spec.d.ts +1 -0
  61. package/dist/validators/action-validator.spec.js +67 -0
  62. package/dist/validators/admin-panel-more-actions-validator.spec.d.ts +1 -0
  63. package/dist/validators/admin-panel-more-actions-validator.spec.js +129 -0
  64. package/dist/validators/admin-panel-more-actions.validator.d.ts +2 -0
  65. package/dist/validators/admin-panel-more-actions.validator.js +11 -0
  66. package/dist/validators/admin-panel-tabs-validator.spec.d.ts +1 -0
  67. package/dist/validators/admin-panel-tabs-validator.spec.js +39 -0
  68. package/dist/validators/admin-panel-tabs.validator.d.ts +2 -0
  69. package/dist/validators/admin-panel-tabs.validator.js +11 -0
  70. package/dist/validators/admin-panel-validator.spec.d.ts +1 -0
  71. package/dist/validators/admin-panel-validator.spec.js +112 -0
  72. package/dist/validators/admin-panel.validator.d.ts +2 -0
  73. package/dist/validators/admin-panel.validator.js +14 -0
  74. package/dist/validators/client-data-validator.spec.d.ts +1 -0
  75. package/dist/validators/client-data-validator.spec.js +35 -0
  76. package/dist/validators/client-panel-validator.spec.d.ts +1 -0
  77. package/dist/validators/client-panel-validator.spec.js +51 -0
  78. package/dist/validators/client-panel.validator.d.ts +2 -0
  79. package/dist/validators/client-panel.validator.js +14 -0
  80. package/dist/validators/company-data-validator.spec.d.ts +1 -0
  81. package/dist/validators/company-data-validator.spec.js +73 -0
  82. package/dist/validators/field-option-validator.spec.d.ts +1 -0
  83. package/dist/validators/field-option-validator.spec.js +28 -0
  84. package/dist/validators/field-option.validator.d.ts +2 -0
  85. package/dist/validators/field-option.validator.js +11 -0
  86. package/dist/validators/field-validator.spec.d.ts +1 -0
  87. package/dist/validators/field-validator.spec.js +76 -0
  88. package/dist/validators/jwt-validator.spec.d.ts +2 -0
  89. package/dist/validators/jwt-validator.spec.js +43 -0
  90. package/dist/validators/menu-with-submenu-validator.spec.d.ts +1 -0
  91. package/dist/validators/menu-with-submenu-validator.spec.js +52 -0
  92. package/dist/validators/menu-with-submenu.validator.d.ts +2 -0
  93. package/dist/validators/menu-with-submenu.validator.js +11 -0
  94. package/dist/validators/menu-with-url-validator.spec.d.ts +1 -0
  95. package/dist/validators/menu-with-url-validator.spec.js +70 -0
  96. package/dist/validators/menu-with-url.validator.d.ts +2 -0
  97. package/dist/validators/menu-with-url.validator.js +11 -0
  98. package/dist/validators/multilang-text-validator.spec.d.ts +1 -0
  99. package/dist/validators/multilang-text-validator.spec.js +33 -0
  100. package/dist/validators/notification-info-validator.spec.d.ts +1 -0
  101. package/dist/validators/notification-info-validator.spec.js +82 -0
  102. package/dist/validators/notification-info.validator.d.ts +7 -0
  103. package/dist/validators/notification-info.validator.js +16 -0
  104. package/dist/validators/notification-request-validator.spec.d.ts +1 -0
  105. package/dist/validators/notification-request-validator.spec.js +115 -0
  106. package/dist/validators/product-create-request-validator.spec.d.ts +2 -0
  107. package/dist/validators/product-create-request-validator.spec.js +44 -0
  108. package/dist/validators/product-delete-request-validator.spec.d.ts +1 -0
  109. package/dist/validators/product-delete-request-validator.spec.js +40 -0
  110. package/dist/validators/product-downgradable-request-validator.spec.d.ts +1 -0
  111. package/dist/validators/product-downgradable-request-validator.spec.js +40 -0
  112. package/dist/validators/product-downgrade-request-validator.spec.d.ts +1 -0
  113. package/dist/validators/product-downgrade-request-validator.spec.js +46 -0
  114. package/dist/validators/product-info-validator.spec.d.ts +1 -0
  115. package/dist/validators/product-info-validator.spec.js +172 -0
  116. package/dist/validators/product-info.validator.d.ts +2 -0
  117. package/dist/validators/product-info.validator.js +11 -0
  118. package/dist/validators/product-renew-request-validator.spec.d.ts +1 -0
  119. package/dist/validators/product-renew-request-validator.spec.js +40 -0
  120. package/dist/validators/product-suspend-request-validator.spec.d.ts +1 -0
  121. package/dist/validators/product-suspend-request-validator.spec.js +40 -0
  122. package/dist/validators/product-unsuspend-request-validator.spec.d.ts +1 -0
  123. package/dist/validators/product-unsuspend-request-validator.spec.js +40 -0
  124. package/dist/validators/product-upgradable-request-validator.spec.d.ts +1 -0
  125. package/dist/validators/product-upgradable-request-validator.spec.js +40 -0
  126. package/dist/validators/product-upgrade-request-validator.spec.d.ts +1 -0
  127. package/dist/validators/product-upgrade-request-validator.spec.js +46 -0
  128. package/dist/validators/product-validate-attributes-request-validator.spec.d.ts +1 -0
  129. package/dist/validators/product-validate-attributes-request-validator.spec.js +27 -0
  130. package/dist/validators/receiver-email-validator.spec.d.ts +1 -0
  131. package/dist/validators/receiver-email-validator.spec.js +32 -0
  132. package/dist/validators/receiver-push-validator.spec.d.ts +1 -0
  133. package/dist/validators/receiver-push-validator.spec.js +31 -0
  134. package/dist/validators/receiver-sms-validator.spec.d.ts +1 -0
  135. package/dist/validators/receiver-sms-validator.spec.js +29 -0
  136. package/dist/validators/sender-email-validator.spec.d.ts +2 -0
  137. package/dist/validators/sender-email-validator.spec.js +62 -0
  138. package/dist/validators/sender-push-validator.spec.d.ts +1 -0
  139. package/dist/validators/sender-push-validator.spec.js +38 -0
  140. package/dist/validators/sender-sms-validator.spec.d.ts +1 -0
  141. package/dist/validators/sender-sms-validator.spec.js +22 -0
  142. package/dist/validators/settings-with-tabs-validator.spec.d.ts +1 -0
  143. package/dist/validators/settings-with-tabs-validator.spec.js +29 -0
  144. package/dist/validators/settings-with-tabs.validator.d.ts +2 -0
  145. package/dist/validators/settings-with-tabs.validator.js +11 -0
  146. package/dist/validators/settings-with-url-validator.spec.d.ts +1 -0
  147. package/dist/validators/settings-with-url-validator.spec.js +29 -0
  148. package/dist/validators/settings-with-url.validator.d.ts +2 -0
  149. package/dist/validators/settings-with-url.validator.js +11 -0
  150. package/dist/validators/unit-validator.spec.d.ts +1 -0
  151. package/dist/validators/unit-validator.spec.js +27 -0
  152. package/dist/validators/unit.validator.d.ts +2 -0
  153. package/dist/validators/unit.validator.js +11 -0
  154. package/package.json +1 -1
@@ -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
+ });
@@ -0,0 +1,2 @@
1
+ import 'reflect-metadata';
2
+ import 'reflect-metadata';
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("reflect-metadata");
4
+ require("reflect-metadata");
5
+ const product_create_request_validator_1 = require("./product-create-request-validator");
6
+ const country_enum_1 = require("../enums/country.enum");
7
+ const duration_enum_1 = require("../enums/duration.enum");
8
+ describe('validateProductCreateRequestDto', () => {
9
+ it('should return no errors for a valid request', async () => {
10
+ const validRequest = {
11
+ clientData: {
12
+ email: 'test@example.com',
13
+ firstName: 'John',
14
+ lastName: 'Doe',
15
+ telephone: '+14155552671',
16
+ address1: '123 Main St',
17
+ postcode: '12345',
18
+ city: 'Anytown',
19
+ country: country_enum_1.CountryEnum.UNITED_STATES,
20
+ },
21
+ itemData: {
22
+ productAttributes: { key: 'value' },
23
+ itemAttributes: { key: 'value' },
24
+ duration: duration_enum_1.DurationEnum.ONE_MONTH,
25
+ },
26
+ };
27
+ const errors = await (0, product_create_request_validator_1.validateProductCreateRequestDto)(validRequest);
28
+ expect(errors.length).toBe(0);
29
+ });
30
+ it('should return errors for an invalid request', async () => {
31
+ const invalidRequest = {
32
+ clientData: {
33
+ email: 'not-an-email',
34
+ },
35
+ itemData: {
36
+ productAttributes: {},
37
+ itemAttributes: {},
38
+ duration: 'invalid-duration',
39
+ },
40
+ };
41
+ const errors = await (0, product_create_request_validator_1.validateProductCreateRequestDto)(invalidRequest);
42
+ expect(errors.length).toBeGreaterThan(0);
43
+ });
44
+ });
@@ -0,0 +1 @@
1
+ import 'reflect-metadata';
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("reflect-metadata");
4
+ const product_delete_request_validator_1 = require("./product-delete-request-validator");
5
+ const country_enum_1 = require("../enums/country.enum");
6
+ const duration_enum_1 = require("../enums/duration.enum");
7
+ describe('validateProductDeleteRequestDto', () => {
8
+ it('should return no errors for a valid request', async () => {
9
+ const validRequest = {
10
+ clientData: {
11
+ email: 'test@example.com',
12
+ firstName: 'John',
13
+ lastName: 'Doe',
14
+ telephone: '+14155552671',
15
+ address1: '123 Main St',
16
+ postcode: '12345',
17
+ city: 'Anytown',
18
+ country: country_enum_1.CountryEnum.UNITED_STATES,
19
+ },
20
+ itemData: {
21
+ itemId: 'item-123',
22
+ productAttributes: { key: 'value' },
23
+ itemAttributes: { key: 'value' },
24
+ duration: duration_enum_1.DurationEnum.ONE_MONTH,
25
+ },
26
+ };
27
+ const errors = await (0, product_delete_request_validator_1.validateProductDeleteRequestDto)(validRequest);
28
+ expect(errors.length).toBe(0);
29
+ });
30
+ it('should return errors for an invalid request', async () => {
31
+ const invalidRequest = {
32
+ clientData: {
33
+ email: 'not-an-email',
34
+ },
35
+ itemData: {},
36
+ };
37
+ const errors = await (0, product_delete_request_validator_1.validateProductDeleteRequestDto)(invalidRequest);
38
+ expect(errors.length).toBeGreaterThan(0);
39
+ });
40
+ });
@@ -0,0 +1 @@
1
+ import 'reflect-metadata';
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("reflect-metadata");
4
+ const product_downgradable_request_validator_1 = require("./product-downgradable-request-validator");
5
+ const country_enum_1 = require("../enums/country.enum");
6
+ const duration_enum_1 = require("../enums/duration.enum");
7
+ describe('validateProductDowngradableRequestDto', () => {
8
+ it('should return no errors for a valid request', async () => {
9
+ const validRequest = {
10
+ clientData: {
11
+ email: 'test@example.com',
12
+ firstName: 'John',
13
+ lastName: 'Doe',
14
+ telephone: '+14155552671',
15
+ address1: '123 Main St',
16
+ postcode: '12345',
17
+ city: 'Anytown',
18
+ country: country_enum_1.CountryEnum.UNITED_STATES,
19
+ },
20
+ itemData: {
21
+ itemId: 'item-123',
22
+ productAttributes: { key: 'value' },
23
+ itemAttributes: { key: 'value' },
24
+ duration: duration_enum_1.DurationEnum.ONE_MONTH,
25
+ },
26
+ };
27
+ const errors = await (0, product_downgradable_request_validator_1.validateProductDowngradableRequestDto)(validRequest);
28
+ expect(errors.length).toBe(0);
29
+ });
30
+ it('should return errors for an invalid request', async () => {
31
+ const invalidRequest = {
32
+ clientData: {
33
+ email: 'not-an-email',
34
+ },
35
+ itemData: {},
36
+ };
37
+ const errors = await (0, product_downgradable_request_validator_1.validateProductDowngradableRequestDto)(invalidRequest);
38
+ expect(errors.length).toBeGreaterThan(0);
39
+ });
40
+ });
@@ -0,0 +1 @@
1
+ import 'reflect-metadata';
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("reflect-metadata");
4
+ const product_downgrade_request_validator_1 = require("./product-downgrade-request-validator");
5
+ const country_enum_1 = require("../enums/country.enum");
6
+ const duration_enum_1 = require("../enums/duration.enum");
7
+ describe('validateProductDowngradeRequestDto', () => {
8
+ it('should return no errors for a valid request', async () => {
9
+ const validRequest = {
10
+ clientData: {
11
+ email: 'test@example.com',
12
+ firstName: 'John',
13
+ lastName: 'Doe',
14
+ telephone: '+14155552671',
15
+ address1: '123 Main St',
16
+ postcode: '12345',
17
+ city: 'Anytown',
18
+ country: country_enum_1.CountryEnum.UNITED_STATES,
19
+ },
20
+ itemData: {
21
+ itemId: 'item-123',
22
+ productAttributes: { key: 'value' },
23
+ itemAttributes: { key: 'value' },
24
+ duration: duration_enum_1.DurationEnum.ONE_MONTH,
25
+ },
26
+ previousItemData: {
27
+ itemId: 'item-123',
28
+ productAttributes: { key: 'value' },
29
+ itemAttributes: { key: 'value' },
30
+ duration: duration_enum_1.DurationEnum.ONE_MONTH,
31
+ },
32
+ };
33
+ const errors = await (0, product_downgrade_request_validator_1.validateProductDowngradeRequestDto)(validRequest);
34
+ expect(errors.length).toBe(0);
35
+ });
36
+ it('should return errors for an invalid request', async () => {
37
+ const invalidRequest = {
38
+ clientData: {
39
+ email: 'not-an-email',
40
+ },
41
+ itemData: {},
42
+ };
43
+ const errors = await (0, product_downgrade_request_validator_1.validateProductDowngradeRequestDto)(invalidRequest);
44
+ expect(errors.length).toBeGreaterThan(0);
45
+ });
46
+ });
@@ -0,0 +1 @@
1
+ import 'reflect-metadata';
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("reflect-metadata");
4
+ // import { ProductInfoDto } from '../dtos/product/product-info.dto';
5
+ const actions_enum_1 = require("../enums/actions.enum");
6
+ const language_enum_1 = require("../enums/language.enum");
7
+ const field_type_enum_1 = require("../enums/field-type.enum");
8
+ const product_info_validator_1 = require("./product-info.validator");
9
+ describe('ProductInfoDto Validator', () => {
10
+ const field = {
11
+ id: 'field',
12
+ label: [{ language: language_enum_1.LanguageEnum.EN, text: "label" }],
13
+ value: 'string',
14
+ type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
15
+ required: false,
16
+ disabled: false,
17
+ hidden: false,
18
+ upgradable: false
19
+ };
20
+ const invalidField = {
21
+ id: 'field',
22
+ label: [{ language: language_enum_1.LanguageEnum.EN, text: "label" }],
23
+ value: 'string',
24
+ type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
25
+ disabled: false,
26
+ upgradable: false
27
+ };
28
+ const testCases = [
29
+ {
30
+ description: 'should return no errors for valid DTO',
31
+ dto: {
32
+ title: 'Test',
33
+ supportedActions: [actions_enum_1.ActionsEnum.CREATE],
34
+ supportedLanguages: [language_enum_1.LanguageEnum.EN],
35
+ productAttributes: [field],
36
+ itemAttributes: [field]
37
+ },
38
+ expectedErrorsLength: 0
39
+ },
40
+ {
41
+ description: 'should return error for invalid required and hidden',
42
+ dto: {
43
+ title: 'Test',
44
+ supportedActions: [actions_enum_1.ActionsEnum.CREATE],
45
+ supportedLanguages: [language_enum_1.LanguageEnum.EN],
46
+ itemAttributes: [invalidField]
47
+ },
48
+ expectedErrorsLength: 1
49
+ },
50
+ {
51
+ description: 'should return error for invalid title',
52
+ dto: {
53
+ title: '',
54
+ supportedActions: [actions_enum_1.ActionsEnum.CREATE],
55
+ supportedLanguages: [language_enum_1.LanguageEnum.EN],
56
+ productAttributes: [field],
57
+ itemAttributes: [field]
58
+ },
59
+ expectedErrorsLength: 1
60
+ },
61
+ {
62
+ description: 'should return error for unsupported action',
63
+ dto: {
64
+ title: 'Test',
65
+ supportedActions: ['update'],
66
+ supportedLanguages: [language_enum_1.LanguageEnum.EN],
67
+ productAttributes: [field],
68
+ itemAttributes: [field]
69
+ },
70
+ expectedErrorsLength: 1
71
+ },
72
+ {
73
+ description: 'should return error for unsupported language',
74
+ dto: {
75
+ title: 'Test',
76
+ supportedActions: [actions_enum_1.ActionsEnum.CREATE],
77
+ supportedLanguages: [],
78
+ productAttributes: [field],
79
+ itemAttributes: [field]
80
+ },
81
+ expectedErrorsLength: 1
82
+ },
83
+ {
84
+ description: 'should return no errors for valid DTO with adminPanel and clientPanel',
85
+ dto: {
86
+ title: 'Test',
87
+ supportedActions: [actions_enum_1.ActionsEnum.CREATE],
88
+ supportedLanguages: [language_enum_1.LanguageEnum.EN],
89
+ productAttributes: [field],
90
+ itemAttributes: [field],
91
+ adminPanel: { tabs: { product: [{ label: 'Product', url: 'https://example.com/product' }] } },
92
+ clientPanel: { tabs: { item: [{ label: 'Item', url: 'https://example.com/item' }] } }
93
+ },
94
+ expectedErrorsLength: 0
95
+ },
96
+ {
97
+ description: 'should return error for invalid DTO with adminPanel and clientPanel',
98
+ dto: {
99
+ title: '',
100
+ supportedActions: [actions_enum_1.ActionsEnum.CREATE],
101
+ supportedLanguages: [language_enum_1.LanguageEnum.EN],
102
+ productAttributes: [field],
103
+ itemAttributes: [field],
104
+ adminPanel: { /* invalid admin panel data */},
105
+ clientPanel: { /* invalid client panel data */}
106
+ },
107
+ expectedErrorsLength: 3
108
+ },
109
+ {
110
+ description: 'should return no errors for valid DTO with payPerUseUnits',
111
+ dto: {
112
+ title: 'Test',
113
+ supportedActions: [actions_enum_1.ActionsEnum.CREATE],
114
+ supportedLanguages: [language_enum_1.LanguageEnum.EN],
115
+ productAttributes: [field],
116
+ itemAttributes: [field],
117
+ payPerUseUnits: [{ id: "ram", unitDescription: "MB", intervalDescription: "month" }]
118
+ },
119
+ expectedErrorsLength: 0
120
+ },
121
+ {
122
+ description: 'should return error for invalid DTO with payPerUseUnits',
123
+ dto: {
124
+ title: 'Test',
125
+ supportedActions: [actions_enum_1.ActionsEnum.CREATE],
126
+ supportedLanguages: [language_enum_1.LanguageEnum.EN],
127
+ productAttributes: [field],
128
+ itemAttributes: [field],
129
+ payPerUseUnits: [{ id: "", unitDescription: "", intervalDescription: "" }]
130
+ },
131
+ expectedErrorsLength: 1
132
+ }
133
+ ];
134
+ testCases.forEach(({ description, dto, expectedErrorsLength }) => {
135
+ it(description, () => {
136
+ const errors = (0, product_info_validator_1.validateProductInfoDto)(dto);
137
+ expect(errors.length).toBe(expectedErrorsLength);
138
+ });
139
+ });
140
+ const validationErrorTestCases = [
141
+ {
142
+ description: 'should return ValidationError for missing title',
143
+ dto: {
144
+ supportedActions: [actions_enum_1.ActionsEnum.CREATE],
145
+ supportedLanguages: [language_enum_1.LanguageEnum.EN],
146
+ productAttributes: [field],
147
+ itemAttributes: [field]
148
+ },
149
+ expectedErrors: ['title']
150
+ },
151
+ {
152
+ description: 'should return ValidationError for unsupported action',
153
+ dto: {
154
+ title: 'Test',
155
+ supportedActions: ['update'],
156
+ supportedLanguages: [language_enum_1.LanguageEnum.EN],
157
+ productAttributes: [field],
158
+ itemAttributes: [field]
159
+ },
160
+ expectedErrors: ['supportedActions']
161
+ }
162
+ ];
163
+ validationErrorTestCases.forEach(({ description, dto, expectedErrors }) => {
164
+ it(description, async () => {
165
+ const errors = await (0, product_info_validator_1.validateProductInfoDto)(dto);
166
+ const errorProperties = errors.map(error => error.property);
167
+ expectedErrors.forEach(expectedError => {
168
+ expect(errorProperties).toContain(expectedError);
169
+ });
170
+ });
171
+ });
172
+ });
@@ -0,0 +1,2 @@
1
+ import { ValidationError } from "class-validator";
2
+ export declare function validateProductInfoDto(data: object): ValidationError[];
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateProductInfoDto = validateProductInfoDto;
4
+ const class_transformer_1 = require("class-transformer");
5
+ const class_validator_1 = require("class-validator");
6
+ const product_info_dto_1 = require("../dtos/product/product-info.dto");
7
+ function validateProductInfoDto(data) {
8
+ const dto = (0, class_transformer_1.plainToInstance)(product_info_dto_1.ProductInfoDto, data);
9
+ const errors = (0, class_validator_1.validateSync)(dto);
10
+ return errors;
11
+ }
@@ -0,0 +1 @@
1
+ import 'reflect-metadata';
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("reflect-metadata");
4
+ const product_renew_request_validator_1 = require("./product-renew-request-validator");
5
+ const country_enum_1 = require("../enums/country.enum");
6
+ const duration_enum_1 = require("../enums/duration.enum");
7
+ describe('validateProductRenewRequestDto', () => {
8
+ it('should return no errors for a valid request', async () => {
9
+ const validRequest = {
10
+ clientData: {
11
+ email: 'test@example.com',
12
+ firstName: 'John',
13
+ lastName: 'Doe',
14
+ telephone: '+14155552671',
15
+ address1: '123 Main St',
16
+ postcode: '12345',
17
+ city: 'Anytown',
18
+ country: country_enum_1.CountryEnum.UNITED_STATES,
19
+ },
20
+ itemData: {
21
+ itemId: 'item-123',
22
+ productAttributes: { key: 'value' },
23
+ itemAttributes: { key: 'value' },
24
+ duration: duration_enum_1.DurationEnum.ONE_MONTH,
25
+ },
26
+ };
27
+ const errors = await (0, product_renew_request_validator_1.validateProductRenewRequestDto)(validRequest);
28
+ expect(errors.length).toBe(0);
29
+ });
30
+ it('should return errors for an invalid request', async () => {
31
+ const invalidRequest = {
32
+ clientData: {
33
+ email: 'not-an-email',
34
+ },
35
+ itemData: {},
36
+ };
37
+ const errors = await (0, product_renew_request_validator_1.validateProductRenewRequestDto)(invalidRequest);
38
+ expect(errors.length).toBeGreaterThan(0);
39
+ });
40
+ });
@@ -0,0 +1 @@
1
+ import 'reflect-metadata';