Skip to content

Commit 66447dc

Browse files
committed
Add all remaining struct specs
1 parent 8389097 commit 66447dc

17 files changed

+381
-19
lines changed

spec/steam_api/structs/app_details/details_spec.rb

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,66 @@
33
RSpec.describe SteamApi::Structs::AppDetails::Details do
44
subject { described_class.new(params) }
55

6-
pending "TODO"
6+
describe "#initialize" do
7+
let(:params) do
8+
{
9+
appid: 400,
10+
response: {
11+
success: true,
12+
data: {
13+
type: "game",
14+
name: "Portal",
15+
required_age: 0,
16+
is_free: false,
17+
developers: ["Valve"],
18+
publishers: ["Valve"],
19+
price_overview: {
20+
currency: "USD",
21+
initial: 999,
22+
final: 499,
23+
discount_percent: 50,
24+
initial_formatted: "$9.99",
25+
final_formatted: "$4.99"
26+
}
27+
}
28+
}
29+
}
30+
end
31+
32+
context "when the params are present" do
33+
it { is_expected.to have_attributes(appid: 400) }
34+
35+
it do
36+
is_expected.to have_attributes(
37+
response: have_attributes(
38+
success: true,
39+
data: have_attributes(
40+
type: "game",
41+
name: "Portal",
42+
required_age: 0,
43+
is_free: false,
44+
developers: contain_exactly("Valve"),
45+
publishers: contain_exactly("Valve"),
46+
price_overview: have_attributes(
47+
currency: "USD",
48+
initial: 999,
49+
final: 499,
50+
discount_percent: 50,
51+
initial_formatted: "$9.99",
52+
final_formatted: "$4.99"
53+
)
54+
)
55+
)
56+
)
57+
end
58+
end
59+
60+
context "when the params are missing" do
61+
let(:params) { {} }
62+
63+
it "raises a Dry::Struct::Error" do
64+
expect { subject }.to raise_error(Dry::Struct::Error)
65+
end
66+
end
67+
end
768
end

spec/steam_api/structs/app_details/package_group_spec.rb

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,41 @@
33
RSpec.describe SteamApi::Structs::AppDetails::PackageGroup do
44
subject { described_class.new(params) }
55

6-
pending "TODO"
6+
describe "#initialize" do
7+
let(:params) do
8+
{
9+
name: "Special Offers",
10+
title: "Discounted Packages",
11+
description: "Limited time offers",
12+
selection_text: "Choose your package",
13+
save_text: "Save big!",
14+
display_type: 1,
15+
is_recurring_subscription: "No",
16+
subs: [
17+
SteamApi::Structs::AppDetails::Sub.new(
18+
packageid: 12345,
19+
percent_savings_text: "50%",
20+
percent_savings: 50,
21+
option_text: "Buy Now",
22+
option_description: "Special offer",
23+
can_get_free_license: "No",
24+
is_free_license: false,
25+
price_in_cents_with_discount: 4999
26+
)
27+
]
28+
}
29+
end
30+
31+
context "when the params are present" do
32+
it { is_expected.to have_attributes(**params) }
33+
end
34+
35+
context "when the params are missing" do
36+
let(:params) { {} }
37+
38+
it "raises a Dry::Struct::Error" do
39+
expect { subject }.to raise_error(Dry::Struct::Error)
40+
end
41+
end
42+
end
743
end

spec/steam_api/structs/app_details/sub_spec.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,30 @@
33
RSpec.describe SteamApi::Structs::AppDetails::Sub do
44
subject { described_class.new(params) }
55

6-
pending "TODO"
6+
describe "#initialize" do
7+
let(:params) do
8+
{
9+
packageid: 12345,
10+
percent_savings_text: "50%",
11+
percent_savings: 50,
12+
option_text: "Buy Now",
13+
option_description: "Special offer",
14+
can_get_free_license: "No",
15+
is_free_license: false,
16+
price_in_cents_with_discount: 4999
17+
}
18+
end
19+
20+
context "when the params are present" do
21+
it { is_expected.to have_attributes(**params) }
22+
end
23+
24+
context "when the params are missing" do
25+
let(:params) { {} }
26+
27+
it "raises a Dry::Struct::Error" do
28+
expect { subject }.to raise_error(Dry::Struct::Error)
29+
end
30+
end
31+
end
732
end
Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
require "spec_helper"
22

33
RSpec.describe SteamApi::Structs::Requests::Abstract do
4-
subject { described_class.new(params) }
4+
let(:subclass) do
5+
Class.new(described_class) do
6+
def version
7+
"v1"
8+
end
59

6-
pending "TODO"
10+
def interface
11+
"TestInterface"
12+
end
13+
14+
def path
15+
"test_path"
16+
end
17+
end
18+
end
19+
20+
subject { subclass.new }
21+
22+
describe "#initialize" do
23+
it "raises an error when instantiated directly" do
24+
expect { described_class.new.version }.to raise_error(NoMethodError, /Override this method/)
25+
end
26+
27+
it "does not raise an error when instantiated as a subclass" do
28+
expect { subject }.not_to raise_error
29+
end
30+
end
731
end

