Commit 5256863c by lanrion

adjust for error handler modify

parent 90626d36
......@@ -2,7 +2,9 @@ language: ruby
bundler_args: --without development
rvm:
- 2.0.0
script: bundle exec rspec spec
script:
- CODECLIMATE_REPO_TOKEN=c91fecbbd9e414e7cc3ad7a7d99207145de0ac65a3368de09e8c19295343d399 bundle exec rake"
- bundle exec rspec spec
services:
- redis
addons:
......
......@@ -15,7 +15,7 @@ describe WeixinAuthorize::Api::Custom do
it "#send_text_custom" do
response = $client.send_text_custom(ENV["OPENID"], text_message)
expect(response["errcode"]).to eq(0)
expect(response.code).to eq(WeixinAuthorize::OK_CODE)
end
it "#send_news_custom" do
......@@ -32,14 +32,14 @@ describe WeixinAuthorize::Api::Custom do
"picurl"=> "http://www.baidu.com/img/bdlogo.gif"
}]
response = $client.send_news_custom(ENV["OPENID"], articles)
expect(response["errcode"]).to eq(0)
expect(response.code).to eq(WeixinAuthorize::OK_CODE)
end
it "#send_image_custom" do
image = $client.upload_media(image_file, "image")
media_id = image["media_id"]
media_id = image.result["media_id"]
response = $client.send_image_custom(ENV["OPENID"], media_id)
expect(response["errcode"]).to eq(0)
expect(response.code).to eq(WeixinAuthorize::OK_CODE)
end
it "#send_video_custom" do
......
......@@ -11,44 +11,44 @@ describe WeixinAuthorize::Api::Groups do
it "create a group" do
response = $client.create_group(group_name)
if !response["errcode"].nil?
expect(response.keys).to eq(["errcode", "errmsg"])
puts "SB WEIXIN says: system error"
else
if response.code == WeixinAuthorize::OK_CODE
expect(response["group"]["name"]).to eq(group_name)
else
expect(response.code).to eq(-1)
puts "SB WEIXIN says: system error"
end
end
it "get groups" do
groups = $client.groups
expect(groups["groups"][-1]["name"]).to eq(group_name)
expect(groups.result["groups"][-1]["name"]).to eq(group_name)
end
it "#get_group_for ENV['OPENID']" do
group = $client.get_group_for(ENV["OPENID"])
expect(group.keys).to eq(["groupid"])
expect(group.result.keys).to eq(["groupid"])
end
it "#update_group_name" do
response = $client.create_group(group_name)
if !response["errcode"].nil?
expect(response.keys).to eq(["errcode", "errmsg"])
if response.code != WeixinAuthorize::OK_CODE
expect(response.code).to eq(-1)
puts "SB WEIXIN says: system error"
else
expect(response["group"]["name"]).to eq(group_name)
response = $client.update_group_name(response["group"]["id"], group_name_2)
expect(response["errcode"]).to eq(0)
expect(response.result["group"]["name"]).to eq(group_name)
response = $client.update_group_name(response.result["group"]["id"], group_name_2)
expect(response.code).to eq(WeixinAuthorize::OK_CODE)
groups = $client.groups
expect(groups["groups"][-1]["name"]).to eq(group_name_2)
expect(groups.result["groups"][-1]["name"]).to eq(group_name_2)
end
end
it "#update_group_for_openid" do
groups = $client.groups
last_group_id = groups["groups"][-1]["id"]
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["groupid"]).to eq(last_group_id)
expect(group.result["groupid"]).to eq(last_group_id)
$client.update_group_for_openid(ENV["OPENID"], 0)
end
......
......@@ -12,12 +12,13 @@ describe WeixinAuthorize::Api::Media do
it "can upload a image" do
response = $client.upload_media(image_file, "image")
expect(response.keys).to eq(["type", "media_id", "created_at"])
expect(response.code).to eq(WeixinAuthorize::OK_CODE)
expect(response.result.keys).to eq(["type", "media_id", "created_at"])
end
it "#download_media_url return a String url" do
image = $client.upload_media(image_file, "image")
media_id = image["media_id"]
media_id = image.result["media_id"]
response = $client.download_media_url(media_id)
expect(response.class).to eq(String)
end
......
......@@ -6,16 +6,23 @@ describe WeixinAuthorize::Api::Menu do
it "can create a menu" do
menu = '{"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC"},{"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER"},{"name":"菜单","sub_button":[{"type":"view","name":"搜索","url":"http://www.soso.com/"},{"type":"view","name":"视频","url":"http://v.qq.com/"},{"type":"click","name":"赞一下我们","key":"V1001_GOOD"}]}]}'
response = $client.create_menu(MultiJson.load(menu)) # or Json string
expect(response["errcode"]).to eq(0)
expect(response.code).to eq(WeixinAuthorize::OK_CODE)
end
it "can't create a menu if invalid button size" do
menu = '{"button":[]}'
response = $client.create_menu(menu)
expect(response.code).not_to eq(WeixinAuthorize::OK_CODE)
end
it "can get a weixin Menu info" do
menu_info = $client.menu
expect(menu_info.keys[0]).to eq("menu")
expect(menu_info.result.keys[0]).to eq("menu")
expect(menu_info.code).to eq(WeixinAuthorize::OK_CODE)
end
it "can delete weixin Menu" do
response = $client.delete_menu
expect(response["errcode"]).to eq(0)
expect(response.code).to eq(WeixinAuthorize::OK_CODE)
end
end
......@@ -4,13 +4,15 @@ describe WeixinAuthorize::Api::Qrcode do
it "#create_qr_scene" do
response = $client.create_qr_scene("123")
expect(response.keys).to eq(["ticket", "expire_seconds"])
expect(response["expire_seconds"]).to eq(1800)
expect(response.code).to eq(WeixinAuthorize::OK_CODE)
expect(response.result.keys).to eq(["ticket", "expire_seconds"])
expect(response.result["expire_seconds"]).to eq(1800)
end
it "#create_qr_limit_scene" do
response = $client.create_qr_limit_scene("1234")
expect(response.keys).to eq(["ticket"])
expect(response.code).to eq(WeixinAuthorize::OK_CODE)
expect(response.result.keys).to eq(["ticket"])
end
end
......@@ -3,18 +3,21 @@ require "spec_helper"
describe WeixinAuthorize::Api::User do
it "can get a weixin User info" do
user_info = $client.user(ENV["OPENID"])
expect(user_info["openid"]).to eq(ENV["OPENID"])
expect(user_info.code).to eq(WeixinAuthorize::OK_CODE)
expect(user_info.result["openid"]).to eq(ENV["OPENID"])
end
it "can get followers infos" do
valid_info = $client.is_valid?
expect(valid_info).to eq(true)
followers = $client.followers
expect(followers.keys).to eq(["total", "count", "data", "next_openid"])
expect(followers.code).to eq(WeixinAuthorize::OK_CODE)
expect(followers.result.keys).to eq(["total", "count", "data", "next_openid"])
valid_info = $client.is_valid?
expect(valid_info).to eq(true)
followers = $client.followers
expect(followers.keys).to eq(["total", "count", "data", "next_openid"])
expect(followers.code).to eq(WeixinAuthorize::OK_CODE)
expect(followers.result.keys).to eq(["total", "count", "data", "next_openid"])
end
end
......@@ -23,6 +23,8 @@ require 'coveralls'
require 'simplecov'
require "codeclimate-test-reporter"
require "pry-rails"
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
......
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