libgss 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +16 -0
- data/.rspec +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +31 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/lib/libgss/action.rb +25 -0
- data/lib/libgss/action_request.rb +302 -0
- data/lib/libgss/asset_request.rb +29 -0
- data/lib/libgss/network.rb +105 -0
- data/lib/libgss/outputs.rb +23 -0
- data/lib/libgss/version.rb +3 -0
- data/lib/libgss.rb +11 -0
- data/libgss.gemspec +27 -0
- data/spec/libgss/action_request_spec.rb +160 -0
- data/spec/libgss/actions/dictionary_spec.rb +39 -0
- data/spec/libgss/actions/friendship_spec.rb +139 -0
- data/spec/libgss/actions/game_data_spec.rb +81 -0
- data/spec/libgss/actions/int_range_spec.rb +46 -0
- data/spec/libgss/actions/log_spec.rb +58 -0
- data/spec/libgss/actions/master_spec.rb +142 -0
- data/spec/libgss/actions/probability_spec.rb +70 -0
- data/spec/libgss/actions/ruby_stored_script_spec.rb +62 -0
- data/spec/libgss/actions/schedule_spec.rb +49 -0
- data/spec/libgss/asset_request_spec.rb +33 -0
- data/spec/libgss/network_spec.rb +75 -0
- data/spec/protected_assets/Icon.png +0 -0
- data/spec/public_assets/Default.png +0 -0
- data/spec/spec_helper.rb +9 -0
- metadata +161 -0
@@ -0,0 +1,160 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Libgss::ActionRequest do
|
5
|
+
before do
|
6
|
+
request_fixture_load("01_basic")
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:network) do
|
10
|
+
network = Libgss::Network.new("http://localhost:3000")
|
11
|
+
network.player_id = "1000001"
|
12
|
+
network.login
|
13
|
+
network
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:request) do
|
17
|
+
network.new_action_request
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#server_time" do
|
21
|
+
it "basic call" do
|
22
|
+
t1 = Time.now.to_i
|
23
|
+
callback_called = false
|
24
|
+
callback = Proc.new do |outputs|
|
25
|
+
callback_called = true
|
26
|
+
t2 = Time.now.to_i
|
27
|
+
outputs.length.should == 1
|
28
|
+
t = outputs.first["result"]
|
29
|
+
t.should >= t1 # 秒単位だと同じ場合がある
|
30
|
+
t.should <= t2
|
31
|
+
end
|
32
|
+
request.server_time
|
33
|
+
request.send_request(&callback)
|
34
|
+
callback_called.should == true
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#server_date" do
|
40
|
+
shared_examples_for "Libgss::ActionRequest#server_date" do |time, date|
|
41
|
+
it do
|
42
|
+
request.server_date(time)
|
43
|
+
request.send_request
|
44
|
+
request.outputs.length.should == 1
|
45
|
+
request.outputs.first["result"].should == date
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# デフォルトでは業務日付の切り替えは04:00に行われます
|
50
|
+
it_should_behave_like "Libgss::ActionRequest#server_date", Time.parse("2017/7/10 03:59:59+09:00"), "2017-07-09"
|
51
|
+
it_should_behave_like "Libgss::ActionRequest#server_date", Time.parse("2017/7/10 04:00:00+09:00"), "2017-07-10"
|
52
|
+
it_should_behave_like "Libgss::ActionRequest#server_date", Time.parse("2017/7/10 04:00:01+09:00"), "2017-07-10"
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
expected_player_1000001 = {
|
57
|
+
"player_id"=>"fontana:1000001",
|
58
|
+
"nickname"=>nil,
|
59
|
+
"level"=>1,
|
60
|
+
"first_login_at"=> Time.parse("2012/7/15 21:50+09:00").to_i, # 1342356600,
|
61
|
+
# "current_login_at"=>1366678900,
|
62
|
+
# "last_login_at"=>1366678900,
|
63
|
+
"first_paid_at"=>nil,
|
64
|
+
"last_paid_at"=>nil,
|
65
|
+
"login_days"=>101,
|
66
|
+
"login_count_this_day"=>1,
|
67
|
+
"continuous_login_days"=>1
|
68
|
+
}
|
69
|
+
|
70
|
+
describe "#get" do
|
71
|
+
context "Player" do
|
72
|
+
it do
|
73
|
+
request.get_by_player
|
74
|
+
request.send_request do |outputs|
|
75
|
+
outputs.length.should == 1
|
76
|
+
player = outputs.first["result"]
|
77
|
+
# puts player.inspect
|
78
|
+
# AppSeedで定義されているデータの確認
|
79
|
+
player.select!{|k,v| expected_player_1000001.keys.include?(k) }
|
80
|
+
player.should == expected_player_1000001
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "bulk action" do
|
87
|
+
before do
|
88
|
+
request_fixture_load("01_basic")
|
89
|
+
end
|
90
|
+
|
91
|
+
context "server_time and get_by_player" do
|
92
|
+
it "using array index" do
|
93
|
+
request.server_time # 1
|
94
|
+
request.get_by_player # 2
|
95
|
+
callback_called = false
|
96
|
+
t1 = Time.now.to_i
|
97
|
+
request.send_request do |outputs|
|
98
|
+
callback_called = true
|
99
|
+
outputs.length.should == 2
|
100
|
+
# 1
|
101
|
+
t2 = Time.now.to_i
|
102
|
+
t = outputs[0]["result"]
|
103
|
+
t.should >= t1 # 秒単位だと同じ場合がある
|
104
|
+
t.should <= t2
|
105
|
+
# 2
|
106
|
+
player = outputs[1]["result"]
|
107
|
+
player.select!{|k,v| expected_player_1000001.keys.include?(k) }
|
108
|
+
player.should == expected_player_1000001
|
109
|
+
end
|
110
|
+
callback_called.should == true
|
111
|
+
end
|
112
|
+
|
113
|
+
ACITON_ID_SERVER_TIME = 10000001
|
114
|
+
ACITON_ID_GAME_DATA = 10000002
|
115
|
+
ACITON_ID_PLAYER = 10000003
|
116
|
+
|
117
|
+
# バルクアクションには大量のアクションが含まれることがあり、
|
118
|
+
# その中には状況によってアクションが呼ばれないこともあります。
|
119
|
+
# そのような場合は、バルクアクションの順番によって結果を取得することが
|
120
|
+
# 難しいので、アクションに固有の番号をつけると簡単になります。
|
121
|
+
it "using specified ID" do
|
122
|
+
a1 = request.server_time
|
123
|
+
a1.id = ACITON_ID_SERVER_TIME
|
124
|
+
|
125
|
+
if false # ここはこのテストでは実行されませんが、本番では動くかも。
|
126
|
+
a2 = request.get_by_game_data.with(ACITON_ID_GAME_DATA) # withメソッドで短く書くこともできます。
|
127
|
+
end
|
128
|
+
|
129
|
+
request.get_by_player.with(ACITON_ID_PLAYER)
|
130
|
+
|
131
|
+
callback_called = false
|
132
|
+
t1 = Time.now.to_i
|
133
|
+
request.send_request do |outputs|
|
134
|
+
callback_called = true
|
135
|
+
outputs.length.should == 2
|
136
|
+
# a1
|
137
|
+
output1 = outputs.get(ACITON_ID_SERVER_TIME)
|
138
|
+
t = output1["result"]
|
139
|
+
t2 = Time.now.to_i
|
140
|
+
t.should >= t1 # 秒単位だと同じ場合がある
|
141
|
+
t.should <= t2
|
142
|
+
|
143
|
+
if output2 = outputs.get(ACITON_ID_GAME_DATA)
|
144
|
+
fail "why this data is set? #{output2.inspect}"
|
145
|
+
end
|
146
|
+
|
147
|
+
# a3
|
148
|
+
output3 = outputs.get(ACITON_ID_PLAYER)
|
149
|
+
player = output3["result"]
|
150
|
+
player.select!{|k,v| expected_player_1000001.keys.include?(k) }
|
151
|
+
player.should == expected_player_1000001
|
152
|
+
end
|
153
|
+
callback_called.should == true
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Libgss::ActionRequest do
|
5
|
+
|
6
|
+
let(:network) do
|
7
|
+
network = Libgss::Network.new("http://localhost:3000")
|
8
|
+
network.player_id = "1000001"
|
9
|
+
network
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:request) do
|
13
|
+
network.login
|
14
|
+
network.new_action_request
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
describe "#get_by_dictionary" do
|
19
|
+
shared_examples_for "Libgss::ActionRequest#get_by_dictionary" do |input, output, conditions|
|
20
|
+
it do
|
21
|
+
callback_called = false
|
22
|
+
request.get_by_dictionary("ArmorUpgrade1", input, conditions)
|
23
|
+
request.send_request do |outputs|
|
24
|
+
callback_called = true
|
25
|
+
outputs.length.should == 1
|
26
|
+
outputs.first["result"].should == output
|
27
|
+
end
|
28
|
+
callback_called.should == true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it_should_behave_like "Libgss::ActionRequest#get_by_dictionary", 10001, 10002, nil
|
33
|
+
it_should_behave_like "Libgss::ActionRequest#get_by_dictionary", 10002, 10004, nil
|
34
|
+
|
35
|
+
it_should_behave_like "Libgss::ActionRequest#get_by_dictionary", 10001, nil, {"input$gt" => 10003}
|
36
|
+
it_should_behave_like "Libgss::ActionRequest#get_by_dictionary", 10002, nil, {"input$gt" => 10003}
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "Libgss::ActionRequest friendship" do
|
5
|
+
|
6
|
+
let(:network) do
|
7
|
+
network = Libgss::Network.new("http://localhost:3000")
|
8
|
+
network.player_id = "1000001"
|
9
|
+
network.login
|
10
|
+
network
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:request) do
|
14
|
+
network.new_action_request
|
15
|
+
end
|
16
|
+
|
17
|
+
before do
|
18
|
+
request_fixture_load("01_basic")
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#all" do
|
22
|
+
it "can't return other player's friendships" do
|
23
|
+
request.find_all("Friendship", nil, [["requester_id", "asc"], ["accepter_id", "asc"]])
|
24
|
+
request.send_request
|
25
|
+
request.outputs.length.should == 1
|
26
|
+
result = request.outputs.first["result"]
|
27
|
+
result.length.should == 8
|
28
|
+
result[0..6].each{|friendship| friendship["requester_id"].should == "fontana:1000001"}
|
29
|
+
result[7..7].each{|friendship| friendship["accepter_id" ].should == "fontana:1000001"}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "state" do
|
34
|
+
shared_examples_for "friendship state transition" do |target, action, res, *args|
|
35
|
+
it "#{action} #{target} => #{res.inspect}, #{args.inspect}" do
|
36
|
+
# request.apply("Friendship", target)
|
37
|
+
request.send(action, "Friendship", target)
|
38
|
+
|
39
|
+
# request.execute("RubyStoredScript", "get_applyings")
|
40
|
+
request.find_all("Friendship", nil, [["requester_id", "asc"], ["accepter_id", "asc"]])
|
41
|
+
request.send_request
|
42
|
+
request.outputs.length.should == 2
|
43
|
+
|
44
|
+
case res
|
45
|
+
when "OK" then
|
46
|
+
status_cd, new_data = *args
|
47
|
+
request.outputs.first["error"].should == nil
|
48
|
+
request.outputs.first["result"].should == "OK"
|
49
|
+
# applyings = request.outputs.last["result"]
|
50
|
+
friendships = request.outputs.last["result"]
|
51
|
+
friendships.length.should == 8 + (new_data ? 1 : 0)
|
52
|
+
friendships.detect{|f|
|
53
|
+
f["requester_id"] == "fontana:1000001" &&
|
54
|
+
f["accepter_id"] == target &&
|
55
|
+
f["status_cd"] == status_cd
|
56
|
+
}.should_not be_nil
|
57
|
+
|
58
|
+
when "NG" then
|
59
|
+
error_cd = args.first
|
60
|
+
request.outputs.first["result"].should == nil
|
61
|
+
request.outputs.first["error"]["message"].should =~ /\A#{error_cd}:/ # エラー
|
62
|
+
friendships = request.outputs.last["result"]
|
63
|
+
friendships.length.should == 8
|
64
|
+
friendships.detect{|f|
|
65
|
+
f["requester_id"] == "fontana:1000001" &&
|
66
|
+
f["accepter_id"] == target
|
67
|
+
}.should be_nil
|
68
|
+
|
69
|
+
when "IG" then
|
70
|
+
status_cd, new_data = *args
|
71
|
+
request.outputs.first["result"].should == "OK"
|
72
|
+
request.outputs.first["error"].should == nil
|
73
|
+
friendships = request.outputs.last["result"]
|
74
|
+
friendships.length.should == 8
|
75
|
+
if new_data
|
76
|
+
friendships.detect{|f|
|
77
|
+
f["requester_id"] == "fontana:1000001" &&
|
78
|
+
f["accepter_id"] == target
|
79
|
+
}.should be_nil
|
80
|
+
else
|
81
|
+
friendships.detect{|f|
|
82
|
+
f["requester_id"] == "fontana:1000001" &&
|
83
|
+
f["accepter_id"] == target &&
|
84
|
+
f["status_cd"] == status_cd
|
85
|
+
}.should_not be_nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# status_cd の定数
|
93
|
+
FriendshipNone = 0
|
94
|
+
FriendshipApplied_r = 1
|
95
|
+
FriendshipApproved = 2
|
96
|
+
FriendshipDeleted = 3
|
97
|
+
FriendshipApplied_l = 4
|
98
|
+
FriendshipBlocked_r = 5
|
99
|
+
FriendshipBlocked_l = 6
|
100
|
+
FriendshipBlocked_lr = 7
|
101
|
+
|
102
|
+
# フレンドシップがない初期状態
|
103
|
+
context "without friendship" do
|
104
|
+
it_should_behave_like "friendship state transition", "fontana:1000009", :apply , "OK", FriendshipApplied_r, :new
|
105
|
+
it_should_behave_like "friendship state transition", "fontana:1000009", :approve , "NG", 1003
|
106
|
+
it_should_behave_like "friendship state transition", "fontana:1000009", :breakoff, "IG", nil, :new
|
107
|
+
it_should_behave_like "friendship state transition", "fontana:1000009", :block , "OK", FriendshipBlocked_r, :new
|
108
|
+
it_should_behave_like "friendship state transition", "fontana:1000009", :unblock , "IG", nil, :new
|
109
|
+
end
|
110
|
+
|
111
|
+
context "approve" do
|
112
|
+
it_should_behave_like "friendship state transition", "fontana:1000005", :approve , "OK", FriendshipApproved
|
113
|
+
end
|
114
|
+
|
115
|
+
context "breakoff" do
|
116
|
+
it_should_behave_like "friendship state transition", "fontana:1000002", :breakoff , "OK", FriendshipDeleted
|
117
|
+
it_should_behave_like "friendship state transition", "fontana:1000003", :breakoff , "OK", FriendshipDeleted
|
118
|
+
it_should_behave_like "friendship state transition", "fontana:1000004", :breakoff , "IG", FriendshipDeleted
|
119
|
+
it_should_behave_like "friendship state transition", "fontana:1000005", :breakoff , "OK", FriendshipDeleted
|
120
|
+
end
|
121
|
+
|
122
|
+
context "block" do
|
123
|
+
it_should_behave_like "friendship state transition", "fontana:1000002", :block , "OK", FriendshipBlocked_r
|
124
|
+
it_should_behave_like "friendship state transition", "fontana:1000003", :block , "OK", FriendshipBlocked_r
|
125
|
+
it_should_behave_like "friendship state transition", "fontana:1000004", :block , "OK", FriendshipBlocked_r
|
126
|
+
it_should_behave_like "friendship state transition", "fontana:1000005", :block , "OK", FriendshipBlocked_r
|
127
|
+
it_should_behave_like "friendship state transition", "fontana:1000006", :block , "OK", FriendshipBlocked_r
|
128
|
+
it_should_behave_like "friendship state transition", "fontana:1000007", :block , "OK", FriendshipBlocked_lr
|
129
|
+
it_should_behave_like "friendship state transition", "fontana:1000008", :block , "OK", FriendshipBlocked_lr
|
130
|
+
end
|
131
|
+
|
132
|
+
context "unblock" do
|
133
|
+
it_should_behave_like "friendship state transition", "fontana:1000006", :unblock , "OK", FriendshipDeleted
|
134
|
+
it_should_behave_like "friendship state transition", "fontana:1000007", :unblock , "OK", FriendshipBlocked_l
|
135
|
+
it_should_behave_like "friendship state transition", "fontana:1000008", :unblock , "OK", FriendshipBlocked_l
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Libgss::ActionRequest do
|
5
|
+
|
6
|
+
let(:network) do
|
7
|
+
network = Libgss::Network.new("http://localhost:3000")
|
8
|
+
network.player_id = "1000001"
|
9
|
+
network.login
|
10
|
+
network
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:request) do
|
14
|
+
network.new_action_request
|
15
|
+
end
|
16
|
+
|
17
|
+
expected_game_data_1000001 = {
|
18
|
+
"content"=>{
|
19
|
+
"hp"=>15,
|
20
|
+
"max_hp"=>15,
|
21
|
+
"mp"=>5,
|
22
|
+
"max_mp"=>5,
|
23
|
+
"exp"=>100,
|
24
|
+
"money"=>200,
|
25
|
+
"items"=>{"20001"=>3, "20005"=>1},
|
26
|
+
"equipments"=>{"head"=>10018, "body"=>10012, "right_hand"=>10001, "left_hand"=>nil}
|
27
|
+
},
|
28
|
+
"greeting_points"=>0,
|
29
|
+
"login_bonus"=>[[10001, 1]],
|
30
|
+
"invitation_code"=>nil,
|
31
|
+
"invite_player"=>nil,
|
32
|
+
"read_notifications"=>[]
|
33
|
+
}
|
34
|
+
|
35
|
+
describe "#get_by_game_data" do
|
36
|
+
before do
|
37
|
+
request_fixture_load("01_basic")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "basic call" do
|
41
|
+
callback_called = false
|
42
|
+
request.get_by_game_data
|
43
|
+
request.send_request do |outputs|
|
44
|
+
callback_called = true
|
45
|
+
outputs.length.should == 1
|
46
|
+
game_data = outputs.first["result"]
|
47
|
+
# AppSeedで定義されているデータの確認
|
48
|
+
# game_data.select!{|k,v| expected_game_data_1000001.keys.include?(k) }
|
49
|
+
game_data.should == expected_game_data_1000001
|
50
|
+
end
|
51
|
+
callback_called.should == true
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#update" do
|
57
|
+
it "basic call" do
|
58
|
+
callback_called = false
|
59
|
+
request.get_by_game_data
|
60
|
+
request.send_request # コールバックなしでもOK
|
61
|
+
request.outputs.length.should == 1
|
62
|
+
game_data = request.outputs.first["result"]
|
63
|
+
new_content_attrs = {"hp" => 10, "mp" => 3, "exp" => 120, "money" => 220}
|
64
|
+
game_data["content"].update(new_content_attrs)
|
65
|
+
#
|
66
|
+
req1 = network.new_action_request
|
67
|
+
req1.update("GameData", game_data)
|
68
|
+
req1.send_request
|
69
|
+
req1.outputs.first["result"].should == "OK"
|
70
|
+
#
|
71
|
+
req2 = network.new_action_request
|
72
|
+
req2.get_by_game_data
|
73
|
+
req2.send_request
|
74
|
+
content = expected_game_data_1000001["content"].dup
|
75
|
+
content.update(new_content_attrs)
|
76
|
+
req2.outputs.first["result"]["content"].should == content
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Libgss::ActionRequest do
|
5
|
+
|
6
|
+
let(:network) do
|
7
|
+
network = Libgss::Network.new("http://localhost:3000")
|
8
|
+
network.player_id = "1000001"
|
9
|
+
network
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:request) do
|
13
|
+
network.login
|
14
|
+
network.new_action_request
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
describe "#get_by_int_range" do
|
19
|
+
shared_examples_for "Libgss::ActionRequest#get_by_int_range" do |input, output, conditions|
|
20
|
+
it do
|
21
|
+
callback_called = false
|
22
|
+
request.get_by_int_range("RequiredExperience", input, conditions)
|
23
|
+
request.send_request do |outputs|
|
24
|
+
callback_called = true
|
25
|
+
outputs.length.should == 1
|
26
|
+
outputs.first["result"].should == output
|
27
|
+
end
|
28
|
+
callback_called.should == true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it_should_behave_like "Libgss::ActionRequest#get_by_int_range", 0, 1, nil
|
33
|
+
it_should_behave_like "Libgss::ActionRequest#get_by_int_range", 9, 1, nil
|
34
|
+
it_should_behave_like "Libgss::ActionRequest#get_by_int_range", 10, 2, nil
|
35
|
+
it_should_behave_like "Libgss::ActionRequest#get_by_int_range", 24, 2, nil
|
36
|
+
it_should_behave_like "Libgss::ActionRequest#get_by_int_range", 25, 3, nil
|
37
|
+
|
38
|
+
cond = {"value$gte" => 10 }
|
39
|
+
it_should_behave_like "Libgss::ActionRequest#get_by_int_range", 0, nil, cond
|
40
|
+
it_should_behave_like "Libgss::ActionRequest#get_by_int_range", 9, nil, cond
|
41
|
+
it_should_behave_like "Libgss::ActionRequest#get_by_int_range", 10, nil, cond
|
42
|
+
it_should_behave_like "Libgss::ActionRequest#get_by_int_range", 24, nil, cond
|
43
|
+
it_should_behave_like "Libgss::ActionRequest#get_by_int_range", 25, nil, cond
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Libgss::ActionRequest do
|
5
|
+
|
6
|
+
let(:network) do
|
7
|
+
network = Libgss::Network.new("http://localhost:3000")
|
8
|
+
network.player_id = "1000001"
|
9
|
+
network
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:request) do
|
13
|
+
network.login
|
14
|
+
network.new_action_request
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
describe "log#create" do
|
19
|
+
it "valid" do
|
20
|
+
callback_called = false
|
21
|
+
# player_id, created_atはサーバで設定されます。
|
22
|
+
request.create("ItemIncomingLog", {"level" => 1, "item_cd" => 10001, "incoming_route_cd" => 1, "amount" => 2})
|
23
|
+
request.send_request do |outputs|
|
24
|
+
callback_called = true
|
25
|
+
outputs.length.should == 1
|
26
|
+
outputs.first["result"].should == "OK"
|
27
|
+
end
|
28
|
+
callback_called.should == true
|
29
|
+
end
|
30
|
+
|
31
|
+
shared_examples_for "log#create invalid" do |error_code, attrs|
|
32
|
+
it "with additional field" do
|
33
|
+
callback_called = false
|
34
|
+
request.create("ItemIncomingLog", attrs)
|
35
|
+
request.send_request do |outputs|
|
36
|
+
callback_called = true
|
37
|
+
outputs.length.should == 1
|
38
|
+
error = outputs.first["error"]
|
39
|
+
error.should_not be_nil
|
40
|
+
error["message"].should =~ /^#{error_code}\:/
|
41
|
+
error["input"].should == {
|
42
|
+
"id" => 1,
|
43
|
+
"name" => "ItemIncomingLog",
|
44
|
+
"attrs" => attrs,
|
45
|
+
"action"=>"create"
|
46
|
+
}
|
47
|
+
outputs.first["id"].should == 1
|
48
|
+
outputs.first["result"].should == nil
|
49
|
+
end
|
50
|
+
callback_called.should == true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it_should_behave_like "log#create invalid", 1004, {"level" => 1, "item_cd" => 10001, "incoming_route_cd" => 1, "amount" => 2, "extra_field" => 100}
|
55
|
+
it_should_behave_like "log#create invalid", 1005, {"level" => 1, "item_cd" => 10001, "incoming_route_cd" => 1} # 必須のフィールドamountがないのでエラー
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Libgss::ActionRequest do
|
5
|
+
|
6
|
+
let(:network) do
|
7
|
+
network = Libgss::Network.new("http://localhost:3000")
|
8
|
+
network.player_id = "1000001"
|
9
|
+
network
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:request) do
|
13
|
+
network.login
|
14
|
+
network.new_action_request
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#find_all" do
|
18
|
+
it "basic call" do
|
19
|
+
callback_called = false
|
20
|
+
request.find_all("Item")
|
21
|
+
request.send_request do |outputs|
|
22
|
+
callback_called = true
|
23
|
+
outputs.length.should == 1
|
24
|
+
items = outputs.first["result"]
|
25
|
+
items.length.should == 12
|
26
|
+
items.each do |item|
|
27
|
+
item["item_cd"].should_not == nil
|
28
|
+
item["name"].should_not == nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
callback_called.should == true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "with conditions" do
|
35
|
+
callback_called = false
|
36
|
+
request.find_all("Item", {"item_cd$gte" => 20005, "item_cd$lte" => 20008})
|
37
|
+
request.send_request do |outputs|
|
38
|
+
callback_called = true
|
39
|
+
outputs.length.should == 1
|
40
|
+
items = outputs.first["result"]
|
41
|
+
items.length.should == 4
|
42
|
+
items.each do |item|
|
43
|
+
item["item_cd"].should_not == nil
|
44
|
+
item["name"].should_not == nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
callback_called.should == true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "with order and conditions" do
|
51
|
+
callback_called = false
|
52
|
+
request.find_all("Item", {"item_cd$gte" => 20005, "item_cd$lte" => 20008}, [["item_cd", "desc"]])
|
53
|
+
request.send_request do |outputs|
|
54
|
+
callback_called = true
|
55
|
+
outputs.length.should == 1
|
56
|
+
items = outputs.first["result"]
|
57
|
+
items.length.should == 4
|
58
|
+
items.map{|item| item["item_cd"]}.should == [20008, 20007, 20006, 20005]
|
59
|
+
end
|
60
|
+
callback_called.should == true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#paginate" do
|
65
|
+
it "with pagination" do
|
66
|
+
callback_called = false
|
67
|
+
request.paginate("Item", 2, 5, nil, [["item_cd", "desc"]])
|
68
|
+
request.send_request do |outputs|
|
69
|
+
callback_called = true
|
70
|
+
outputs.length.should == 1
|
71
|
+
items = outputs.first["result"]
|
72
|
+
items.length.should == 5
|
73
|
+
items.map{|item| item["item_cd"]}.should == [20007, 20006, 20005, 20004, 20003]
|
74
|
+
end
|
75
|
+
callback_called.should == true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#count" do
|
80
|
+
it "no option" do
|
81
|
+
callback_called = false
|
82
|
+
request.count("Item")
|
83
|
+
request.send_request do |outputs|
|
84
|
+
callback_called = true
|
85
|
+
outputs.length.should == 1
|
86
|
+
outputs.first["result"].should == 12
|
87
|
+
end
|
88
|
+
callback_called.should == true
|
89
|
+
end
|
90
|
+
|
91
|
+
it "with conditions" do
|
92
|
+
callback_called = false
|
93
|
+
request.count("Item", {"item_cd$gte" => 20005, "item_cd$lte" => 20008})
|
94
|
+
request.send_request do |outputs|
|
95
|
+
callback_called = true
|
96
|
+
outputs.length.should == 1
|
97
|
+
outputs.first["result"].should == 4
|
98
|
+
end
|
99
|
+
callback_called.should == true
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#find_first" do
|
104
|
+
it "basic call" do
|
105
|
+
callback_called = false
|
106
|
+
request.find_first("Item")
|
107
|
+
request.send_request do |outputs|
|
108
|
+
callback_called = true
|
109
|
+
outputs.length.should == 1
|
110
|
+
item = outputs.first["result"]
|
111
|
+
item["item_cd"].should == 20001
|
112
|
+
end
|
113
|
+
callback_called.should == true
|
114
|
+
end
|
115
|
+
|
116
|
+
it "with conditions" do
|
117
|
+
callback_called = false
|
118
|
+
request.find_first("Item", {"item_cd$gte" => 20005, "item_cd$lte" => 20008})
|
119
|
+
request.send_request do |outputs|
|
120
|
+
callback_called = true
|
121
|
+
outputs.length.should == 1
|
122
|
+
item = outputs.first["result"]
|
123
|
+
item["item_cd"].should == 20005
|
124
|
+
end
|
125
|
+
callback_called.should == true
|
126
|
+
end
|
127
|
+
|
128
|
+
it "with order and conditions" do
|
129
|
+
callback_called = false
|
130
|
+
request.find_first("Item", {"item_cd$gte" => 20005, "item_cd$lte" => 20008}, [["item_cd", "desc"]])
|
131
|
+
request.send_request do |outputs|
|
132
|
+
callback_called = true
|
133
|
+
outputs.length.should == 1
|
134
|
+
item = outputs.first["result"]
|
135
|
+
item["item_cd"].should == 20008
|
136
|
+
end
|
137
|
+
callback_called.should == true
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|