66
77import dev .matheuscruz .domain .User ;
88import dev .matheuscruz .domain .UserRepository ;
9- import dev .matheuscruz .presentation .data .Problem ;
9+ import dev .matheuscruz .presentation .data .ProblemResponse ;
1010import io .quarkus .narayana .jta .QuarkusTransaction ;
1111import io .quarkus .test .junit .QuarkusTest ;
1212import jakarta .inject .Inject ;
@@ -30,7 +30,7 @@ void setUp() {
3030 @ Test
3131 @ DisplayName ("should return Created when valid SignUpRequest is provided" )
3232 void should_returnCreated_when_validSignUpRequestIsProvided () {
33- var request = new SignUpResource .SignUpRequest ("test@email.com" , "password-1234" , "John" , "Doe" );
33+ var request = new SignUpResource .SignUpRequest ("test@email.com" , "password-1234" , "John" , "Doe" , "+1234567890" );
3434
3535 var response = given ().contentType ("application/json" ).body (request ).when ().post ("/api/sign-up" ).then ().log ()
3636 .ifValidationFails ().statusCode (201 ).extract ().as (SignUpResource .SignUpResponse .class );
@@ -43,16 +43,17 @@ void should_returnCreated_when_validSignUpRequestIsProvided() {
4343 @ DisplayName ("should return Conflict when email already exists" )
4444 void should_returnConflict_when_emailAlreadyExists () {
4545 var existingEmail = "existing.user@email.com" ;
46- var existingUser = User .create (existingEmail , "some-hashed-password" , "Existing" , "User" );
46+ var existingUser = User .create (existingEmail , "some-hashed-password" , "Existing" , "User" , "+0987654321" );
4747
4848 QuarkusTransaction .requiringNew ().run (() -> {
4949 userRepository .persist (existingUser );
5050 });
5151
52- var request = new SignUpResource .SignUpRequest (existingEmail , "a-different-password" , "New" , "Person" );
52+ var request = new SignUpResource .SignUpRequest (existingEmail , "a-different-password" , "New" , "Person" ,
53+ "+0987654321" );
5354
5455 var response = given ().contentType ("application/json" ).body (request ).when ().post ("/api/sign-up" ).then ().log ()
55- .ifValidationFails ().statusCode (409 ).extract ().as (Problem .class );
56+ .ifValidationFails ().statusCode (409 ).extract ().as (ProblemResponse .class );
5657
5758 assertThat (response .message ()).isEqualTo ("Este nome de usuário já foi usado. Tente outro." );
5859 assertThat (userRepository .count ()).isEqualTo (1 );
@@ -62,53 +63,58 @@ void should_returnConflict_when_emailAlreadyExists() {
6263 @ Test
6364 @ DisplayName ("should return Bad Request when email is not valid" )
6465 void should_returnBadRequest_when_emailIsNotValid () {
65- var request = new SignUpResource .SignUpRequest ("invalid-email.com" , "password-1234" , "John" , "Doe" );
66+ var request = new SignUpResource .SignUpRequest ("invalid-email.com" , "password-1234" , "John" , "Doe" ,
67+ "+1234567890" );
6668
67- var validationProblem = given ().contentType ("application/json" ).body (request ).when ().post ("/api/sign-up" ).then ()
68- .log ().ifValidationFails ().statusCode (400 ).extract ().as (ValidationProblem .class );
69+ var validationProblemResponse = given ().contentType ("application/json" ).body (request ).when ()
70+ .post ("/api/sign-up" ).then ().log ().ifValidationFails ().statusCode (400 ).extract ()
71+ .as (ValidationProblemResponse .class );
6972
70- assertThat (validationProblem .title ()).isEqualTo ("Constraint Violation" );
71- assertThat (validationProblem .violations ()).hasSize (1 ).extracting (Violation ::field , Violation ::message )
73+ assertThat (validationProblemResponse .title ()).isEqualTo ("Constraint Violation" );
74+ assertThat (validationProblemResponse .violations ()).hasSize (1 ).extracting (Violation ::field , Violation ::message )
7275 .containsExactly (tuple ("signUp.req.email" , "must be a well-formed email address" ));
7376 }
7477
7578 @ Test
7679 @ DisplayName ("should return Bad Request when password is too short" )
7780 void should_returnBadRequest_when_passwordIsTooShort () {
78- var request = new SignUpResource .SignUpRequest ("test@email.com" , "1234" , "John" , "Doe" );
81+ var request = new SignUpResource .SignUpRequest ("test@email.com" , "1234" , "John" , "Doe" , "+1234567890" );
7982
80- var validationProblem = given ().contentType ("application/json" ).body (request ).when ().post ("/api/sign-up" ).then ()
81- .log ().ifValidationFails ().statusCode (400 ).extract ().as (ValidationProblem .class );
83+ var validationProblemResponse = given ().contentType ("application/json" ).body (request ).when ()
84+ .post ("/api/sign-up" ).then ().log ().ifValidationFails ().statusCode (400 ).extract ()
85+ .as (ValidationProblemResponse .class );
8286
83- assertThat (validationProblem .title ()).isEqualTo ("Constraint Violation" );
84- assertThat (validationProblem .violations ()).hasSize (1 ).extracting (Violation ::field , Violation ::message )
87+ assertThat (validationProblemResponse .title ()).isEqualTo ("Constraint Violation" );
88+ assertThat (validationProblemResponse .violations ()).hasSize (1 ).extracting (Violation ::field , Violation ::message )
8589 .containsExactly (tuple ("signUp.req.password" , "size must be between 8 and 32" ));
8690 }
8791
8892 @ Test
8993 @ DisplayName ("should return Bad Request when password is too long" )
9094 void should_returnBadRequest_when_passwordIsTooLong () {
9195 var request = new SignUpResource .SignUpRequest ("test@email.com" , "12345678910111213141516171819202122" , "John" ,
92- "Doe" );
96+ "Doe" , "+1234567890" );
9397
94- var validationProblem = given ().contentType ("application/json" ).body (request ).when ().post ("/api/sign-up" ).then ()
95- .log ().ifValidationFails ().statusCode (400 ).extract ().as (ValidationProblem .class );
98+ var validationProblemResponse = given ().contentType ("application/json" ).body (request ).when ()
99+ .post ("/api/sign-up" ).then ().log ().ifValidationFails ().statusCode (400 ).extract ()
100+ .as (ValidationProblemResponse .class );
96101
97- assertThat (validationProblem .title ()).isEqualTo ("Constraint Violation" );
98- assertThat (validationProblem .violations ()).hasSize (1 ).extracting (Violation ::field , Violation ::message )
102+ assertThat (validationProblemResponse .title ()).isEqualTo ("Constraint Violation" );
103+ assertThat (validationProblemResponse .violations ()).hasSize (1 ).extracting (Violation ::field , Violation ::message )
99104 .containsExactly (tuple ("signUp.req.password" , "size must be between 8 and 32" ));
100105 }
101106
102107 @ Test
103108 @ DisplayName ("should return Bad Request when password is blank" )
104109 void should_returnBadRequest_when_passwordIsBlank () {
105- var request = new SignUpResource .SignUpRequest ("test@email.com" , "" , "John" , "Doe" );
110+ var request = new SignUpResource .SignUpRequest ("test@email.com" , "" , "John" , "Doe" , "+1234567890" );
106111
107- var validationProblem = given ().contentType ("application/json" ).body (request ).when ().post ("/api/sign-up" ).then ()
108- .log ().ifValidationFails ().statusCode (400 ).extract ().as (ValidationProblem .class );
112+ var validationProblemResponse = given ().contentType ("application/json" ).body (request ).when ()
113+ .post ("/api/sign-up" ).then ().log ().ifValidationFails ().statusCode (400 ).extract ()
114+ .as (ValidationProblemResponse .class );
109115
110- assertThat (validationProblem .title ()).isEqualTo ("Constraint Violation" );
111- assertThat (validationProblem .violations ()).hasSize (2 ).extracting (Violation ::field , Violation ::message )
116+ assertThat (validationProblemResponse .title ()).isEqualTo ("Constraint Violation" );
117+ assertThat (validationProblemResponse .violations ()).hasSize (2 ).extracting (Violation ::field , Violation ::message )
112118 .containsExactlyInAnyOrder (tuple ("signUp.req.password" , "size must be between 8 and 32" ),
113119 tuple ("signUp.req.password" , "must not be blank" )
114120
@@ -118,45 +124,61 @@ void should_returnBadRequest_when_passwordIsBlank() {
118124 @ Test
119125 @ DisplayName ("should return Bad Request when first name is blank" )
120126 void should_returnBadRequest_when_firstNameIsBlank () {
121- var request = new SignUpResource .SignUpRequest ("test@email.com" , "password-1234" , "" , "Doe" );
127+ var request = new SignUpResource .SignUpRequest ("test@email.com" , "password-1234" , "" , "Doe" , "+1234567890" );
122128
123- var validationProblem = given ().contentType ("application/json" ).body (request ).when ().post ("/api/sign-up" ).then ()
124- .log ().ifValidationFails ().statusCode (400 ).extract ().as (ValidationProblem .class );
129+ var validationProblemResponse = given ().contentType ("application/json" ).body (request ).when ()
130+ .post ("/api/sign-up" ).then ().log ().ifValidationFails ().statusCode (400 ).extract ()
131+ .as (ValidationProblemResponse .class );
125132
126- assertThat (validationProblem .title ()).isEqualTo ("Constraint Violation" );
127- assertThat (validationProblem .violations ()).hasSize (1 ).extracting (Violation ::field , Violation ::message )
133+ assertThat (validationProblemResponse .title ()).isEqualTo ("Constraint Violation" );
134+ assertThat (validationProblemResponse .violations ()).hasSize (1 ).extracting (Violation ::field , Violation ::message )
128135 .containsExactly (tuple ("signUp.req.firstName" , "must not be blank" ));
129136 }
130137
131138 @ Test
132139 @ DisplayName ("should return Bad Request when last name is blank" )
133140 void should_returnBadRequest_when_lastNameIsBlank () {
134- var request = new SignUpResource .SignUpRequest ("test@email.com" , "password-1234" , "John" , "" );
141+ var request = new SignUpResource .SignUpRequest ("test@email.com" , "password-1234" , "John" , "" , "+1234567890" );
135142
136- var validationProblem = given ().contentType ("application/json" ).body (request ).when ().post ("/api/sign-up" ).then ()
137- .log ().ifValidationFails ().statusCode (400 ).extract ().as (ValidationProblem .class );
143+ var validationProblemResponse = given ().contentType ("application/json" ).body (request ).when ()
144+ .post ("/api/sign-up" ).then ().log ().ifValidationFails ().statusCode (400 ).extract ()
145+ .as (ValidationProblemResponse .class );
138146
139- assertThat (validationProblem .title ()).isEqualTo ("Constraint Violation" );
140- assertThat (validationProblem .violations ()).hasSize (1 ).extracting (Violation ::field , Violation ::message )
147+ assertThat (validationProblemResponse .title ()).isEqualTo ("Constraint Violation" );
148+ assertThat (validationProblemResponse .violations ()).hasSize (1 ).extracting (Violation ::field , Violation ::message )
141149 .containsExactly (tuple ("signUp.req.lastName" , "must not be blank" ));
142150 }
143151
144152 @ Test
145153 @ DisplayName ("should return Bad Request when e-mail is blank" )
146154 void should_returnBadRequest_when_emailIsBlank () {
147- var request = new SignUpResource .SignUpRequest ("" , "password-1234" , "John" , "Doe" );
155+ var request = new SignUpResource .SignUpRequest ("" , "password-1234" , "John" , "Doe" , "+1234567890" );
148156
149- var problem = given ().contentType ("application/json" ).body (request ).when ().post ("/api/sign-up" ).then (). log ()
150- .ifValidationFails ().statusCode (400 ).extract ().as (ValidationProblem .class );
157+ var ProblemResponse = given ().contentType ("application/json" ).body (request ).when ().post ("/api/sign-up" ).then ()
158+ .log (). ifValidationFails ().statusCode (400 ).extract ().as (ValidationProblemResponse .class );
151159
152- assertThat (problem .title ()).isEqualTo ("Constraint Violation" );
153- assertThat (problem .violations ()).hasSize (1 ).extracting (Violation ::field , Violation ::message )
160+ assertThat (ProblemResponse .title ()).isEqualTo ("Constraint Violation" );
161+ assertThat (ProblemResponse .violations ()).hasSize (1 ).extracting (Violation ::field , Violation ::message )
154162 .containsExactlyInAnyOrder (tuple ("signUp.req.email" , "must not be blank" ));
155163 }
156164
165+ @ Test
166+ @ DisplayName ("should return Bad Request when phone number is blank" )
167+ void should_returnBadRequest_when_phoneNumberIsBlank () {
168+ var request = new SignUpResource .SignUpRequest ("test@email.com" , "password-1234" , "John" , "Doe" , "" );
169+
170+ var validationProblemResponse = given ().contentType ("application/json" ).body (request ).when ()
171+ .post ("/api/sign-up" ).then ().log ().ifValidationFails ().statusCode (400 ).extract ()
172+ .as (ValidationProblemResponse .class );
173+
174+ assertThat (validationProblemResponse .title ()).isEqualTo ("Constraint Violation" );
175+ assertThat (validationProblemResponse .violations ()).hasSize (1 ).extracting (Violation ::field , Violation ::message )
176+ .containsExactly (tuple ("signUp.req.phoneNumber" , "must not be blank" ));
177+ }
178+
157179 public record Violation (String field , String message ) {
158180 }
159181
160- public record ValidationProblem (String title , int status , java .util .List <Violation > violations ) {
182+ public record ValidationProblemResponse (String title , int status , java .util .List <Violation > violations ) {
161183 }
162184}
0 commit comments