6
6
import org .junit .jupiter .api .DisplayName ;
7
7
import org .junit .jupiter .api .Test ;
8
8
import org .junit .jupiter .params .ParameterizedTest ;
9
+ import org .junit .jupiter .params .provider .CsvSource ;
9
10
import org .junit .jupiter .params .provider .NullAndEmptySource ;
10
11
import org .junit .jupiter .params .provider .ValueSource ;
11
12
import org .springframework .beans .factory .annotation .Autowired ;
@@ -43,8 +44,8 @@ void return400_createWithoutFirstName(String emptyFirstName) throws Exception {
43
44
var request = new CreateManager (
44
45
emptyFirstName ,
45
46
"lastName" ,
46
- "12312312311" ,
47
47
"manager@email.com" ,
48
+ "12312312311" ,
48
49
"11999999999" ,
49
50
"admin@email.com"
50
51
);
@@ -68,8 +69,8 @@ void return400_createWithoutLastName(String emptyLastName) throws Exception {
68
69
var request = new CreateManager (
69
70
"firstName" ,
70
71
emptyLastName ,
71
- "12312312311" ,
72
72
"manager@email.com" ,
73
+ "12312312311" ,
73
74
"11999999999" ,
74
75
"admin@email.com"
75
76
);
@@ -94,8 +95,8 @@ void return400_createWithInvalidCpf(String invalidCpf) throws Exception {
94
95
var request = new CreateManager (
95
96
"firstName" ,
96
97
"lastName" ,
97
- invalidCpf ,
98
98
"manager@email.com" ,
99
+ invalidCpf ,
99
100
"11999999999" ,
100
101
"admin@email.com"
101
102
);
@@ -120,8 +121,8 @@ void return400_createWithInvalidEmail(String invalidEmail) throws Exception {
120
121
var request = new CreateManager (
121
122
"firstName" ,
122
123
"lastName" ,
123
- "12345678901" ,
124
124
invalidEmail ,
125
+ "12345678901" ,
125
126
"11999999999" ,
126
127
"admin@email.com"
127
128
);
@@ -146,8 +147,8 @@ void return400_createWithInvalidPhone(String invalidPhone) throws Exception {
146
147
var request = new CreateManager (
147
148
"firstName" ,
148
149
"lastName" ,
149
- "12345678901" ,
150
150
"manager@email.com" ,
151
+ "12345678901" ,
151
152
invalidPhone ,
152
153
"admin@email.com"
153
154
);
@@ -164,14 +165,56 @@ void return400_createWithInvalidPhone(String invalidPhone) throws Exception {
164
165
assertEquals (0 , this .repository .count ());
165
166
}
166
167
168
+ @ ParameterizedTest
169
+ @ CsvSource (value = {
170
+ "manager@email.com,12312312311,manager@email.com,12312312311" ,
171
+ "manager@email.com,12312312311,manager@email.com,99999999999" ,
172
+ "manager@email.com,12312312311,different@email.com,12312312311" ,
173
+ })
174
+ @ DisplayName ("should not create a duplicate manager" )
175
+ void return409_createDuplicate (String createEmail ,
176
+ String createCpf ,
177
+ String email ,
178
+ String cpf ) throws Exception {
179
+ var request = new CreateManager (
180
+ "firstName" ,
181
+ "lastName" ,
182
+ createEmail ,
183
+ createCpf ,
184
+ "12345678901" ,
185
+ "admin@email.com"
186
+ );
187
+ var json = objectMapper .writeValueAsString (request );
188
+
189
+ var saved = new CreateManager (
190
+ "anotherName" ,
191
+ "anotherLast" ,
192
+ email ,
193
+ cpf ,
194
+ "12345678901" ,
195
+ "admin@email.com"
196
+ );
197
+ this .repository .save (new Manager (saved ));
198
+
199
+ this .mockMvc
200
+ .perform (post (URL )
201
+ .content (json )
202
+ .contentType (MediaType .APPLICATION_JSON )
203
+ )
204
+ .andDo (print ())
205
+ .andExpect (status ().isConflict ());
206
+
207
+ assertEquals (1 , this .repository .count ());
208
+ }
209
+
167
210
@ Test
168
211
@ DisplayName ("should create a new manager successfully" )
169
212
void return201_createSuccessfully () throws Exception {
170
213
var request = new CreateManager (
171
214
"firstName" ,
172
215
"lastName" ,
173
- "12312312311" ,
174
216
"manager@email.com" ,
217
+ "12312312311" ,
175
218
"12345678901" ,
176
219
"admin@email.com"
177
220
);
0 commit comments