Skip to content

Commit

Permalink
feat: postPatron method and test
Browse files Browse the repository at this point in the history
  • Loading branch information
VicenteVigueras committed Apr 11, 2024
1 parent 04a2882 commit 484d8e8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ public ResponseEntity<PatronsResponse> getPatronbyId(@PathVariable UUID id) {
}

@PostMapping("/patrons")
public CreatePatronsResponse postItem(@Valid @RequestBody CreatePatronsRequest request) {
public CreatePatronsResponse postPatron(@Valid @RequestBody CreatePatronsRequest request) {
LibraryGuest patron = PatronsRequest.asLibraryGuest(request.getPatron());
library.addLibraryGuest(patron);
return CreatePatronsResponse.builder().patron(PatronsResponse.from(patron)).build();
}

// @PostMapping
// @DeleteMapping("/{id}")
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void testController_getsAllPatrons() throws Exception {
.perform(get("/patrons").contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.patrons").isArray())
.andExpect(jsonPath("$.patrons.length()").value(5));
.andExpect(jsonPath("$.patrons.length()").value(6));
}

@Test
Expand All @@ -46,29 +46,22 @@ void testController_getsPatron() throws Exception {
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
}
}
// @Test
// void testController_addsItem() throws Exception {
// String json =
// """
// {
// "patron": {
// "type": "patron",
// "name": "someone",
// "email": "vicente@example.com"
// }
// }
// """;

// mockMvc
// .perform(post("/patrons").contentType(MediaType.APPLICATION_JSON).content(json))
// .andExpect(status().isOk())
// .andExpect(jsonPath("$.patron.email").value("vicente@example.com"));
@Test
void testController_addsPatron() throws Exception {
String json =
"""
{
"patron": {
"name": "vicente",
"email": "vicente@example.com"
}
}
""";

// Set<LibraryGuest> patrons =
// library.getPatrons();
// assertThat(patrons).hasSize(1);
// var patron = patrons.iterator().next();
// assertThat(patron.getEmail()).isEqualTo("vicente@example.com");
// }
// }
mockMvc
.perform(post("/patrons").contentType(MediaType.APPLICATION_JSON).content(json))
.andExpect(status().isOk())
.andExpect(jsonPath("$.patron.name").value("vicente"));
}
}

0 comments on commit 484d8e8

Please sign in to comment.