Add update endpoints for tags and categories

This commit is contained in:
Tim
2025-07-02 14:36:26 +08:00
parent a6fd1b52ed
commit 19fb175cce
6 changed files with 80 additions and 0 deletions

View File

@@ -64,4 +64,23 @@ class CategoryControllerTest {
.andExpect(jsonPath("$[0].describe").value("d2"))
.andExpect(jsonPath("$[0].icon").value("i2"));
}
@Test
void updateCategory() throws Exception {
Category c = new Category();
c.setId(3L);
c.setName("tech");
c.setDescribe("d3");
c.setIcon("i3");
Mockito.when(categoryService.updateCategory(eq(3L), eq("tech"), eq("d3"), eq("i3"))).thenReturn(c);
mockMvc.perform(put("/api/categories/3")
.contentType(MediaType.APPLICATION_JSON)
.content("{\"name\":\"tech\",\"describe\":\"d3\",\"icon\":\"i3\"}"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(3))
.andExpect(jsonPath("$.name").value("tech"))
.andExpect(jsonPath("$.describe").value("d3"))
.andExpect(jsonPath("$.icon").value("i3"));
}
}

View File

@@ -65,4 +65,23 @@ class TagControllerTest {
.andExpect(jsonPath("$[0].describe").value("d2"))
.andExpect(jsonPath("$[0].icon").value("i2"));
}
@Test
void updateTag() throws Exception {
Tag t = new Tag();
t.setId(3L);
t.setName("java");
t.setDescribe("d3");
t.setIcon("i3");
Mockito.when(tagService.updateTag(eq(3L), eq("java"), eq("d3"), eq("i3"))).thenReturn(t);
mockMvc.perform(put("/api/tags/3")
.contentType(MediaType.APPLICATION_JSON)
.content("{\"name\":\"java\",\"describe\":\"d3\",\"icon\":\"i3\"}"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(3))
.andExpect(jsonPath("$.name").value("java"))
.andExpect(jsonPath("$.describe").value("d3"))
.andExpect(jsonPath("$.icon").value("i3"));
}
}