Skip to content

Commit cd6dba1

Browse files
committed
fix: ensure tests from pull request
fix #222
1 parent 208368a commit cd6dba1

File tree

9 files changed

+114
-84
lines changed

9 files changed

+114
-84
lines changed

CHANGELOG.md

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

55
## Unreleased
66

7+
8+
---
9+
10+
### [3.5.2] - 2023-02-18
11+
12+
### Changed
13+
14+
- validation to `url.value-object` use URL default validation and remove regex. by @ArturHamannRonconi
15+
16+
### Added
17+
18+
- added separator as optional param to `getInitials`method from `user-name.value-object`
19+
720
---
821
### [3.5.1] - 2023-01-27
922

lib/utils/cpf.value-object.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { ValueObject } from '../core';
22
import { Result } from '../core';
3-
import isValidCpfDigit, {
4-
formatValueToCpfPattern,
5-
removeSpecialCharsFromCpf,
6-
} from './check-cpf-digit.util';
3+
import isValidCpfDigit from './check-cpf-digit.util';
4+
import { formatValueToCpfPattern } from './check-cpf-digit.util';
75
const regexCpf =
86
/^([0-9]{3})[\.]((?!\1)[0-9]{3})[\.]([0-9]{3})[-]([0-9]{2})$|^[0-9]{11}$/;
97

