Skip to content

Commit

Permalink
CHG: refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
seandong committed Aug 1, 2017
1 parent 9582f0d commit 381a1d7
Show file tree
Hide file tree
Showing 29 changed files with 324 additions and 43 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
/spec/reports/
/tmp/
*.gem
config.yml
.DS_Store
29 changes: 29 additions & 0 deletions test/fixtures/api/agent/get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"errcode":0,
"errmsg": "ok",
"agentid": "1",
"name": "NAME",
"square_logo_url": "xxxxxxxx",
"description": "desc",
"allow_userinfos": {
"user":[
{
"userid":"id2"
},
{
"userid":"id3"
}
]
},
"allow_partys":{
"partyid": [1]
},
"allow_tags":{
"tagid": [1,2,3]
},
"close": 0,
"redirect_domain": "www.qq.com",
"report_location_flag": 0,
"isreportenter": 0,
"home_url": "http://www.qq.com"
}
16 changes: 16 additions & 0 deletions test/fixtures/api/agent/list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"errcode":0,
"errmsg":"ok" ,
"agentlist":[
{
"agentid":1,
"name":"NAME",
"square_logo_url":"xxxxxxxx"
},
{
"agentid":2,
"name":"NAME",
"square_logo_url":"xxxxxxxx"
}
]
}
4 changes: 4 additions & 0 deletions test/fixtures/api/agent/set.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"errcode":0,
"errmsg":"ok"
}
8 changes: 8 additions & 0 deletions test/fixtures/api/batch/getresult.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"errcode": 0,
"errmsg": "ok",
"status": 1,
"type": "replace_user",
"total": 3,
"percentage": 33,
}
4 changes: 4 additions & 0 deletions test/fixtures/api/error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"errcode": -1,
"errmsg": "Invalid input"
}
6 changes: 6 additions & 0 deletions test/fixtures/api/get_jsapi_ticket.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"errcode":0,
"errmsg":"ok",
"ticket":"bxLdikRXVbTPdHSM05e5u5sUoXNKd8-41ZO3MhKoyN5OfkWITDGgnr2fwJ0m9E8NYzWKVZvdVtaUgWvsdshFKA",
"expires_in":7200
}
6 changes: 6 additions & 0 deletions test/fixtures/api/gettoken.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"errcode":0,
"errmsg":"",
"access_token": "accesstoken000001",
"expires_in": 7200
}
24 changes: 24 additions & 0 deletions test/fixtures/api/menu/get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"button":[
{
"type":"click",
"name":"今日歌曲",
"key":"V1001_TODAY_MUSIC"
},
{
"name":"菜单",
"sub_button":[
{
"type":"view",
"name":"搜索",
"url":"http://www.soso.com/"
},
{
"type":"click",
"name":"赞一下我们",
"key":"V1001_GOOD"
}
]
}
]
}
Empty file.
4 changes: 4 additions & 0 deletions test/fixtures/api/service/get_corp_token.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"access_token": "xxxxxx",
"expires_in": 7200
}
54 changes: 54 additions & 0 deletions test/fixtures/api/service/get_permanent_code.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"access_token": "xxxxxx",
"expires_in": 7200,
"permanent_code": "xxxx",
"auth_corp_info":
{
"corpid": "xxxx",
"corp_name": "name",
"corp_type": "verified",
"corp_square_logo_url": "yyyyy",
"corp_user_max": 50,
"corp_agent_max": 30,
"corp_full_name":"full_name",
"verified_end_time":1431775834,
"subject_type": 1,
"corp_wxqrcode": "zzzzz"
},
"auth_info":
{
"agent" :
[
{
"agentid":1,
"name":"NAME",
"round_logo_url":"xxxxxx",
"square_logo_url":"yyyyyy",
"appid":1,
"privilege":
{
"level":1,
"allow_party":[1,2,3],
"allow_user":["zhansan","lisi"],
"allow_tag":[1,2,3],
"extra_party":[4,5,6],
"extra_user":["wangwu"],
"extra_tag":[4,5,6]
}
},
{
"agentid":2,
"name":"NAME2",
"round_logo_url":"xxxxxx",
"square_logo_url":"yyyyyy",
"appid":5
}
]
},
"auth_user_info":
{
"email":"[email protected]",
"mobile":"1234567890",
"userid":"aa"
}
}
6 changes: 6 additions & 0 deletions test/fixtures/api/service/get_pre_auth_code.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"errcode":0 ,
"errmsg":"ok" ,
"pre_auth_code":"xxxx",
"expires_in":1200
}
4 changes: 4 additions & 0 deletions test/fixtures/api/service/get_suite_token.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"suite_access_token":"61W3mEpU66027wgNZ_MhGHNQDHnFATkDa9-2llqrMBjUwxRSNPbVsMmyD-yq8wZETSoE5NQgecigDrSHkPtIYA",
"expires_in":7200
}
4 changes: 4 additions & 0 deletions test/fixtures/api/success.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"errcode": 0,
"errmsg": "ok"
}
6 changes: 6 additions & 0 deletions test/fixtures/api/user/convert_to_openid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"errcode": 0,
"errmsg": "ok",
"openid": "oDOGms-6yCnGrRovBj2yHij5JL6E",
"appid":"wxf874e15f78cc84a7"
}
5 changes: 5 additions & 0 deletions test/fixtures/api/user/convert_to_userid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"errcode": 0,
"errmsg": "ok",
"userid": "zhangsan"
}
18 changes: 18 additions & 0 deletions test/fixtures/api/user/get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"errcode": 0,
"errmsg": "ok",
"userid": "zhangsan",
"name": "李四",
"department": [1, 2],
"order": [1, 2],
"position": "后台工程师",
"mobile": "15913215421",
"gender": "1",
"email": "[email protected]",
"isleader": 1,
"avatar": "http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0",
"telephone": "020-123456",
"english_name": "jackzhang",
"extattr": {"attrs":[{"name":"爱好","value":"旅游"},{"name":"卡号","value":"1234567234"}]},
"status": 1
}
10 changes: 10 additions & 0 deletions test/fixtures/api/user/getuserdetail.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"userid":"lisi",
"name":"李四",
"department":[3],
"position": "后台工程师",
"mobile":"15050495892",
"gender":1,
"email":"[email protected]",
"avatar":"http://shp.qpic.cn/bizmp/xxxxxxxxxxx/0"
}
8 changes: 8 additions & 0 deletions test/fixtures/api/user/getuserinfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"errcode": 0,
"errmsg": "ok",
"UserId":"USERID",
"DeviceId":"DEVICEID",
"user_ticket": "USER_TICKET",
"expires_in":7200
}
22 changes: 22 additions & 0 deletions test/fixtures/api/user/list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"errcode": 0,
"errmsg": "ok",
"userlist": [
{
"userid": "zhangsan",
"name": "李四",
"department": [1, 2],
"order": [1, 2],
"position": "后台工程师",
"mobile": "15913215421",
"gender": "1",
"email": "[email protected]",
"isleader": 0,
"avatar": "http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0",
"telephone": "020-123456",
"english_name": "jackzhang",
"status": 1,
"extattr": {"attrs":[{"name":"爱好","value":"旅游"},{"name":"卡号","value":"1234567234"}]}
}
]
}
11 changes: 11 additions & 0 deletions test/fixtures/api/user/simplelist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"errcode": 0,
"errmsg": "ok",
"userlist": [
{
"userid": "zhangsan",
"name": "李四",
"department": [1, 2]
}
]
}
11 changes: 11 additions & 0 deletions test/fixtures/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORP_ID: 'ww79c13c8a6183aac6'
CORP_SECRET: 'gLZfbW8ZKIi9JYmL_Ox3t8xQH0GklCaZAL8-L3jzJ0s'
APP_ID: '1000006'
APP_SECRET: 'Fih7jCrS6Fee3OQ4QpIfkwjwvBPJS3gWkkdYpDGyh68'

SUITE_CORPID: 'wx0c2fbd31ee9b9611'
SUITE_ID: 'tja33baec0c0d207e2'
SUITE_ENCODING_AES_KEY: '657bca245569d26385ec5134cf83e59110ea7715eba'
SUITE_TOKEN: 'e96f2a5d0b05a69ec20e9325ae8d34'
SUITE_SECRET: 'd0S0OQv-QzW7IMhX9WXK46jUqxtHQcIIrWksJ2n2fQDc-wMKHNhCT9E-yOiVN77b'
SUITE_TICKET: 'kBCgyTpUHJTCll-eFdaiCuK70hsgakeKcESr1X350kYB0yF76Ih2oxgFnfEKmlus'
10 changes: 0 additions & 10 deletions test/fixtures/config.yml.sample

This file was deleted.

33 changes: 33 additions & 0 deletions test/support/fake_wework.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'json'
require 'sinatra/base'

class FakeWework < Sinatra::Base

get '/cgi-bin/media/get' do
send_file fixture_file_path('zhiren.png'), :type => :jpg
end

get '/cgi-bin/*' do |api|
json_response "api/#{api}.json"
end

%i(get post).each do |http_method|
send http_method, '/cgi-bin/*/*' do |category, api|
json_response "api/#{category}/#{api}.json"
end
end

private

def json_response file_name
content_type :json
status 200
file_path = fixture_file_path(file_name)
file_path = fixture_file_path('api/success.json') unless File.exist?(file_path)
File.open(file_path, 'rb').read
end

def fixture_file_path path
File.join(File.expand_path('../../fixtures/', __FILE__), path)
end
end
23 changes: 12 additions & 11 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'wework'
require 'mock_redis'
require "minitest/pride"
require 'minitest/autorun'
require 'minitest/unit'

require 'yaml'


ENV['CORP_ID'] = 'corpid'
ENV['CONTACT_SECRET'] = 'corp secret'
ENV['APP_ID'] = 'appid'
ENV['APP_SECRET'] = 'app secret'


#load seeds file
seeds_path = File.join(File.dirname(__FILE__), 'fixtures/config.yml')
if File.exist? seeds_path
YAML.load_file(seeds_path).each do |k, v|
ENV[k] = "#{v}"
end
end

unless ENV['IGNORE_WEWORK_MOCK']
require 'webmock/minitest'
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each {|f| require f}
end

class Minitest::Test
Wework.configure do |config|
config.redis = Redis.new(host: '127.0.0.1', port: 6379, db: 1)
def before_setup
stub_request(:any, /qyapi.weixin.qq.com/).to_rack(FakeWework) unless ENV['IGNORE_WEWORK_MOCK']

Wework.configure do |config|
config.redis = MockRedis.new
end
end
end
Loading

0 comments on commit 381a1d7

Please sign in to comment.