spec/steam_api/structs/requests/get_app_details_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,19 @@
33
RSpec.describe SteamApi::Structs::Requests::GetAppDetails do
44
subject { described_class.new(params) }
55

6-
pending "TODO"
6+
describe "#initialize" do
7+
let(:params) { {appid: 12345, filters: [], cc: "US", l: "en"} }
8+
9+
it "initializes with the given appid and other parameters" do
10+
expect(subject).to have_attributes(appid: 12345, filters: [], cc: "US", l: "en")
11+
end
12+
13+
context "when appid is missing" do
14+
let(:params) { {filters: [], cc: "US", l: "en"} }
15+
16+
it "raises an error" do
17+
expect { subject }.to raise_error(Dry::Struct::Error)
18+
end
19+
end
20+
end
721
end

spec/steam_api/structs/requests/get_app_global_achievements_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,19 @@
33
RSpec.describe SteamApi::Structs::Requests::GetAppGlobalAchievements do
44
subject { described_class.new(params) }
55

6-
pending "TODO"
6+
describe "#initialize" do
7+
let(:params) { {gameid: 12345} }
8+
9+
it "initializes with the given gameid" do
10+
expect(subject).to have_attributes(gameid: 12345)
11+
end
12+
13+
context "when gameid is missing" do
14+
let(:params) { {} }
15+
16+
it "raises an error" do
17+
expect { subject }.to raise_error(Dry::Struct::Error)
18+
end
19+
end
20+
end
721
end

spec/steam_api/structs/requests/get_app_news_spec.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,27 @@
33
RSpec.describe SteamApi::Structs::Requests::GetAppNews do
44
subject { described_class.new(params) }
55

6-
pending "TODO"
6+
describe "#initialize" do
7+
let(:params) { {appid: 12345, count: 5, maxlength: 300} }
8+
9+
it "initializes with the given appid, count, and maxlength" do
10+
expect(subject).to have_attributes(appid: 12345, count: 5, maxlength: 300)
11+
end
12+
13+
context "when maxlength is missing" do
14+
let(:params) { {appid: 12345, count: 5} }
15+
16+
it "raises an error" do
17+
expect { subject }.to raise_error(Dry::Struct::Error)
18+
end
19+
end
20+
21+
context "when parameters are missing" do
22+
let(:params) { {} }
23+
24+
it "raises an error" do
25+
expect { subject }.to raise_error(Dry::Struct::Error)
26+
end
27+
end
28+
end
729
end

spec/steam_api/structs/requests/get_game_current_players_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,19 @@
33
RSpec.describe SteamApi::Structs::Requests::GetGameCurrentPlayers do
44
subject { described_class.new(params) }
55

6-
pending "TODO"
6+
describe "#initialize" do
7+
let(:params) { {appid: 12345} }
8+
9+
it "initializes with the given appid" do
10+
expect(subject).to have_attributes(appid: 12345)
11+
end
12+
13+
context "when appid is missing" do
14+
let(:params) { {} }
15+
16+
it "raises an error" do
17+
expect { subject }.to raise_error(Dry::Struct::Error)
18+
end
19+
end
20+
end
721
end

spec/steam_api/structs/requests/get_player_achievements_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,19 @@
33
RSpec.describe SteamApi::Structs::Requests::GetPlayerAchievements do
44
subject { described_class.new(params) }
55

6-
pending "TODO"
6+
describe "#initialize" do
7+
let(:params) { {steamid: "123456789", appid: 12345} }
8+
9+
it "initializes with the given steamid and appid" do
10+
expect(subject).to have_attributes(steamid: "123456789", appid: 12345)
11+
end
12+
13+
context "when parameters are missing" do
14+
let(:params) { {} }
15+
16+
it "raises an error" do
17+
expect { subject }.to raise_error(Dry::Struct::Error)
18+
end
19+
end
20+
end
721
end

spec/steam_api/structs/requests/get_player_friends_spec.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,27 @@
33
RSpec.describe SteamApi::Structs::Requests::GetPlayerFriends do
44
subject { described_class.new(params) }
55

6-
pending "TODO"
6+
describe "#initialize" do
7+
let(:params) { {steamid: "123456789", relationship: "friend"} }
8+
9+
it "initializes with the given steamid and relationship" do
10+
expect(subject).to have_attributes(steamid: "123456789", relationship: "friend")
11+
end
12+
13+
context "when relationship is missing" do
14+
let(:params) { {steamid: "123456789"} }
15+
16+
it "raises an error" do
17+
expect { subject }.to raise_error(Dry::Struct::Error)
18+
end
19+
end
20+
21+
context "when steamid is missing" do
22+
let(:params) { {} }
23+
24+
it "raises an error" do
25+
expect { subject }.to raise_error(Dry::Struct::Error)
26+
end
27+
end
28+
end
729
end

0 commit comments

Comments
 (0)