|
| 1 | +package me.chanjar.weixin.cp.api.impl; |
| 2 | + |
| 3 | +import com.google.inject.Inject; |
| 4 | +import me.chanjar.weixin.common.error.WxErrorException; |
| 5 | +import me.chanjar.weixin.cp.api.ApiTestModule; |
| 6 | +import me.chanjar.weixin.cp.api.WxCpService; |
| 7 | +import me.chanjar.weixin.cp.bean.todo.WxCpTodo; |
| 8 | +import org.testng.annotations.Guice; |
| 9 | +import org.testng.annotations.Test; |
| 10 | + |
| 11 | +import java.util.Arrays; |
| 12 | + |
| 13 | +import static org.testng.Assert.assertEquals; |
| 14 | +import static org.testng.Assert.assertNotNull; |
| 15 | + |
| 16 | +/** |
| 17 | + * 单元测试类. |
| 18 | + * |
| 19 | + * @author <a href="https://github.com/binarywang">Binary Wang</a> created on 2026-08-11 |
| 20 | + */ |
| 21 | +@Guice(modules = ApiTestModule.class) |
| 22 | +public class WxCpTodoServiceImplTest { |
| 23 | + /** |
| 24 | + * The Wx service. |
| 25 | + */ |
| 26 | + @Inject |
| 27 | + protected WxCpService wxService; |
| 28 | + |
| 29 | + private static final String TODO_ID = "17c7d2bd9f20d652840f72f59e796AAA"; |
| 30 | + |
| 31 | + /** |
| 32 | + * Test get. |
| 33 | + * |
| 34 | + * @throws WxErrorException the wx error exception |
| 35 | + */ |
| 36 | + @Test |
| 37 | + public void testGet() throws WxErrorException { |
| 38 | + final WxCpTodo todo = this.wxService.getTodoService().get(TODO_ID); |
| 39 | + assertNotNull(todo, "get() 返回的待办对象不应为 null"); |
| 40 | + assertEquals(todo.getTodoId(), TODO_ID, "返回的 todo_id 应与请求一致"); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Test update status only. |
| 45 | + * |
| 46 | + * @throws WxErrorException the wx error exception |
| 47 | + */ |
| 48 | + @Test |
| 49 | + public void testUpdateStatusOnly() throws WxErrorException { |
| 50 | + this.wxService.getTodoService().update(TODO_ID, 0, null); |
| 51 | + // 更新成功后通过 get() 回查,验证整体状态确实写入 |
| 52 | + final WxCpTodo todo = this.wxService.getTodoService().get(TODO_ID); |
| 53 | + assertNotNull(todo, "回查待办不应为 null"); |
| 54 | + assertEquals(todo.getStatus(), Integer.valueOf(0), "待办整体状态应为 0(完成)"); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Test update with attendees. |
| 59 | + * |
| 60 | + * @throws WxErrorException the wx error exception |
| 61 | + */ |
| 62 | + @Test |
| 63 | + public void testUpdateWithAttendees() throws WxErrorException { |
| 64 | + this.wxService.getTodoService().update(TODO_ID, 1, |
| 65 | + Arrays.asList( |
| 66 | + new WxCpTodo.Attendee().setUserid("lisi").setStatus(0), |
| 67 | + new WxCpTodo.Attendee().setUserid("zhangsan").setStatus(1) |
| 68 | + )); |
| 69 | + // 更新成功后通过 get() 回查,验证参与人列表确实写入 |
| 70 | + final WxCpTodo todo = this.wxService.getTodoService().get(TODO_ID); |
| 71 | + assertNotNull(todo, "回查待办不应为 null"); |
| 72 | + assertNotNull(todo.getAttendees(), "attendees 列表不应为 null"); |
| 73 | + assertEquals(todo.getAttendees().size(), 2, "参与人数量应为 2"); |
| 74 | + assertEquals(todo.getStatus(), Integer.valueOf(1), "待办整体状态应为 1(进行中)"); |
| 75 | + } |
| 76 | +} |
0 commit comments