@@ -36,11 +34,9 @@ export class CPFValueObject extends ValueObject<Prop> {
3634
* @example after "52734865211"
3735
*/
3836
removeSpecialChars(): CPFValueObject {
39-
this.props.value = removeSpecialCharsFromCpf(this.props.value);
40-
41-
// this.props.value = this.util
42-
// .string(this.props.value)
43-
// .removeSpecialChars();
37+
this.props.value = this.util
38+
.string(this.props.value)
39+
.removeSpecialChars();
4440
return this;
4541
}
4642

@@ -62,13 +58,10 @@ export class CPFValueObject extends ValueObject<Prop> {
6258
* @example param "527.348.652-11"
6359
*/
6460
compare(cpf: string): boolean {
65-
// const formattedCpf = this.util.string(cpf).removeSpecialChars();
66-
// const instanceValue = this.util
67-
// .string(this.props.value)
68-
// .removeSpecialChars();
69-
70-
const formattedCpf = removeSpecialCharsFromCpf(cpf);
71-
const instanceValue = removeSpecialCharsFromCpf(this.props.value);
61+
const formattedCpf = this.util.string(cpf).removeSpecialChars();
62+
const instanceValue = this.util
63+
.string(this.props.value)
64+
.removeSpecialChars();
7265
return instanceValue === formattedCpf;
7366
}
7467

lib/utils/password.value-object.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ class PasswordValueObject extends ValueObject<Prop> {
9797
public static isValidProps(value: string): boolean {
9898
const { string } = this.validator;
9999
if (!PasswordValueObject.isEncrypted(value)) {
100-
const passwordHasRequiredLength = string(value).hasLengthBetween(
100+
const passwordHasRequiredLength = string(
101+
value
102+
).hasLengthBetweenOrEqual(
101103
PasswordValueObject.MIN_LENGTH,
102104
PasswordValueObject.MAX_LENGTH
103105
);
@@ -106,7 +108,7 @@ class PasswordValueObject extends ValueObject<Prop> {
106108
return true;
107109
}
108110

109-
isEqual(password: PasswordValueObject) {
111+
isEqual(password: PasswordValueObject): boolean {
110112
return this.compare(password.value());
111113
}
112114

lib/utils/url.value-object.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { ValueObject } from '../core';
22
import { Result } from '../core';
3-
const regexHash =
4-
/^(https?:\/\/)(([\da-z\.-]+))?\.?([a-z\.]{2,6})([\/\w \.-]*)*\/?(:\d{2,4})?(\/\w+)?$/;
53

64
interface Prop {
75
value: string;
86
}
97

108
class UrlValueObject extends ValueObject<Prop> {
11-
protected static readonly REGEX = regexHash;
129
protected static readonly DISABLE_SETTER: boolean = true;
1310
protected static readonly MESSAGE: string = 'Invalid url value';
1411

@@ -38,6 +35,10 @@ class UrlValueObject extends ValueObject<Prop> {
3835
}
3936
}
4037

38+
public URL(): URL {
39+
return new URL(this.props.value);
40+
}
41+
4142
validation(value: string): boolean {
4243
return UrlValueObject.isValidProps(value);
4344
}

lib/utils/user-name.value-object.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class UserNameValueObject extends ValueObject<Prop> {
2828
* @returns instance
2929
*/
3030
private capitalize(): UserNameValueObject {
31-
const names = this.props.value.split(' ').filter((name) => {
31+
const names = this.props.value.split(' ').filter((name): boolean => {
3232
return name.length > 1;
3333
});
3434

@@ -39,12 +39,10 @@ export class UserNameValueObject extends ValueObject<Prop> {
3939
capitalized.push(lowerCaseName);
4040
}
4141

42-
// const value = this.util
43-
// .string(capitalized.toString())
44-
// .replace(',')
45-
// .to(' ');
46-
47-
const value = capitalized.toString().replace(/,/g, ' ');
42+
const value = this.util
43+
.string(capitalized.toString())
44+
.replace(',')
45+
.to(' ');
4846

4947
this.props.value = value;
5048
return this;
@@ -96,19 +94,17 @@ export class UserNameValueObject extends ValueObject<Prop> {
9694

9795
/**
9896
* @returns initials as string
97+
* @param separator as string char to separate letters
98+
* @default separator . (dot)
9999
* @example
100100
* for a name "Thomas A. Anderson" = "T.A.A"
101101
*/
102-
getInitials(): string {
102+
getInitials(separator = '.'): string {
103103
const names = this.props.value.split(' ');
104104
const letters = names.map((name) => name[0]);
105+
const value = this.util.string(letters.toString());
105106

106-
// const initials = this.
107-
// .string(letters.toString())
108-
// .replace(',')
109-
// .to('.');
110-
111-
const initials = letters.toString().replace(/,/g, '.');
107+
const initials = value.replace(',').to(separator);
112108

113109
return initials;
114110
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"dependencies": {
6161
"bcrypt": "^5.0.1",
6262
"pino": "^8.8.0",
63-
"pino-pretty": "^9.1.1",
63+
"pino-pretty": "^9.3.0",
6464
"rich-domain": "^1.17.1"
6565
},
6666
"devDependencies": {

tests/utils/password.value-object.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ describe('password.value-object', () => {
7676

7777
it('should password to be equal', () => {
7878
const passA = PasswordValueObject.create('123456abc!').value();
79-
const passB = PasswordValueObject.create('123456abc!').value();
79+
/** @todo: fix inference type on clone to get instance type */
80+
const passB = passA.clone() as PasswordValueObject;
8081
const isEqual = passA.isEqual(passB);
8182
expect(isEqual).toBe(true);
8283
});

tests/utils/user-name-value-object.util.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,20 @@ describe('user-name.value-object', () => {
117117
expect(username.getInitials()).toBe('F.M.L');
118118
});
119119

120+
it('should get initials with custom separator', () => {
121+
const separator = '-';
122+
const username =
123+
UserNameValueObject.create('FIRST MIDDLE LAST').value();
124+
expect(username.getInitials(separator)).toBe('F-M-L');
125+
});
126+
127+
it('should get initials with none separator', () => {
128+
const separator = '';
129+
const username =
130+
UserNameValueObject.create('FIRST MIDDLE LAST').value();
131+
expect(username.getInitials(separator)).toBe('FML');
132+
});
133+
120134
it('should get initials', () => {
121135
const username = UserNameValueObject.create('FIRSt').value();
122136
expect(username.getInitials()).toBe('F');

0 commit comments

Comments
 (0)