|
| 1 | +package cn.binarywang.wx.miniapp.api.impl; |
| 2 | + |
| 3 | +import cn.binarywang.wx.miniapp.api.WxMaService; |
| 4 | +import cn.binarywang.wx.miniapp.api.WxMaSubscribeService; |
| 5 | +import cn.binarywang.wx.miniapp.bean.WxMaGetUserNotifyRequest; |
| 6 | +import cn.binarywang.wx.miniapp.bean.WxMaServiceNotifyExtRequest; |
| 7 | +import cn.binarywang.wx.miniapp.bean.WxMaServiceNotifyRequest; |
| 8 | +import me.chanjar.weixin.common.error.WxErrorException; |
| 9 | +import org.mockito.Mockito; |
| 10 | +import org.testng.annotations.Test; |
| 11 | + |
| 12 | +import static org.mockito.ArgumentMatchers.anyString; |
| 13 | +import static org.mockito.ArgumentMatchers.eq; |
| 14 | +import static org.mockito.Mockito.verify; |
| 15 | +import static org.mockito.Mockito.when; |
| 16 | + |
| 17 | +public class WxMaSubscribeServiceImplUrlTest { |
| 18 | + |
| 19 | + @Test |
| 20 | + public void setUserNotifyUsesOfficialEndpoint() throws WxErrorException { |
| 21 | + WxMaService service = successService(); |
| 22 | + |
| 23 | + subscribeService(service).setUserNotify(WxMaServiceNotifyRequest.builder().build()); |
| 24 | + |
| 25 | + verify(service).post(eq("https://api.weixin.qq.com/wxa/set_user_notify"), anyString()); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + public void setUserNotifyExtUsesOfficialEndpoint() throws WxErrorException { |
| 30 | + WxMaService service = successService(); |
| 31 | + |
| 32 | + subscribeService(service).setUserNotifyExt(WxMaServiceNotifyExtRequest.builder().build()); |
| 33 | + |
| 34 | + verify(service).post(eq("https://api.weixin.qq.com/wxa/set_user_notifyext"), anyString()); |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + public void getUserNotifyUsesOfficialEndpoint() throws WxErrorException { |
| 39 | + WxMaService service = successService(); |
| 40 | + |
| 41 | + subscribeService(service).getUserNotify(WxMaGetUserNotifyRequest.builder().build()); |
| 42 | + |
| 43 | + verify(service).post(eq("https://api.weixin.qq.com/wxa/get_user_notify"), anyString()); |
| 44 | + } |
| 45 | + |
| 46 | + private WxMaSubscribeService subscribeService(WxMaService service) { |
| 47 | + return new WxMaSubscribeServiceImpl(service); |
| 48 | + } |
| 49 | + |
| 50 | + private WxMaService successService() throws WxErrorException { |
| 51 | + WxMaService service = Mockito.mock(WxMaService.class); |
| 52 | + when(service.post(anyString(), anyString())).thenReturn("{\"errcode\":0,\"errmsg\":\"ok\"}"); |
| 53 | + return service; |
| 54 | + } |
| 55 | +} |
0 commit comments