Commit 2b583a54 by lanrion

添加批量更新分组,删除分组API

parent e11e584b
......@@ -16,3 +16,4 @@ test/tmp
test/version_tmp
tmp
*DS_Store
.ruby-version
......@@ -38,6 +38,17 @@ module WeixinAuthorize
http_post(group_url, {openid: openid, to_groupid: to_groupid})
end
# 批量移动用户分组
def batch_update_group_for_openids(openids, group_id)
group_url = "#{group_base_url}/members/batchupdate"
http_post(group_url, {openid_list: openids, to_groupid: group_id})
end
def delete_group(group_id)
group_url = "#{group_base_url}/delete"
http_post(group_url, {group: {id: group_id}})
end
private
def group_base_url
......
......@@ -42,17 +42,14 @@ describe WeixinAuthorize::Api::Custom do
it "#send_video_custom" do
pending("The test must have a media_id")
this_should_not_get_executed
end
it "#send_music_custom" do
pending("The test must have a media_id")
this_should_not_get_executed
end
it "#send_voice_custom" do
pending("The test must have a media_id")
this_should_not_get_executed
end
end
......@@ -8,18 +8,35 @@ describe WeixinAuthorize::Api::Groups do
"test group_name_2"
end
let(:groups) do
$client.groups
end
let(:last_group_id) do
groups.result["groups"][-1]["id"]
end
it "#delete all group step by step" do
group_ids = groups.result["groups"].collect{|group|group["id"]}
group_ids.each do |group_id|
res = $client.delete_group(group_id)
if res.code.to_s != "45009"
expect(res.code).to eq(WeixinAuthorize::OK_CODE)
end
end
end
it "create a group" do
response = $client.create_group(group_name)
if response.code == WeixinAuthorize::OK_CODE
expect(response.result["group"]["name"]).to eq(group_name)
else
expect(response.code).to eq(-1)
puts "SB WEIXIN says: system error"
puts "WEIXIN says: system error"
end
end
it "get groups" do
groups = $client.groups
expect(groups.result["groups"][-1]["name"]).to eq(group_name)
end
......@@ -32,7 +49,7 @@ describe WeixinAuthorize::Api::Groups do
response = $client.create_group(group_name)
if response.code != WeixinAuthorize::OK_CODE
expect(response.code).to eq(-1)
puts "SB WEIXIN says: system error"
puts "WEIXIN says: system error"
else
expect(response.result["group"]["name"]).to eq(group_name)
response = $client.update_group_name(response.result["group"]["id"], group_name_2)
......@@ -43,12 +60,15 @@ describe WeixinAuthorize::Api::Groups do
end
it "#update_group_for_openid" do
groups = $client.groups
last_group_id = groups.result["groups"][-1]["id"]
$client.update_group_for_openid(ENV["OPENID"], last_group_id)
group = $client.get_group_for(ENV["OPENID"])
expect(group.result["groupid"]).to eq(last_group_id)
$client.update_group_for_openid(ENV["OPENID"], 0)
end
it "#batch update group for openids" do
res = $client.batch_update_group_for_openids([ENV["OPENID"]], last_group_id)
expect(res.code).to eq(WeixinAuthorize::OK_CODE)
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment