|
16 | 16 |
|
17 | 17 | import cat.udl.eps.softarch.demo.repository.ContentRepository; |
18 | 18 | import cat.udl.eps.softarch.demo.repository.ReportRepository; |
19 | | - |
| 19 | +import io.cucumber.core.internal.com.fasterxml.jackson.databind.node.ObjectNode; |
20 | 20 | import io.cucumber.java.ParameterType; |
21 | 21 | import io.cucumber.java.en.Given; |
22 | 22 | import io.cucumber.java.en.Then; |
@@ -62,21 +62,24 @@ public void iCreateAReportWithTheLastCreatedContent(String reason) throws Except |
62 | 62 | .reduce((first, second) -> second) |
63 | 63 | .orElseThrow(() -> new RuntimeException("No contents found")); |
64 | 64 |
|
65 | | - Report report = new Report(); |
66 | | - report.setContent(content); |
67 | | - report.setReason(reason); |
68 | | - report.setCreatedAt(ZonedDateTime.now()); |
| 65 | + String contentUri = "/contents/" + content.getContentId(); |
69 | 66 |
|
70 | | - stepDefs.result = stepDefs.mockMvc.perform( |
71 | | - post("/reports") |
72 | | - .contentType(MediaType.APPLICATION_JSON) |
73 | | - .content(stepDefs.mapper.writeValueAsString(report)) |
74 | | - .characterEncoding(StandardCharsets.UTF_8) |
75 | | - .accept(MediaType.APPLICATION_JSON) |
76 | | - .with(AuthenticationStepDefs.authenticate())) |
77 | | - .andDo(print()) |
78 | | - .andExpect(status().isCreated()); |
| 67 | + com.fasterxml.jackson.databind.node.ObjectNode json = stepDefs.mapper.createObjectNode(); |
| 68 | + json.put("reason", reason); |
| 69 | + json.put("createdAt", ZonedDateTime.now().toString()); |
| 70 | + json.put("content", contentUri); |
79 | 71 |
|
| 72 | + stepDefs.result = stepDefs.mockMvc.perform( |
| 73 | + post("/reports") |
| 74 | + .contentType(MediaType.APPLICATION_JSON) |
| 75 | + .content(json.toString()) |
| 76 | + .characterEncoding(StandardCharsets.UTF_8) |
| 77 | + .accept(MediaType.APPLICATION_JSON) |
| 78 | + .with(AuthenticationStepDefs.authenticate())) |
| 79 | + .andDo(print()) |
| 80 | + .andExpect(status().isCreated()); |
| 81 | + |
| 82 | + // Leer el ID real desde el header Location |
80 | 83 | String location = stepDefs.result.andReturn().getResponse().getHeader("Location"); |
81 | 84 | createdReportId = Long.valueOf(location.substring(location.lastIndexOf("/") + 1)); |
82 | 85 | } |
|
0 commit comments