@hosterai/types 0.0.26 → 0.0.28
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 +49 -8
- package/dist/dtos/attachment.dto.js +17 -0
- package/dist/dtos/attribute-field.dto.d.ts +9 -10
- package/dist/dtos/attribute-field.dto.js +28 -38
- package/dist/dtos/base-response.dto.js +11 -0
- package/dist/dtos/client-data.dto.js +82 -0
- package/dist/dtos/company-data.dto.js +97 -0
- package/dist/dtos/country.dto.js +17 -0
- package/dist/dtos/error-response.dto.js +15 -0
- package/dist/dtos/field.dto.d.ts +17 -1
- package/dist/dtos/field.dto.js +41 -10
- package/dist/dtos/info.dto.d.ts +0 -6
- package/dist/dtos/info.dto.js +0 -24
- package/dist/dtos/invoice/invoice-item-data.dto.js +7 -0
- package/dist/dtos/invoice/requests/credit-note-request.dto.js +6 -0
- package/dist/dtos/invoice/requests/invoice-request.dto.js +6 -0
- package/dist/dtos/invoice/requests/proforma-invoice-request.dto.d.ts +3 -0
- package/dist/dtos/invoice/requests/proforma-invoice-request.dto.js +51 -3
- package/dist/dtos/invoice/requests/tax-details-request.dto.d.ts +31 -0
- package/dist/dtos/invoice/requests/tax-details-request.dto.js +84 -0
- package/dist/dtos/invoice/responses/proforma-invoice-response.dto.js +17 -0
- package/dist/dtos/invoice/responses/tax-details-response.dto.d.ts +20 -0
- package/dist/dtos/invoice/responses/tax-details-response.dto.js +56 -0
- package/dist/dtos/invoice/tin-validation-details.dto.d.ts +51 -0
- package/dist/dtos/invoice/tin-validation-details.dto.js +165 -0
- package/dist/dtos/invoice/transaction-data.dto.js +22 -0
- package/dist/dtos/invoice-contact-data.dto.js +102 -0
- package/dist/dtos/item-data.dto.d.ts +2 -2
- package/dist/dtos/item-data.dto.js +63 -2
- package/dist/dtos/jwt.dto.js +27 -0
- package/dist/dtos/multilang-text.dto.js +12 -0
- package/dist/dtos/notification/receiver/receiver-email.dto.js +19 -0
- package/dist/dtos/notification/receiver/receiver-sms.dto.js +7 -0
- package/dist/dtos/notification/requests/notification-send-request.dto.d.ts +3 -3
- package/dist/dtos/notification/requests/notification-send-request.dto.js +27 -3
- package/dist/dtos/notification/responses/notification-send-response.dto.js +6 -0
- package/dist/dtos/notification/sender/sender-email.dto.js +26 -0
- package/dist/dtos/notification/sender/sender-push.dto.js +36 -0
- package/dist/dtos/notification/sender/sender-sms.dto.js +11 -0
- package/dist/dtos/product/product-info.dto.d.ts +4 -4
- package/dist/dtos/product/product-info.dto.js +7 -7
- package/dist/dtos/product/product-item-data.dto.d.ts +1 -1
- package/dist/dtos/product/product-item-data.dto.js +8 -1
- package/dist/dtos/product/requests/product-create-request.dto.d.ts +1 -1
- package/dist/dtos/product/requests/product-create-request.dto.js +12 -1
- package/dist/dtos/product/requests/product-delete-request.dto.d.ts +1 -1
- package/dist/dtos/product/requests/product-delete-request.dto.js +12 -1
- package/dist/dtos/product/requests/product-downgradable-request.dto.d.ts +1 -1
- package/dist/dtos/product/requests/product-downgradable-request.dto.js +12 -1
- package/dist/dtos/product/requests/product-downgrade-request.dto.d.ts +1 -1
- package/dist/dtos/product/requests/product-downgrade-request.dto.js +17 -1
- package/dist/dtos/product/requests/product-downgradeable-request.dto.d.ts +18 -0
- package/dist/dtos/product/requests/product-downgradeable-request.dto.js +37 -0
- package/dist/dtos/product/requests/product-renew-request.dto.d.ts +1 -1
- package/dist/dtos/product/requests/product-renew-request.dto.js +12 -1
- package/dist/dtos/product/requests/product-suspend-request.dto.d.ts +1 -1
- package/dist/dtos/product/requests/product-suspend-request.dto.js +12 -1
- package/dist/dtos/product/requests/product-unsuspend-request.dto.d.ts +1 -1
- package/dist/dtos/product/requests/product-unsuspend-request.dto.js +12 -1
- package/dist/dtos/product/requests/product-upgradable-request.dto.d.ts +1 -1
- package/dist/dtos/product/requests/product-upgradable-request.dto.js +12 -1
- package/dist/dtos/product/requests/product-upgrade-request.dto.d.ts +1 -1
- package/dist/dtos/product/requests/product-upgrade-request.dto.js +17 -1
- package/dist/dtos/product/requests/product-upgradeable-request.dto.d.ts +18 -0
- package/dist/dtos/product/requests/product-upgradeable-request.dto.js +37 -0
- package/dist/dtos/product/responses/product-create-response.dto.js +37 -0
- package/dist/dtos/product/responses/product-delete-response.dto.js +37 -0
- package/dist/dtos/product/responses/product-downgradable-response.dto.js +37 -0
- package/dist/dtos/product/responses/product-downgrade-response.dto.js +37 -0
- package/dist/dtos/product/responses/product-downgradeable-response.dto.d.ts +22 -0
- package/dist/dtos/product/responses/product-downgradeable-response.dto.js +11 -0
- package/dist/dtos/product/responses/product-info-response.dto.js +6 -0
- package/dist/dtos/product/responses/product-renew-response.dto.js +37 -0
- package/dist/dtos/product/responses/product-suspend-response.dto.js +37 -0
- package/dist/dtos/product/responses/product-unsuspend-response.dto.js +37 -0
- package/dist/dtos/product/responses/product-upgradable-response.dto.js +37 -0
- package/dist/dtos/product/responses/product-upgrade-response.dto.js +37 -0
- package/dist/dtos/product/responses/product-upgradeable-response.dto.d.ts +22 -0
- package/dist/dtos/product/responses/product-upgradeable-response.dto.js +11 -0
- package/dist/dtos/requests/validate-attributes-request.dto.js +12 -0
- package/dist/dtos/response-data.dto.js +19 -0
- package/dist/dtos/responses/validate-attributes-response.dto.js +7 -0
- package/dist/dtos/setup-status-response.dto.js +20 -0
- package/dist/enums/events.enum.d.ts +3 -0
- package/dist/enums/events.enum.js +3 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +24 -0
- package/dist/openapi/schemas/components.schemas.d.ts +155 -40
- package/dist/openapi/schemas/components.schemas.js +187 -96
- package/dist/validators/addon-field-validator.d.ts +9 -0
- package/dist/validators/addon-field-validator.js +14 -0
- package/dist/validators/addon-field-validator.spec.d.ts +1 -0
- package/dist/validators/addon-field-validator.spec.js +38 -0
- package/dist/validators/attachment-validator.d.ts +8 -0
- package/dist/validators/attachment-validator.js +17 -0
- package/dist/validators/attachment-validator.spec.d.ts +1 -0
- package/dist/validators/attachment-validator.spec.js +58 -0
- package/dist/validators/attribute-field-validator.d.ts +8 -0
- package/dist/validators/attribute-field-validator.js +17 -0
- package/dist/validators/attribute-field-validator.spec.d.ts +1 -0
- package/dist/validators/attribute-field-validator.spec.js +84 -0
- package/dist/validators/country-validator.d.ts +8 -0
- package/dist/validators/country-validator.js +17 -0
- package/dist/validators/country-validator.spec.d.ts +1 -0
- package/dist/validators/country-validator.spec.js +58 -0
- package/dist/validators/field-validator.spec.js +1 -29
- package/dist/validators/info-validator.d.ts +8 -0
- package/dist/validators/info-validator.js +17 -0
- package/dist/validators/info-validator.spec.d.ts +1 -0
- package/dist/validators/info-validator.spec.js +85 -0
- package/dist/validators/invoice-contact-data-validator.d.ts +8 -0
- package/dist/validators/invoice-contact-data-validator.js +17 -0
- package/dist/validators/invoice-contact-data-validator.spec.d.ts +1 -0
- package/dist/validators/invoice-contact-data-validator.spec.js +88 -0
- package/dist/validators/invoice-info-validator.d.ts +8 -0
- package/dist/validators/invoice-info-validator.js +17 -0
- package/dist/validators/invoice-info-validator.spec.d.ts +1 -0
- package/dist/validators/invoice-info-validator.spec.js +81 -0
- package/dist/validators/invoice-item-data-validator.d.ts +8 -0
- package/dist/validators/invoice-item-data-validator.js +17 -0
- package/dist/validators/invoice-item-data-validator.spec.d.ts +1 -0
- package/dist/validators/invoice-item-data-validator.spec.js +45 -0
- package/dist/validators/item-data-validator.d.ts +8 -0
- package/dist/validators/item-data-validator.js +17 -0
- package/dist/validators/item-data-validator.spec.d.ts +1 -0
- package/dist/validators/item-data-validator.spec.js +79 -0
- package/dist/validators/notification-request-validator.js +1 -1
- package/dist/validators/product-create-request-validator.js +1 -1
- package/dist/validators/product-delete-request-validator.js +1 -1
- package/dist/validators/product-downgradable-request-validator.js +1 -1
- package/dist/validators/product-downgrade-request-validator.js +1 -1
- package/dist/validators/product-downgradeable-request-validator.d.ts +8 -0
- package/dist/validators/product-downgradeable-request-validator.js +17 -0
- package/dist/validators/product-info-validator.spec.js +5 -1
- package/dist/validators/product-item-data-validator.d.ts +8 -0
- package/dist/validators/product-item-data-validator.js +17 -0
- package/dist/validators/product-item-data-validator.spec.d.ts +1 -0
- package/dist/validators/product-item-data-validator.spec.js +60 -0
- package/dist/validators/product-renew-request-validator.js +1 -1
- package/dist/validators/product-suspend-request-validator.js +1 -1
- package/dist/validators/product-unsuspend-request-validator.js +1 -1
- package/dist/validators/product-upgradable-request-validator.js +1 -1
- package/dist/validators/product-upgrade-request-validator.js +1 -1
- package/dist/validators/product-upgradeable-request-validator.d.ts +8 -0
- package/dist/validators/product-upgradeable-request-validator.js +17 -0
- package/dist/validators/tab-validator.d.ts +8 -0
- package/dist/validators/tab-validator.js +17 -0
- package/dist/validators/tab-validator.spec.d.ts +1 -0
- package/dist/validators/tab-validator.spec.js +49 -0
- package/dist/validators/tin-validation-details-validator.d.ts +8 -0
- package/dist/validators/tin-validation-details-validator.js +17 -0
- package/dist/validators/tin-validation-details-validator.spec.d.ts +1 -0
- package/dist/validators/tin-validation-details-validator.spec.js +77 -0
- package/dist/validators/transaction-data-validator.d.ts +8 -0
- package/dist/validators/transaction-data-validator.js +17 -0
- package/dist/validators/transaction-data-validator.spec.d.ts +1 -0
- package/dist/validators/transaction-data-validator.spec.js +62 -0
- package/package.json +1 -1
- package/dist/dtos/info/info-notification.dto.d.ts +0 -5
- package/dist/dtos/info/info-notification.dto.js +0 -7
- package/dist/dtos/info/info.dto.d.ts +0 -196
- package/dist/dtos/info/info.dto.js +0 -278
- package/dist/dtos/notification/notification-request.dto.d.ts +0 -20
- package/dist/dtos/notification/notification-request.dto.js +0 -31
- package/dist/dtos/receiver/receiver-email.dto.d.ts +0 -20
- package/dist/dtos/receiver/receiver-email.dto.js +0 -39
- package/dist/dtos/receiver/receiver-push.dto.d.ts +0 -15
- package/dist/dtos/receiver/receiver-push.dto.js +0 -31
- package/dist/dtos/receiver/receiver-sms.dto.d.ts +0 -11
- package/dist/dtos/receiver/receiver-sms.dto.js +0 -26
- package/dist/dtos/request.dto.d.ts +0 -20
- package/dist/dtos/request.dto.js +0 -31
- package/dist/dtos/sender/sender-email.dto.d.ts +0 -25
- package/dist/dtos/sender/sender-email.dto.js +0 -46
- package/dist/dtos/sender/sender-push.dto.d.ts +0 -31
- package/dist/dtos/sender/sender-push.dto.js +0 -50
- package/dist/dtos/sender/sender-sms.dto.d.ts +0 -15
- package/dist/dtos/sender/sender-sms.dto.js +0 -30
- package/dist/enums/message-type.enum.d.ts +0 -5
- package/dist/enums/message-type.enum.js +0 -9
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ValidationError } from 'class-validator';
|
|
2
|
+
/**
|
|
3
|
+
* Validates a CountryDto object using class-validator decorators.
|
|
4
|
+
*
|
|
5
|
+
* @param data The object to validate as a CountryDto.
|
|
6
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateCountryDto(data: object): ValidationError[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateCountryDto = validateCountryDto;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const country_dto_1 = require("../dtos/country.dto");
|
|
7
|
+
/**
|
|
8
|
+
* Validates a CountryDto object using class-validator decorators.
|
|
9
|
+
*
|
|
10
|
+
* @param data The object to validate as a CountryDto.
|
|
11
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
12
|
+
*/
|
|
13
|
+
function validateCountryDto(data) {
|
|
14
|
+
const dto = (0, class_transformer_1.plainToInstance)(country_dto_1.CountryDto, data);
|
|
15
|
+
const errors = (0, class_validator_1.validateSync)(dto);
|
|
16
|
+
return errors;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const country_validator_1 = require("./country-validator");
|
|
5
|
+
const country_enum_1 = require("../enums/country.enum");
|
|
6
|
+
const baseValidDto = {
|
|
7
|
+
name: 'Greece',
|
|
8
|
+
code: country_enum_1.CountryEnum.GREECE,
|
|
9
|
+
};
|
|
10
|
+
describe('CountryDto Validator', () => {
|
|
11
|
+
describe('Valid cases', () => {
|
|
12
|
+
it('should return no errors for a valid DTO', () => {
|
|
13
|
+
expect((0, country_validator_1.validateCountryDto)(baseValidDto)).toHaveLength(0);
|
|
14
|
+
});
|
|
15
|
+
it('should return no errors with optional isEurope', () => {
|
|
16
|
+
const dto = { ...baseValidDto, isEurope: true };
|
|
17
|
+
expect((0, country_validator_1.validateCountryDto)(dto)).toHaveLength(0);
|
|
18
|
+
});
|
|
19
|
+
it('should return no errors with isEurope false', () => {
|
|
20
|
+
const dto = { ...baseValidDto, isEurope: false };
|
|
21
|
+
expect((0, country_validator_1.validateCountryDto)(dto)).toHaveLength(0);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe('Missing required fields', () => {
|
|
25
|
+
it('should return errors when all fields are missing', () => {
|
|
26
|
+
const errors = (0, country_validator_1.validateCountryDto)({});
|
|
27
|
+
expect(errors.some(e => e.property === 'name')).toBe(true);
|
|
28
|
+
expect(errors.some(e => e.property === 'code')).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
it('should return error when name is missing', () => {
|
|
31
|
+
const dto = { code: country_enum_1.CountryEnum.GREECE };
|
|
32
|
+
const errors = (0, country_validator_1.validateCountryDto)(dto);
|
|
33
|
+
expect(errors.some(e => e.property === 'name')).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
it('should return error when code is missing', () => {
|
|
36
|
+
const dto = { name: 'Greece' };
|
|
37
|
+
const errors = (0, country_validator_1.validateCountryDto)(dto);
|
|
38
|
+
expect(errors.some(e => e.property === 'code')).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe('Invalid field values', () => {
|
|
42
|
+
it('should return error for empty name', () => {
|
|
43
|
+
const dto = { ...baseValidDto, name: '' };
|
|
44
|
+
const errors = (0, country_validator_1.validateCountryDto)(dto);
|
|
45
|
+
expect(errors.some(e => e.property === 'name')).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
it('should return error for invalid country code', () => {
|
|
48
|
+
const dto = { ...baseValidDto, code: 'INVALID' };
|
|
49
|
+
const errors = (0, country_validator_1.validateCountryDto)(dto);
|
|
50
|
+
expect(errors.some(e => e.property === 'code')).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
it('should return error for non-boolean isEurope', () => {
|
|
53
|
+
const dto = { ...baseValidDto, isEurope: 'yes' };
|
|
54
|
+
const errors = (0, country_validator_1.validateCountryDto)(dto);
|
|
55
|
+
expect(errors.some(e => e.property === 'isEurope')).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -11,8 +11,6 @@ const baseValidDto = {
|
|
|
11
11
|
type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
|
|
12
12
|
required: true,
|
|
13
13
|
disabled: false,
|
|
14
|
-
visibleInOrder: false,
|
|
15
|
-
visibleInClientPanel: false,
|
|
16
14
|
upgradable: false,
|
|
17
15
|
};
|
|
18
16
|
describe('FieldDto Validator', () => {
|
|
@@ -32,7 +30,7 @@ describe('FieldDto Validator', () => {
|
|
|
32
30
|
describe('Missing required fields', () => {
|
|
33
31
|
it('should return errors for all missing required fields (except upgradable)', () => {
|
|
34
32
|
const errors = (0, field_validator_1.validateFieldDto)({});
|
|
35
|
-
const requiredProps = ['id', 'label', 'value', 'type', 'required', 'disabled'
|
|
33
|
+
const requiredProps = ['id', 'label', 'value', 'type', 'required', 'disabled'];
|
|
36
34
|
for (const prop of requiredProps) {
|
|
37
35
|
expect(errors.some(e => e.property === prop)).toBe(true);
|
|
38
36
|
}
|
|
@@ -74,30 +72,4 @@ describe('FieldDto Validator', () => {
|
|
|
74
72
|
expect(errors.some(e => e.property === 'value')).toBe(true);
|
|
75
73
|
});
|
|
76
74
|
});
|
|
77
|
-
describe('Repeatable constraints (AllOrNone and Min<=Max)', () => {
|
|
78
|
-
it('should fail when only repeatableMin is present', () => {
|
|
79
|
-
const dto = { ...baseValidDto, repeatableMin: 1 };
|
|
80
|
-
const errors = (0, field_validator_1.validateFieldDto)(dto);
|
|
81
|
-
expect(errors.length).toBeGreaterThan(0);
|
|
82
|
-
// Class-level error; ensure at least one constraint exists
|
|
83
|
-
expect(errors.some(e => e.constraints && (e.constraints['AllOrNone'] || Object.values(e.constraints).some(msg => msg.includes('All of'))))).toBe(true);
|
|
84
|
-
});
|
|
85
|
-
it('should fail when only repeatableMax is present', () => {
|
|
86
|
-
const dto = { ...baseValidDto, repeatableMax: 2 };
|
|
87
|
-
const errors = (0, field_validator_1.validateFieldDto)(dto);
|
|
88
|
-
expect(errors.length).toBeGreaterThan(0);
|
|
89
|
-
expect(errors.some(e => e.constraints && (e.constraints['AllOrNone'] || Object.values(e.constraints).some(msg => msg.includes('All of'))))).toBe(true);
|
|
90
|
-
});
|
|
91
|
-
it('should pass when both present and repeatableMin <= repeatableMax', () => {
|
|
92
|
-
const dto = { ...baseValidDto, repeatableMin: 1, repeatableMax: 2 };
|
|
93
|
-
const errors = (0, field_validator_1.validateFieldDto)(dto);
|
|
94
|
-
expect(errors).toHaveLength(0);
|
|
95
|
-
});
|
|
96
|
-
it('should fail when both present and repeatableMin > repeatableMax', () => {
|
|
97
|
-
const dto = { ...baseValidDto, repeatableMin: 3, repeatableMax: 2 };
|
|
98
|
-
const errors = (0, field_validator_1.validateFieldDto)(dto);
|
|
99
|
-
expect(errors.length).toBeGreaterThan(0);
|
|
100
|
-
expect(errors.some(e => e.constraints && (e.constraints['MinLessOrEqualMax'] || Object.values(e.constraints).some(msg => msg.includes('must be less than or equal'))))).toBe(true);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
75
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ValidationError } from 'class-validator';
|
|
2
|
+
/**
|
|
3
|
+
* Validates an InfoDto object using class-validator decorators.
|
|
4
|
+
*
|
|
5
|
+
* @param data The object to validate as an InfoDto.
|
|
6
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateInfoDto(data: object): ValidationError[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateInfoDto = validateInfoDto;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const info_dto_1 = require("../dtos/info.dto");
|
|
7
|
+
/**
|
|
8
|
+
* Validates an InfoDto object using class-validator decorators.
|
|
9
|
+
*
|
|
10
|
+
* @param data The object to validate as an InfoDto.
|
|
11
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
12
|
+
*/
|
|
13
|
+
function validateInfoDto(data) {
|
|
14
|
+
const dto = (0, class_transformer_1.plainToInstance)(info_dto_1.InfoDto, data);
|
|
15
|
+
const errors = (0, class_validator_1.validateSync)(dto);
|
|
16
|
+
return errors;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const info_validator_1 = require("./info-validator");
|
|
5
|
+
const language_enum_1 = require("../enums/language.enum");
|
|
6
|
+
const events_enum_1 = require("../enums/events.enum");
|
|
7
|
+
const roles_enum_1 = require("../enums/roles.enum");
|
|
8
|
+
const baseValidDto = {
|
|
9
|
+
title: 'My Integration',
|
|
10
|
+
supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
|
|
11
|
+
};
|
|
12
|
+
describe('InfoDto Validator', () => {
|
|
13
|
+
describe('Valid cases', () => {
|
|
14
|
+
it('should return no errors for a valid DTO with required fields only', () => {
|
|
15
|
+
expect((0, info_validator_1.validateInfoDto)(baseValidDto)).toHaveLength(0);
|
|
16
|
+
});
|
|
17
|
+
it('should return no errors with all optional fields', () => {
|
|
18
|
+
const dto = {
|
|
19
|
+
...baseValidDto,
|
|
20
|
+
logo: 'https://example.com/logo.png',
|
|
21
|
+
description: 'A test integration',
|
|
22
|
+
listenEvents: [events_enum_1.EventsEnum.USER_CREATED],
|
|
23
|
+
requiredRoles: [roles_enum_1.RolesEnum.FULL_ACCESS],
|
|
24
|
+
onboardingUrl: 'https://example.com/onboarding',
|
|
25
|
+
};
|
|
26
|
+
expect((0, info_validator_1.validateInfoDto)(dto)).toHaveLength(0);
|
|
27
|
+
});
|
|
28
|
+
it('should return no errors with multiple supported languages', () => {
|
|
29
|
+
const dto = {
|
|
30
|
+
...baseValidDto,
|
|
31
|
+
supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH, language_enum_1.LanguageEnum.FRENCH],
|
|
32
|
+
};
|
|
33
|
+
expect((0, info_validator_1.validateInfoDto)(dto)).toHaveLength(0);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
describe('Missing required fields', () => {
|
|
37
|
+
it('should return errors when all fields are missing', () => {
|
|
38
|
+
const errors = (0, info_validator_1.validateInfoDto)({});
|
|
39
|
+
expect(errors.some(e => e.property === 'title')).toBe(true);
|
|
40
|
+
expect(errors.some(e => e.property === 'supportedLanguages')).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
it('should return error when title is missing', () => {
|
|
43
|
+
const { title, ...dto } = baseValidDto;
|
|
44
|
+
const errors = (0, info_validator_1.validateInfoDto)(dto);
|
|
45
|
+
expect(errors.some(e => e.property === 'title')).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
it('should return error when supportedLanguages is missing', () => {
|
|
48
|
+
const { supportedLanguages, ...dto } = baseValidDto;
|
|
49
|
+
const errors = (0, info_validator_1.validateInfoDto)(dto);
|
|
50
|
+
expect(errors.some(e => e.property === 'supportedLanguages')).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe('Invalid field values', () => {
|
|
54
|
+
it('should return error for empty title', () => {
|
|
55
|
+
const dto = { ...baseValidDto, title: '' };
|
|
56
|
+
const errors = (0, info_validator_1.validateInfoDto)(dto);
|
|
57
|
+
expect(errors.some(e => e.property === 'title')).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
it('should return error for empty supportedLanguages array', () => {
|
|
60
|
+
const dto = { ...baseValidDto, supportedLanguages: [] };
|
|
61
|
+
const errors = (0, info_validator_1.validateInfoDto)(dto);
|
|
62
|
+
expect(errors.some(e => e.property === 'supportedLanguages')).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
it('should return error for invalid language enum', () => {
|
|
65
|
+
const dto = { ...baseValidDto, supportedLanguages: ['INVALID'] };
|
|
66
|
+
const errors = (0, info_validator_1.validateInfoDto)(dto);
|
|
67
|
+
expect(errors.some(e => e.property === 'supportedLanguages')).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
it('should return error for invalid logo URL (not https)', () => {
|
|
70
|
+
const dto = { ...baseValidDto, logo: 'http://example.com/logo.png' };
|
|
71
|
+
const errors = (0, info_validator_1.validateInfoDto)(dto);
|
|
72
|
+
expect(errors.some(e => e.property === 'logo')).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
it('should return error for invalid logo URL (not a URL)', () => {
|
|
75
|
+
const dto = { ...baseValidDto, logo: 'not-a-url' };
|
|
76
|
+
const errors = (0, info_validator_1.validateInfoDto)(dto);
|
|
77
|
+
expect(errors.some(e => e.property === 'logo')).toBe(true);
|
|
78
|
+
});
|
|
79
|
+
it('should return error for invalid onboardingUrl', () => {
|
|
80
|
+
const dto = { ...baseValidDto, onboardingUrl: 'not-a-url' };
|
|
81
|
+
const errors = (0, info_validator_1.validateInfoDto)(dto);
|
|
82
|
+
expect(errors.some(e => e.property === 'onboardingUrl')).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ValidationError } from 'class-validator';
|
|
2
|
+
/**
|
|
3
|
+
* Validates an InvoiceContactData object using class-validator decorators.
|
|
4
|
+
*
|
|
5
|
+
* @param data The object to validate as an InvoiceContactData.
|
|
6
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateInvoiceContactDataDto(data: object): ValidationError[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateInvoiceContactDataDto = validateInvoiceContactDataDto;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const invoice_contact_data_dto_1 = require("../dtos/invoice-contact-data.dto");
|
|
7
|
+
/**
|
|
8
|
+
* Validates an InvoiceContactData object using class-validator decorators.
|
|
9
|
+
*
|
|
10
|
+
* @param data The object to validate as an InvoiceContactData.
|
|
11
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
12
|
+
*/
|
|
13
|
+
function validateInvoiceContactDataDto(data) {
|
|
14
|
+
const dto = (0, class_transformer_1.plainToInstance)(invoice_contact_data_dto_1.InvoiceContactData, data);
|
|
15
|
+
const errors = (0, class_validator_1.validateSync)(dto);
|
|
16
|
+
return errors;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const invoice_contact_data_validator_1 = require("./invoice-contact-data-validator");
|
|
5
|
+
const country_enum_1 = require("../enums/country.enum");
|
|
6
|
+
const baseValidDto = {
|
|
7
|
+
invoiceContactId: 'ic-001',
|
|
8
|
+
isBusinessContact: false,
|
|
9
|
+
firstName: 'John',
|
|
10
|
+
lastName: 'Doe',
|
|
11
|
+
email: 'john@example.com',
|
|
12
|
+
telephone: '+14155552671',
|
|
13
|
+
address1: '123 Main St',
|
|
14
|
+
postcode: '12345',
|
|
15
|
+
city: 'Anytown',
|
|
16
|
+
country: country_enum_1.CountryEnum.UNITED_STATES,
|
|
17
|
+
};
|
|
18
|
+
describe('InvoiceContactData Validator', () => {
|
|
19
|
+
describe('Valid cases', () => {
|
|
20
|
+
it('should return no errors for a valid DTO', () => {
|
|
21
|
+
expect((0, invoice_contact_data_validator_1.validateInvoiceContactDataDto)(baseValidDto)).toHaveLength(0);
|
|
22
|
+
});
|
|
23
|
+
it('should return no errors for a business contact with all optional fields', () => {
|
|
24
|
+
const dto = {
|
|
25
|
+
...baseValidDto,
|
|
26
|
+
isBusinessContact: true,
|
|
27
|
+
businessName: 'Acme Corp',
|
|
28
|
+
mobile: '+14155552672',
|
|
29
|
+
address2: 'Suite 100',
|
|
30
|
+
address3: 'Building A',
|
|
31
|
+
state: 'California',
|
|
32
|
+
tin: 'US123456789',
|
|
33
|
+
taxOffice: 'IRS',
|
|
34
|
+
profession: 'Software Development',
|
|
35
|
+
};
|
|
36
|
+
expect((0, invoice_contact_data_validator_1.validateInvoiceContactDataDto)(dto)).toHaveLength(0);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
describe('Missing required fields', () => {
|
|
40
|
+
it('should return errors when all fields are missing', () => {
|
|
41
|
+
const errors = (0, invoice_contact_data_validator_1.validateInvoiceContactDataDto)({});
|
|
42
|
+
const requiredProps = [
|
|
43
|
+
'invoiceContactId', 'isBusinessContact', 'firstName', 'lastName',
|
|
44
|
+
'email', 'telephone', 'address1', 'postcode', 'city', 'country',
|
|
45
|
+
];
|
|
46
|
+
for (const prop of requiredProps) {
|
|
47
|
+
expect(errors.some(e => e.property === prop)).toBe(true);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
it('should return error when invoiceContactId is missing', () => {
|
|
51
|
+
const { invoiceContactId, ...dto } = baseValidDto;
|
|
52
|
+
const errors = (0, invoice_contact_data_validator_1.validateInvoiceContactDataDto)(dto);
|
|
53
|
+
expect(errors.some(e => e.property === 'invoiceContactId')).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
describe('Invalid field values', () => {
|
|
57
|
+
it('should return error for invalid email', () => {
|
|
58
|
+
const dto = { ...baseValidDto, email: 'not-an-email' };
|
|
59
|
+
const errors = (0, invoice_contact_data_validator_1.validateInvoiceContactDataDto)(dto);
|
|
60
|
+
expect(errors.some(e => e.property === 'email')).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
it('should return error for invalid telephone', () => {
|
|
63
|
+
const dto = { ...baseValidDto, telephone: '123' };
|
|
64
|
+
const errors = (0, invoice_contact_data_validator_1.validateInvoiceContactDataDto)(dto);
|
|
65
|
+
expect(errors.some(e => e.property === 'telephone')).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
it('should return error for invalid country code', () => {
|
|
68
|
+
const dto = { ...baseValidDto, country: 'INVALID' };
|
|
69
|
+
const errors = (0, invoice_contact_data_validator_1.validateInvoiceContactDataDto)(dto);
|
|
70
|
+
expect(errors.some(e => e.property === 'country')).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
it('should return error for address1 exceeding max length', () => {
|
|
73
|
+
const dto = { ...baseValidDto, address1: 'a'.repeat(251) };
|
|
74
|
+
const errors = (0, invoice_contact_data_validator_1.validateInvoiceContactDataDto)(dto);
|
|
75
|
+
expect(errors.some(e => e.property === 'address1')).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
it('should return error for postcode exceeding max length', () => {
|
|
78
|
+
const dto = { ...baseValidDto, postcode: '1'.repeat(17) };
|
|
79
|
+
const errors = (0, invoice_contact_data_validator_1.validateInvoiceContactDataDto)(dto);
|
|
80
|
+
expect(errors.some(e => e.property === 'postcode')).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
it('should return error for invalid mobile phone', () => {
|
|
83
|
+
const dto = { ...baseValidDto, mobile: 'not-a-phone' };
|
|
84
|
+
const errors = (0, invoice_contact_data_validator_1.validateInvoiceContactDataDto)(dto);
|
|
85
|
+
expect(errors.some(e => e.property === 'mobile')).toBe(true);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ValidationError } from 'class-validator';
|
|
2
|
+
/**
|
|
3
|
+
* Validates an InvoiceInfoDto object using class-validator decorators.
|
|
4
|
+
*
|
|
5
|
+
* @param data The object to validate as an InvoiceInfoDto.
|
|
6
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateInvoiceInfoDto(data: object): ValidationError[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateInvoiceInfoDto = validateInvoiceInfoDto;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const invoice_info_dto_1 = require("../dtos/invoice/invoice-info.dto");
|
|
7
|
+
/**
|
|
8
|
+
* Validates an InvoiceInfoDto object using class-validator decorators.
|
|
9
|
+
*
|
|
10
|
+
* @param data The object to validate as an InvoiceInfoDto.
|
|
11
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
12
|
+
*/
|
|
13
|
+
function validateInvoiceInfoDto(data) {
|
|
14
|
+
const dto = (0, class_transformer_1.plainToInstance)(invoice_info_dto_1.InvoiceInfoDto, data);
|
|
15
|
+
const errors = (0, class_validator_1.validateSync)(dto);
|
|
16
|
+
return errors;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const invoice_info_validator_1 = require("./invoice-info-validator");
|
|
5
|
+
const language_enum_1 = require("../enums/language.enum");
|
|
6
|
+
const invoice_types_enum_1 = require("../enums/invoice/invoice-types.enum");
|
|
7
|
+
const country_enum_1 = require("../enums/country.enum");
|
|
8
|
+
const baseValidDto = {
|
|
9
|
+
title: 'Invoice Integration',
|
|
10
|
+
supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
|
|
11
|
+
supportedTypes: [invoice_types_enum_1.InvoiceTypesEnum.INVOICE],
|
|
12
|
+
supportedCountries: [country_enum_1.CountryEnum.GREECE],
|
|
13
|
+
};
|
|
14
|
+
describe('InvoiceInfoDto Validator', () => {
|
|
15
|
+
describe('Valid cases', () => {
|
|
16
|
+
it('should return no errors for a valid DTO', () => {
|
|
17
|
+
const errors = (0, invoice_info_validator_1.validateInvoiceInfoDto)(baseValidDto);
|
|
18
|
+
expect(errors).toHaveLength(0);
|
|
19
|
+
});
|
|
20
|
+
it('should return no errors with all supported types', () => {
|
|
21
|
+
const dto = {
|
|
22
|
+
...baseValidDto,
|
|
23
|
+
supportedTypes: [invoice_types_enum_1.InvoiceTypesEnum.INVOICE, invoice_types_enum_1.InvoiceTypesEnum.CREDIT_NOTE, invoice_types_enum_1.InvoiceTypesEnum.PROFORMA],
|
|
24
|
+
};
|
|
25
|
+
expect((0, invoice_info_validator_1.validateInvoiceInfoDto)(dto)).toHaveLength(0);
|
|
26
|
+
});
|
|
27
|
+
it('should return no errors with optional inherited fields', () => {
|
|
28
|
+
const dto = {
|
|
29
|
+
...baseValidDto,
|
|
30
|
+
logo: 'https://example.com/logo.png',
|
|
31
|
+
description: 'An invoice integration',
|
|
32
|
+
onboardingUrl: 'https://example.com/onboarding',
|
|
33
|
+
};
|
|
34
|
+
expect((0, invoice_info_validator_1.validateInvoiceInfoDto)(dto)).toHaveLength(0);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('Missing required fields', () => {
|
|
38
|
+
it('should return errors when all fields are missing', () => {
|
|
39
|
+
const errors = (0, invoice_info_validator_1.validateInvoiceInfoDto)({});
|
|
40
|
+
expect(errors.some(e => e.property === 'title')).toBe(true);
|
|
41
|
+
expect(errors.some(e => e.property === 'supportedLanguages')).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
it('should return error when title is missing', () => {
|
|
44
|
+
const { title, ...dto } = baseValidDto;
|
|
45
|
+
const errors = (0, invoice_info_validator_1.validateInvoiceInfoDto)(dto);
|
|
46
|
+
expect(errors.some(e => e.property === 'title')).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
it('should return error when supportedLanguages is missing', () => {
|
|
49
|
+
const { supportedLanguages, ...dto } = baseValidDto;
|
|
50
|
+
const errors = (0, invoice_info_validator_1.validateInvoiceInfoDto)(dto);
|
|
51
|
+
expect(errors.some(e => e.property === 'supportedLanguages')).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe('Invalid field values', () => {
|
|
55
|
+
it('should return error for invalid supportedTypes enum', () => {
|
|
56
|
+
const dto = { ...baseValidDto, supportedTypes: ['invalid-type'] };
|
|
57
|
+
const errors = (0, invoice_info_validator_1.validateInvoiceInfoDto)(dto);
|
|
58
|
+
expect(errors.some(e => e.property === 'supportedTypes')).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
it('should return error for empty title', () => {
|
|
61
|
+
const dto = { ...baseValidDto, title: '' };
|
|
62
|
+
const errors = (0, invoice_info_validator_1.validateInvoiceInfoDto)(dto);
|
|
63
|
+
expect(errors.some(e => e.property === 'title')).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
it('should return error for empty supportedLanguages array', () => {
|
|
66
|
+
const dto = { ...baseValidDto, supportedLanguages: [] };
|
|
67
|
+
const errors = (0, invoice_info_validator_1.validateInvoiceInfoDto)(dto);
|
|
68
|
+
expect(errors.some(e => e.property === 'supportedLanguages')).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
it('should return error for invalid language enum', () => {
|
|
71
|
+
const dto = { ...baseValidDto, supportedLanguages: ['INVALID'] };
|
|
72
|
+
const errors = (0, invoice_info_validator_1.validateInvoiceInfoDto)(dto);
|
|
73
|
+
expect(errors.some(e => e.property === 'supportedLanguages')).toBe(true);
|
|
74
|
+
});
|
|
75
|
+
it('should return error for invalid logo URL', () => {
|
|
76
|
+
const dto = { ...baseValidDto, logo: 'not-a-url' };
|
|
77
|
+
const errors = (0, invoice_info_validator_1.validateInvoiceInfoDto)(dto);
|
|
78
|
+
expect(errors.some(e => e.property === 'logo')).toBe(true);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ValidationError } from 'class-validator';
|
|
2
|
+
/**
|
|
3
|
+
* Validates an InvoiceItemDataDto object using class-validator decorators.
|
|
4
|
+
*
|
|
5
|
+
* @param data The object to validate as an InvoiceItemDataDto.
|
|
6
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateInvoiceItemDataDto(data: object): ValidationError[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateInvoiceItemDataDto = validateInvoiceItemDataDto;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const invoice_item_data_dto_1 = require("../dtos/invoice/invoice-item-data.dto");
|
|
7
|
+
/**
|
|
8
|
+
* Validates an InvoiceItemDataDto object using class-validator decorators.
|
|
9
|
+
*
|
|
10
|
+
* @param data The object to validate as an InvoiceItemDataDto.
|
|
11
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
12
|
+
*/
|
|
13
|
+
function validateInvoiceItemDataDto(data) {
|
|
14
|
+
const dto = (0, class_transformer_1.plainToInstance)(invoice_item_data_dto_1.InvoiceItemDataDto, data);
|
|
15
|
+
const errors = (0, class_validator_1.validateSync)(dto);
|
|
16
|
+
return errors;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const invoice_item_data_validator_1 = require("./invoice-item-data-validator");
|
|
5
|
+
const invoice_item_actions_enum_1 = require("../enums/invoice/invoice-item-actions.enum");
|
|
6
|
+
const baseValidDto = {
|
|
7
|
+
productId: 'prod-123',
|
|
8
|
+
productName: 'Web Hosting',
|
|
9
|
+
resourceName: 'hosting-basic',
|
|
10
|
+
productAttributes: { plan: 'basic' },
|
|
11
|
+
itemAttributes: { domain: 'example.com' },
|
|
12
|
+
startDate: '2025-01-01',
|
|
13
|
+
endDate: '2025-12-31',
|
|
14
|
+
action: invoice_item_actions_enum_1.InvoiceItemActionsEnum.CREATE,
|
|
15
|
+
};
|
|
16
|
+
describe('InvoiceItemDataDto Validator', () => {
|
|
17
|
+
describe('Valid cases', () => {
|
|
18
|
+
it('should return no errors for a valid DTO', () => {
|
|
19
|
+
expect((0, invoice_item_data_validator_1.validateInvoiceItemDataDto)(baseValidDto)).toHaveLength(0);
|
|
20
|
+
});
|
|
21
|
+
it.each(Object.values(invoice_item_actions_enum_1.InvoiceItemActionsEnum))('should accept action %s', (action) => {
|
|
22
|
+
const dto = { ...baseValidDto, action };
|
|
23
|
+
expect((0, invoice_item_data_validator_1.validateInvoiceItemDataDto)(dto)).toHaveLength(0);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
describe('Missing required fields', () => {
|
|
27
|
+
it('should return error when action is missing', () => {
|
|
28
|
+
const { action, ...dto } = baseValidDto;
|
|
29
|
+
const errors = (0, invoice_item_data_validator_1.validateInvoiceItemDataDto)(dto);
|
|
30
|
+
expect(errors.some(e => e.property === 'action')).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
it('should return errors for inherited required fields when missing', () => {
|
|
33
|
+
const errors = (0, invoice_item_data_validator_1.validateInvoiceItemDataDto)({});
|
|
34
|
+
expect(errors.some(e => e.property === 'action')).toBe(true);
|
|
35
|
+
expect(errors.some(e => e.property === 'productId')).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('Invalid field values', () => {
|
|
39
|
+
it('should return error for invalid action enum', () => {
|
|
40
|
+
const dto = { ...baseValidDto, action: 'invalid-action' };
|
|
41
|
+
const errors = (0, invoice_item_data_validator_1.validateInvoiceItemDataDto)(dto);
|
|
42
|
+
expect(errors.some(e => e.property === 'action')).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ValidationError } from 'class-validator';
|
|
2
|
+
/**
|
|
3
|
+
* Validates an ItemDataDto object using class-validator decorators.
|
|
4
|
+
*
|
|
5
|
+
* @param data The object to validate as an ItemDataDto.
|
|
6
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateItemDataDto(data: object): ValidationError[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateItemDataDto = validateItemDataDto;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const item_data_dto_1 = require("../dtos/item-data.dto");
|
|
7
|
+
/**
|
|
8
|
+
* Validates an ItemDataDto object using class-validator decorators.
|
|
9
|
+
*
|
|
10
|
+
* @param data The object to validate as an ItemDataDto.
|
|
11
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
12
|
+
*/
|
|
13
|
+
function validateItemDataDto(data) {
|
|
14
|
+
const dto = (0, class_transformer_1.plainToInstance)(item_data_dto_1.ItemDataDto, data);
|
|
15
|
+
const errors = (0, class_validator_1.validateSync)(dto);
|
|
16
|
+
return errors;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|