Skip to content

Commit 36df6ab

Browse files
committed
feat(utils): added custom message to email
1 parent 25bff5d commit 36df6ab

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7+
### 3.4.4 - 2023-01-12
8+
9+
### Added
10+
11+
- custom-string.value-object: By: [VinnyLima](https://github.com/VinnyLima)
12+
- removeSpecialChars and onlyNumbers: [Issue 223](https://github.com/4lessandrodev/types-ddd/issues/223)
13+
- email.value-object: added MESSAGE as customizable value
14+
15+
---
16+
717
### 3.4.3 - 2023-01-05
818

919
### Updated

lib/utils/email.value-object.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export class EmailValueObject extends ValueObject<Prop> {
1010
protected static readonly DISABLE_SETTER: boolean = true;
1111
protected static readonly BLOCKED_DOMAINS: Array<string> = [];
1212
protected static readonly VALID_DOMAINS: Array<string> = [];
13+
protected static readonly MESSAGE: string = 'Invalid email';
1314

1415
private constructor(props: Prop) {
1516
super(props, { disableSetters: EmailValueObject.DISABLE_SETTER });
@@ -67,7 +68,7 @@ export class EmailValueObject extends ValueObject<Prop> {
6768

6869
public static create(value: string): Result<EmailValueObject> {
6970
if (!EmailValueObject.isValidProps(value)) {
70-
return Result.fail('Invalid email');
71+
return Result.fail(EmailValueObject.MESSAGE);
7172
}
7273
return Result.Ok(new EmailValueObject({ value }));
7374
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "types-ddd",
3-
"version": "3.4.3",
3+
"version": "3.4.4",
44
"description": "This package provide utils file and interfaces to assistant build a complex application with domain driving design",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

tests/utils/email-value-object.util.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,12 @@ describe('email-blocked-list', () => {
207207
expect(result1.isFail()).toBeTruthy();
208208
expect(result2.isOk()).toBeTruthy();
209209
});
210+
211+
it('should fail with custom message', () => {
212+
Reflect.set(EmailValueObject, 'MESSAGE', 'Valor inválido para email');
213+
const result = EmailValueObject.create('invalid');
214+
215+
expect(result.isFail()).toBeTruthy();
216+
expect(result.error()).toBe('Valor inválido para email');
217+
});
210218
});

0 commit comments

Comments
 (0)