Public Access
chore(library)!: drop the full-replace PUT of a backlog entry
The Frontend sends PATCH since item 27 batch 2.
This commit is contained in:
1 parent
34d64e7215
commit
23bf5c41b4
5 files changed
+6
-100
No files matched your search
@@ -60,88 +60,23 @@ class LibraryControllerBacklogTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateBacklog_StoresAllFields() throws Exception {
|
||||
mockMvc.perform(put("/api/library/games/220/backlog").header(ClientHeaderFilter.CLIENT_HEADER, "test").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"status\":\"FINISHED\",\"rating\":4,\"notes\":\"Great ending\",\"priority\":\"HIGH\"}"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.status").value("FINISHED"))
|
||||
.andExpect(jsonPath("$.rating").value(4));
|
||||
|
||||
UserGame game = stored();
|
||||
assertEquals(GameStatus.FINISHED, game.getStatus());
|
||||
assertEquals(4, game.getRating());
|
||||
assertEquals("Great ending", game.getNotes());
|
||||
assertEquals("HIGH", game.getPriority().name());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateBacklog_NullsClearOptionalFieldsAndBlankNotesAreNull() throws Exception {
|
||||
UserGame game = stored();
|
||||
game.setRating(5);
|
||||
game.setNotes("old");
|
||||
userGameRepository.save(game);
|
||||
|
||||
mockMvc.perform(put("/api/library/games/220/backlog").header(ClientHeaderFilter.CLIENT_HEADER, "test").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"status\":\"DROPPED\",\"notes\":\" \"}"))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
game = stored();
|
||||
assertEquals(GameStatus.DROPPED, game.getStatus());
|
||||
assertNull(game.getRating());
|
||||
assertNull(game.getNotes());
|
||||
assertNull(game.getPriority());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"{}",
|
||||
"{\"status\":\"WISHLIST\"}",
|
||||
"{\"status\":\"PLAYING\",\"rating\":0}",
|
||||
"{\"status\":\"PLAYING\",\"rating\":6}",
|
||||
"{\"status\":\"PLAYING\",\"priority\":\"URGENT\"}"})
|
||||
void updateBacklog_InvalidBody_Is400AndStoresNothing(String body) throws Exception {
|
||||
mockMvc.perform(put("/api/library/games/220/backlog").header(ClientHeaderFilter.CLIENT_HEADER, "test").contentType(MediaType.APPLICATION_JSON).content(body))
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
assertEquals(GameStatus.BACKLOG, stored().getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateBacklog_FractionalRating_Is400() throws Exception {
|
||||
mockMvc.perform(put("/api/library/games/220/backlog").header(ClientHeaderFilter.CLIENT_HEADER, "test").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"status\":\"PLAYING\",\"rating\":4.7}"))
|
||||
.andExpect(status().isBadRequest());
|
||||
void patchBacklog_FractionalRating_Is400() throws Exception {
|
||||
patchBacklog(APPID, "{\"rating\":4.7}").andExpect(status().isBadRequest());
|
||||
|
||||
assertNull(stored().getRating());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateBacklog_NotesTooLong_Is400() throws Exception {
|
||||
String notes = "x".repeat(2001);
|
||||
mockMvc.perform(put("/api/library/games/220/backlog").header(ClientHeaderFilter.CLIENT_HEADER, "test").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"status\":\"PLAYING\",\"notes\":\"" + notes + "\"}"))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateBacklog_RemovedGame_Is404() throws Exception {
|
||||
void patchBacklog_RemovedGame_Is404() throws Exception {
|
||||
UserGame game = stored();
|
||||
game.setRemovedAt(Instant.now());
|
||||
userGameRepository.save(game);
|
||||
|
||||
mockMvc.perform(put("/api/library/games/220/backlog").header(ClientHeaderFilter.CLIENT_HEADER, "test").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"status\":\"PLAYING\"}"))
|
||||
patchBacklog(APPID, "{\"notes\":\"x\"}")
|
||||
.andExpect(status().isNotFound())
|
||||
.andExpect(jsonPath("$.code").value("GAME_NOT_FOUND"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateBacklog_GameNotOwned_Is404() throws Exception {
|
||||
mockMvc.perform(put("/api/library/games/999/backlog").header(ClientHeaderFilter.CLIENT_HEADER, "test").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"status\":\"PLAYING\"}"))
|
||||
.andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
private ResultActions patchBacklog(long appid, String body) throws Exception {
|
||||
return mockMvc.perform(patch("/api/library/games/" + appid + "/backlog").header(ClientHeaderFilter.CLIENT_HEADER, "test")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(body));
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.List;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@@ -189,7 +189,7 @@ class PublicProfileControllerTest extends AbstractIntegrationTest {
|
||||
// The dev filter falls back to the dummy user 1 for a token it rejects; user 7's game would answer 200.
|
||||
@Test
|
||||
void profileTicket_IsNoLoginForTheLibraryApi() throws Exception {
|
||||
mockMvc.perform(put("/api/library/games/220/backlog").header("Authorization", "Bearer " + ticket(USER_ID))
|
||||
mockMvc.perform(patch("/api/library/games/220/backlog").header("Authorization", "Bearer " + ticket(USER_ID))
|
||||
.contentType("application/json").content("{\"status\":\"DROPPED\"}"))
|
||||
.andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user