-
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
2 changed files
with
37 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[![Actions Status](https://github.com/sergi-Jr/time-tracker/actions/workflows/main.yml/badge.svg)](https://github.com/sergi-Jr/time-tracker/actions) | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/12b45cc1b263ef3160bf/maintainability)](https://codeclimate.com/github/sergi-Jr/time-tracker/maintainability) | ||
[![Test Coverage](https://api.codeclimate.com/v1/badges/12b45cc1b263ef3160bf/test_coverage)](https://codeclimate.com/github/sergi-Jr/time-tracker/test_coverage) |
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 |
---|---|---|
|
@@ -9,14 +9,20 @@ | |
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import sergi.example.task.Task; | ||
import sergi.example.task.dal.TaskRepository; | ||
import sergi.example.user.User; | ||
import sergi.example.user.dal.UserRepository; | ||
import sergi.example.user.dto.UserCreateDTO; | ||
import utils.InitData; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
@@ -38,6 +44,9 @@ class UserControllerTest { | |
@Autowired | ||
private ObjectMapper mapper; | ||
|
||
@Autowired | ||
private TaskRepository taskRepository; | ||
|
||
@Test | ||
@Order(1) | ||
void testCreate() throws Exception { | ||
|
@@ -46,7 +55,7 @@ void testCreate() throws Exception { | |
dto.setEmail(user.getEmail()); | ||
dto.setName(JsonNullable.of(user.getName())); | ||
|
||
var request = post("/users") | ||
var request = post("/v1/users") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(mapper.writeValueAsString(dto)); | ||
mockMvc.perform(request) | ||
|
@@ -68,7 +77,7 @@ void testUpdate() throws Exception { | |
|
||
Map<String, String> data = Map.of("email", "[email protected]", "name", "John Doe"); | ||
|
||
var request = put("/users/" + user.getId()) | ||
var request = put("/v1/users/" + user.getId()) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(mapper.writeValueAsString(data)); | ||
mockMvc.perform(request) | ||
|
@@ -82,4 +91,27 @@ void testUpdate() throws Exception { | |
.containsEntry("email", actual.getEmail()) | ||
.containsEntry("name", actual.getName()); | ||
} | ||
|
||
@Test | ||
@Order(3) | ||
@Transactional | ||
void testShowUserTrack() throws Exception { | ||
User user = init.user(); | ||
Task task = init.task(); | ||
task.setStartedAt(LocalDateTime.parse("2024-10-10T11:53:32")); | ||
task.setFinishedAt(LocalDateTime.parse("2024-10-10T16:53:32")); | ||
taskRepository.save(task); | ||
user.addTask(task); | ||
userRepository.save(user); | ||
|
||
var request = get("/v1/users/" + user.getEmail()) | ||
.param("start-period", "2024-10-10") | ||
.param("end-period", "2024-10-10"); | ||
var result = mockMvc.perform(request) | ||
.andExpect(status().isOk()) | ||
.andReturn(); | ||
|
||
String body = result.getResponse().getContentAsString(); | ||
assertThatJson(body).isArray(); | ||
} | ||
} |