@hosterai/types 0.0.17 → 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 +12 -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 +4 -79
- 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/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,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,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,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';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const product_suspend_request_validator_1 = require("./product-suspend-request-validator");
|
|
5
|
+
const country_enum_1 = require("../enums/country.enum");
|
|
6
|
+
const duration_enum_1 = require("../enums/duration.enum");
|
|
7
|
+
describe('validateProductSuspendRequestDto', () => {
|
|
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_suspend_request_validator_1.validateProductSuspendRequestDto)(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_suspend_request_validator_1.validateProductSuspendRequestDto)(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_unsuspend_request_validator_1 = require("./product-unsuspend-request-validator");
|
|
5
|
+
const country_enum_1 = require("../enums/country.enum");
|
|
6
|
+
const duration_enum_1 = require("../enums/duration.enum");
|
|
7
|
+
describe('validateProductUnsuspendRequestDto', () => {
|
|
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_unsuspend_request_validator_1.validateProductUnsuspendRequestDto)(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_unsuspend_request_validator_1.validateProductUnsuspendRequestDto)(invalidRequest);
|
|
38
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|