|
1 | 1 | package cn.binarywang.wx.miniapp.api.impl; |
2 | 2 |
|
3 | 3 | import cn.binarywang.wx.miniapp.api.WxMaService; |
| 4 | +import cn.binarywang.wx.miniapp.api.WxMaSubscribeService; |
4 | 5 | import cn.binarywang.wx.miniapp.bean.WxMaGetUserNotifyRequest; |
5 | 6 | import cn.binarywang.wx.miniapp.bean.WxMaGetUserNotifyResult; |
6 | 7 | import cn.binarywang.wx.miniapp.bean.WxMaServiceNotifyExtRequest; |
|
14 | 15 | import com.google.common.collect.Lists; |
15 | 16 | import com.google.inject.Inject; |
16 | 17 | import me.chanjar.weixin.common.error.WxErrorException; |
| 18 | +import org.testng.Assert; |
17 | 19 | import org.testng.annotations.Guice; |
18 | 20 | import org.testng.annotations.Test; |
19 | 21 |
|
20 | 22 | import java.util.List; |
21 | 23 |
|
22 | 24 | import static org.assertj.core.api.Assertions.assertThat; |
| 25 | +import static org.mockito.ArgumentMatchers.anyString; |
| 26 | +import static org.mockito.Mockito.mock; |
| 27 | +import static org.mockito.Mockito.when; |
23 | 28 |
|
24 | 29 | /** |
25 | 30 | * 测试类. |
@@ -78,38 +83,57 @@ public void testSendSubscribeMsg() throws WxErrorException { |
78 | 83 |
|
79 | 84 | @Test |
80 | 85 | public void testSetUserNotify() throws WxErrorException { |
81 | | - // TODO 待完善补充,需要真实的 openid、notify_type、notify_code、content_json 参数 |
| 86 | + WxMaService service = mock(WxMaService.class); |
| 87 | + when(service.post(anyString(), anyString())).thenReturn("{\"errcode\":0,\"errmsg\":\"ok\"}"); |
| 88 | + |
| 89 | + WxMaSubscribeService subscribeService = new WxMaSubscribeServiceImpl(service); |
82 | 90 | WxMaServiceNotifyRequest request = WxMaServiceNotifyRequest.builder() |
83 | 91 | .openid("test_openid") |
84 | 92 | .notifyType(1) |
85 | 93 | .notifyCode("test_notify_code") |
86 | 94 | .contentJson("{}") |
87 | 95 | .build(); |
88 | | - this.wxService.getSubscribeService().setUserNotify(request); |
| 96 | + subscribeService.setUserNotify(request); |
89 | 97 | } |
90 | 98 |
|
91 | 99 | @Test |
92 | 100 | public void testSetUserNotifyExt() throws WxErrorException { |
93 | | - // TODO 待完善补充,需要真实的 openid、notify_type、notify_code、ext_json 参数 |
| 101 | + WxMaService service = mock(WxMaService.class); |
| 102 | + when(service.post(anyString(), anyString())).thenReturn("{\"errcode\":0,\"errmsg\":\"ok\"}"); |
| 103 | + |
| 104 | + WxMaSubscribeService subscribeService = new WxMaSubscribeServiceImpl(service); |
94 | 105 | WxMaServiceNotifyExtRequest request = WxMaServiceNotifyExtRequest.builder() |
95 | 106 | .openid("test_openid") |
96 | 107 | .notifyType(1) |
97 | 108 | .notifyCode("test_notify_code") |
98 | 109 | .extJson("{}") |
99 | 110 | .build(); |
100 | | - this.wxService.getSubscribeService().setUserNotifyExt(request); |
| 111 | + subscribeService.setUserNotifyExt(request); |
101 | 112 | } |
102 | 113 |
|
103 | 114 | @Test |
104 | 115 | public void testGetUserNotify() throws WxErrorException { |
105 | | - // TODO 待完善补充,需要真实的 openid、notify_type、notify_code 参数 |
| 116 | + WxMaService service = mock(WxMaService.class); |
| 117 | + when(service.post(anyString(), anyString())).thenReturn( |
| 118 | + "{\"errcode\":0,\"errmsg\":\"ok\"," |
| 119 | + + "\"notify_info\":{" |
| 120 | + + "\"notify_type\":1," |
| 121 | + + "\"content_json\":\"{\\\"status\\\":1}\"," |
| 122 | + + "\"code_state\":0," |
| 123 | + + "\"code_expire_time\":1700000000" |
| 124 | + + "}}"); |
| 125 | + |
| 126 | + WxMaSubscribeService subscribeService = new WxMaSubscribeServiceImpl(service); |
106 | 127 | WxMaGetUserNotifyRequest request = WxMaGetUserNotifyRequest.builder() |
107 | 128 | .openid("test_openid") |
108 | 129 | .notifyCode("test_notify_code") |
109 | 130 | .notifyType(1) |
110 | 131 | .build(); |
111 | | - WxMaGetUserNotifyResult result = this.wxService.getSubscribeService().getUserNotify(request); |
112 | | - assertThat(result).isNotNull(); |
113 | | - System.out.println(result); |
| 132 | + WxMaGetUserNotifyResult result = subscribeService.getUserNotify(request); |
| 133 | + Assert.assertNotNull(result); |
| 134 | + Assert.assertNotNull(result.getNotifyInfo()); |
| 135 | + Assert.assertEquals(result.getNotifyInfo().getNotifyType().intValue(), 1); |
| 136 | + Assert.assertEquals(result.getNotifyInfo().getCodeState().intValue(), 0); |
| 137 | + Assert.assertEquals(result.getNotifyInfo().getCodeExpireTime().longValue(), 1700000000L); |
114 | 138 | } |
115 | 139 | } |
0 commit comments