-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
4 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
package sergi.example.api; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.RequiredArgsConstructor; | ||
import net.datafaker.Faker; | ||
import org.instancio.Instancio; | ||
import org.instancio.Select; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.openapitools.jackson.nullable.JsonNullable; | ||
|
@@ -16,6 +12,7 @@ | |
import sergi.example.user.User; | ||
import sergi.example.user.dal.UserRepository; | ||
import sergi.example.user.dto.UserCreateDTO; | ||
import utils.InitData; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
@@ -33,29 +30,18 @@ class UserControllerTest { | |
private MockMvc mockMvc; | ||
|
||
@Autowired | ||
private Faker faker; | ||
private InitData init; | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@Autowired | ||
private ObjectMapper mapper; | ||
|
||
private User generateUser() { | ||
return Instancio.of(User.class) | ||
.ignore(Select.field(User::getId)) | ||
.ignore(Select.field(User::getCreatedAt)) | ||
.ignore(Select.field(User::getUpdatedAt)) | ||
.ignore(Select.field(User::getTasks)) | ||
.supply(Select.field(User::getName), () -> faker.name().name()) | ||
.supply(Select.field(User::getEmail), () -> faker.internet().emailAddress()) | ||
.create(); | ||
} | ||
|
||
@Test | ||
@Order(1) | ||
void testCreate() throws Exception { | ||
User user = generateUser(); | ||
User user = init.user(); | ||
UserCreateDTO dto = new UserCreateDTO(); | ||
dto.setEmail(user.getEmail()); | ||
dto.setName(JsonNullable.of(user.getName())); | ||
|
@@ -77,7 +63,7 @@ void testCreate() throws Exception { | |
@Test | ||
@Order(2) | ||
void testUpdate() throws Exception { | ||
User user = generateUser(); | ||
User user = init.user(); | ||
userRepository.save(user); | ||
|
||
Map<String, String> data = Map.of("email", "[email protected]", "name", "John Doe"); | ||
|