-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨 #1624 企业微信模块更新用户信息相关接口类以适应企业微信私有化版本
- Loading branch information
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...test/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapterForPrivatizedVersionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package me.chanjar.weixin.cp.util.json; | ||
|
||
import me.chanjar.weixin.cp.bean.WxCpUser; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* <pre> | ||
* 企业微信(私有化版本getUser兼容测试) | ||
* </pre> | ||
* | ||
* @author 庄壮壮 | ||
* @since 2020-06-16 09:36 | ||
*/ | ||
public class WxCpUserGsonAdapterForPrivatizedVersionTest { | ||
|
||
@Test | ||
public void testDeserialize() { | ||
final String userJson = "{\n" + | ||
" \"errcode\": 0,\n" + | ||
" \"errmsg\": \"ok\",\n" + | ||
" \"userid\": \"zhangsan\",\n" + | ||
" \"name\": \"李四\",\n" + | ||
" \"department\": [1, 2],\n" + | ||
" \"order\": [2, 10],\n" + | ||
" \"position\": \"后台工程师1\",\n" + | ||
" \"positions\": [\"后台工程师1\",\"后台工程师2\"],\n" + | ||
" \"mobile\": \"15913215421\",\n" + | ||
" \"hide_mobile\": 0,\n" + | ||
" \"gender\": \"1\",\n" + | ||
" \"email\": \"[email protected]\",\n" + | ||
" \"is_leader_in_dept\": [1, 0],\n" + | ||
" \"avatar\": \"http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0\",\n" + | ||
" \"telephone\": \"020-123456\",\n" + | ||
" \"english_name\": \"jackzhang\",\n" + | ||
" \"extattr\": {\"attrs\":[{\"name\":\"爱好\",\"value\":\"旅游\"},{\"name\":\"卡号\",\"value\":\"1234567234\"}]},\n" + | ||
" \"status\": 1,\n" + | ||
" \"enable\": 0,\n" + | ||
" \"qr_code\": \"https://wwlocal.qq.com/wework_admin/userQRCode?vcode=vc2140a8b3c6207c74&lvc=vcf6f1acfdc4b45088\"\n" + | ||
"}"; | ||
|
||
final WxCpUser user = WxCpUser.fromJson(userJson); | ||
assertThat(user).isNotNull(); | ||
|
||
// test order | ||
assertThat(user.getOrders()).isNotEmpty(); | ||
assertThat(user.getOrders().length).isEqualTo(2); | ||
assertThat(user.getOrders()[0]).isEqualTo(2); | ||
assertThat(user.getOrders()[1]).isEqualTo(10); | ||
|
||
// test english name | ||
assertThat(user.getEnglishName()).isEqualTo("jackzhang"); | ||
|
||
// test extattrs | ||
assertThat(user.getExtAttrs()).isNotEmpty(); | ||
final WxCpUser.Attr extraAttr1 = user.getExtAttrs().get(0); | ||
assertThat(extraAttr1.getName()).isEqualTo("爱好"); | ||
assertThat(extraAttr1.getTextValue()).isEqualTo("旅游"); | ||
final WxCpUser.Attr extraAttr2 = user.getExtAttrs().get(1); | ||
assertThat(extraAttr2.getName()).isEqualTo("卡号"); | ||
assertThat(extraAttr2.getTextValue()).isEqualTo("1234567234"); | ||
|
||
// test position | ||
assertThat(user.getPosition()).isEqualTo("后台工程师1"); | ||
// test positions | ||
assertThat(user.getPositions()).isNotEmpty(); | ||
assertThat(user.getPositions().length).isEqualTo(2); | ||
assertThat(user.getPositions()[0]).isEqualTo("后台工程师1"); | ||
assertThat(user.getPositions()[1]).isEqualTo("后台工程师2"); | ||
} | ||
|
||
@Test | ||
public void testSerialize() { | ||
WxCpUser user = new WxCpUser(); | ||
user.setOrders(new Integer[]{1, 2}); | ||
user.setPositions(new String[]{"后台工程师1", "后台工程师2"}); | ||
user.setEnglishName("jackson"); | ||
WxCpUser.Attr attr1 = new WxCpUser.Attr(); | ||
attr1.setName("爱好").setTextValue("旅游"); | ||
WxCpUser.Attr attr2 = new WxCpUser.Attr(); | ||
attr2.setName("卡号").setTextValue("1234567234"); | ||
|
||
user.addExtAttr(attr1); | ||
user.addExtAttr(attr2); | ||
|
||
assertThat(user.toJson()).isEqualTo("{\"order\":[1,2],\"positions\":[\"后台工程师1\",\"后台工程师2\"],\"english_name\":\"jackson\",\"extattr\":{\"attrs\":[{\"name\":\"爱好\",\"value\":\"旅游\"},{\"name\":\"卡号\",\"value\":\"1234567234\"}]},\"external_profile\":{}}"); | ||
} | ||
} |