Skip to content

Commit 3341442

Browse files
committed
Fix Report Tests
1 parent a81abc1 commit 3341442

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

src/test/java/cat/udl/eps/softarch/demo/steps/ReportRepositoryStepsDefs.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import cat.udl.eps.softarch.demo.repository.ContentRepository;
1818
import cat.udl.eps.softarch.demo.repository.ReportRepository;
19-
19+
import io.cucumber.core.internal.com.fasterxml.jackson.databind.node.ObjectNode;
2020
import io.cucumber.java.ParameterType;
2121
import io.cucumber.java.en.Given;
2222
import io.cucumber.java.en.Then;
@@ -62,21 +62,24 @@ public void iCreateAReportWithTheLastCreatedContent(String reason) throws Except
6262
.reduce((first, second) -> second)
6363
.orElseThrow(() -> new RuntimeException("No contents found"));
6464

65-
Report report = new Report();
66-
report.setContent(content);
67-
report.setReason(reason);
68-
report.setCreatedAt(ZonedDateTime.now());
65+
String contentUri = "/contents/" + content.getContentId();
6966

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);
7971

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
8083
String location = stepDefs.result.andReturn().getResponse().getHeader("Location");
8184
createdReportId = Long.valueOf(location.substring(location.lastIndexOf("/") + 1));
8285
}

0 commit comments

Comments
 (0)