rating-chgk-v2 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/CODE_OF_CONDUCT.md +46 -0
- data/.github/CONTRIBUTING.md +14 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +11 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +5 -0
- data/README.md +60 -0
- data/Rakefile +21 -0
- data/lib/rating_chgk_v2/client.rb +16 -0
- data/lib/rating_chgk_v2/collections/base_collection.rb +48 -0
- data/lib/rating_chgk_v2/collections/countries_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/player_seasons_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/player_tournaments_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/players_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/regions_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/releases_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/seasons_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/team_tournaments_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/teams_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/tournament_appeals_collection.rb +9 -0
- data/lib/rating_chgk_v2/collections/tournament_flags_collection.rb +9 -0
- data/lib/rating_chgk_v2/collections/tournament_requests_collection.rb +9 -0
- data/lib/rating_chgk_v2/collections/tournament_results_collection.rb +9 -0
- data/lib/rating_chgk_v2/collections/tournament_types_collection.rb +9 -0
- data/lib/rating_chgk_v2/collections/tournaments_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/towns_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/venue_types_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/venues_collection.rb +11 -0
- data/lib/rating_chgk_v2/concerns/paginated.rb +31 -0
- data/lib/rating_chgk_v2/connection.rb +33 -0
- data/lib/rating_chgk_v2/data/authentication_token.yml +1 -0
- data/lib/rating_chgk_v2/data/country.yml +2 -0
- data/lib/rating_chgk_v2/data/player.yml +4 -0
- data/lib/rating_chgk_v2/data/player_season.yml +6 -0
- data/lib/rating_chgk_v2/data/player_tournament.yml +3 -0
- data/lib/rating_chgk_v2/data/region.yml +3 -0
- data/lib/rating_chgk_v2/data/release.yml +4 -0
- data/lib/rating_chgk_v2/data/season.yml +3 -0
- data/lib/rating_chgk_v2/data/team.yml +3 -0
- data/lib/rating_chgk_v2/data/team_tournament.yml +2 -0
- data/lib/rating_chgk_v2/data/tournament.yml +20 -0
- data/lib/rating_chgk_v2/data/tournament_flag.yml +3 -0
- data/lib/rating_chgk_v2/data/tournament_result.yml +10 -0
- data/lib/rating_chgk_v2/data/tournament_synch_appeal.yml +10 -0
- data/lib/rating_chgk_v2/data/tournament_synch_controversial.yml +8 -0
- data/lib/rating_chgk_v2/data/tournament_synch_request.yml +8 -0
- data/lib/rating_chgk_v2/data/tournament_type.yml +2 -0
- data/lib/rating_chgk_v2/data/town.yml +4 -0
- data/lib/rating_chgk_v2/data/venue.yml +6 -0
- data/lib/rating_chgk_v2/data/venue_type.yml +2 -0
- data/lib/rating_chgk_v2/endpoints/authentication_token_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/base_endpoint.rb +58 -0
- data/lib/rating_chgk_v2/endpoints/countries_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/players_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/regions_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/releases_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/seasons_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/teams_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/tournament_flags_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/tournament_synch_appeals_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/tournament_synch_controversials_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/tournament_synch_requests_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/tournament_types_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/tournaments_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/towns_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/venue_types_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/venues_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/error.rb +52 -0
- data/lib/rating_chgk_v2/json_handler.rb +19 -0
- data/lib/rating_chgk_v2/models/authentication_token_model.rb +8 -0
- data/lib/rating_chgk_v2/models/base_model.rb +38 -0
- data/lib/rating_chgk_v2/models/country_model.rb +16 -0
- data/lib/rating_chgk_v2/models/player_model.rb +17 -0
- data/lib/rating_chgk_v2/models/player_season_model.rb +8 -0
- data/lib/rating_chgk_v2/models/player_tournament_model.rb +8 -0
- data/lib/rating_chgk_v2/models/region_model.rb +8 -0
- data/lib/rating_chgk_v2/models/release_model.rb +8 -0
- data/lib/rating_chgk_v2/models/season_model.rb +16 -0
- data/lib/rating_chgk_v2/models/team_model.rb +17 -0
- data/lib/rating_chgk_v2/models/team_tournament_model.rb +8 -0
- data/lib/rating_chgk_v2/models/tournament_flag_model.rb +8 -0
- data/lib/rating_chgk_v2/models/tournament_model.rb +22 -0
- data/lib/rating_chgk_v2/models/tournament_result_model.rb +8 -0
- data/lib/rating_chgk_v2/models/tournament_synch_appeal_model.rb +8 -0
- data/lib/rating_chgk_v2/models/tournament_synch_controversial_model.rb +8 -0
- data/lib/rating_chgk_v2/models/tournament_synch_request_model.rb +8 -0
- data/lib/rating_chgk_v2/models/tournament_type_model.rb +8 -0
- data/lib/rating_chgk_v2/models/town_model.rb +8 -0
- data/lib/rating_chgk_v2/models/venue_model.rb +16 -0
- data/lib/rating_chgk_v2/models/venue_type_model.rb +8 -0
- data/lib/rating_chgk_v2/request.rb +58 -0
- data/lib/rating_chgk_v2/rest/authentication_token.rb +11 -0
- data/lib/rating_chgk_v2/rest/countries.rb +27 -0
- data/lib/rating_chgk_v2/rest/players.rb +23 -0
- data/lib/rating_chgk_v2/rest/regions.rb +15 -0
- data/lib/rating_chgk_v2/rest/releases.rb +15 -0
- data/lib/rating_chgk_v2/rest/seasons.rb +27 -0
- data/lib/rating_chgk_v2/rest/teams.rb +23 -0
- data/lib/rating_chgk_v2/rest/tournament_flags.rb +15 -0
- data/lib/rating_chgk_v2/rest/tournament_synch_appeals.rb +11 -0
- data/lib/rating_chgk_v2/rest/tournament_synch_controversials.rb +11 -0
- data/lib/rating_chgk_v2/rest/tournament_synch_requests.rb +11 -0
- data/lib/rating_chgk_v2/rest/tournament_types.rb +15 -0
- data/lib/rating_chgk_v2/rest/tournaments.rb +27 -0
- data/lib/rating_chgk_v2/rest/towns.rb +15 -0
- data/lib/rating_chgk_v2/rest/venue_types.rb +19 -0
- data/lib/rating_chgk_v2/rest/venues.rb +27 -0
- data/lib/rating_chgk_v2/rest.rb +45 -0
- data/lib/rating_chgk_v2/utils/string_utils.rb +28 -0
- data/lib/rating_chgk_v2/version.rb +5 -0
- data/lib/rating_chgk_v2.rb +22 -0
- data/rating-chgk-v2.gemspec +47 -0
- data/spec/lib/rating_chgk_v2/collections/base_collection_spec.rb +53 -0
- data/spec/lib/rating_chgk_v2/collections/countries_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/player_seasons_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/player_tournaments_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/players_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/regions_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/releases_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/seasons_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/teams_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/tournaments_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/towns_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/venue_types_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/venues_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/connection_spec.rb +22 -0
- data/spec/lib/rating_chgk_v2/endpoints/base_endpoint_spec.rb +15 -0
- data/spec/lib/rating_chgk_v2/error_spec.rb +11 -0
- data/spec/lib/rating_chgk_v2/models/country_model_spec.rb +30 -0
- data/spec/lib/rating_chgk_v2/models/player_model_spec.rb +59 -0
- data/spec/lib/rating_chgk_v2/models/season_model_spec.rb +36 -0
- data/spec/lib/rating_chgk_v2/models/team_model_spec.rb +35 -0
- data/spec/lib/rating_chgk_v2/models/tournament_model_spec.rb +38 -0
- data/spec/lib/rating_chgk_v2/models/venue_model_spec.rb +30 -0
- data/spec/lib/rating_chgk_v2/rest/authentication_token_spec.rb +19 -0
- data/spec/lib/rating_chgk_v2/rest/countries_spec.rb +94 -0
- data/spec/lib/rating_chgk_v2/rest/players_spec.rb +126 -0
- data/spec/lib/rating_chgk_v2/rest/regions_spec.rb +37 -0
- data/spec/lib/rating_chgk_v2/rest/releases_spec.rb +34 -0
- data/spec/lib/rating_chgk_v2/rest/seasons_spec.rb +71 -0
- data/spec/lib/rating_chgk_v2/rest/teams_spec.rb +66 -0
- data/spec/lib/rating_chgk_v2/rest/tournament_flags_spec.rb +27 -0
- data/spec/lib/rating_chgk_v2/rest/tournament_synch_appeals_spec.rb +22 -0
- data/spec/lib/rating_chgk_v2/rest/tournament_synch_controversials_spec.rb +20 -0
- data/spec/lib/rating_chgk_v2/rest/tournament_synch_requests_spec.rb +20 -0
- data/spec/lib/rating_chgk_v2/rest/tournament_types_spec.rb +23 -0
- data/spec/lib/rating_chgk_v2/rest/tournaments_spec.rb +89 -0
- data/spec/lib/rating_chgk_v2/rest/towns_spec.rb +35 -0
- data/spec/lib/rating_chgk_v2/rest/venue_types_spec.rb +46 -0
- data/spec/lib/rating_chgk_v2/rest/venues_spec.rb +71 -0
- data/spec/lib/rating_chgk_v2_spec.rb +9 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/support/shared/paginated.rb +41 -0
- data/spec/support/test_client.rb +7 -0
- data/spec/support/vcr.rb +15 -0
- metadata +455 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Connection do
|
4
|
+
let(:dummy) { Class.new { include RatingChgkV2::Connection }.new }
|
5
|
+
|
6
|
+
before { RatingChgkV2.reset_client! }
|
7
|
+
|
8
|
+
after { RatingChgkV2.reset_client! }
|
9
|
+
|
10
|
+
it 'allows to customize timeouts' do
|
11
|
+
custom_client = RatingChgkV2.client(params: {open_timeout: 100, timeout: 500})
|
12
|
+
conn = dummy.connection custom_client
|
13
|
+
expect(conn.options.timeout).to eq(500)
|
14
|
+
expect(conn.options.open_timeout).to eq(100)
|
15
|
+
|
16
|
+
custom_client.timeout = 300
|
17
|
+
custom_client.open_timeout = 200
|
18
|
+
another_conn = dummy.connection custom_client
|
19
|
+
expect(another_conn.options.timeout).to eq(300)
|
20
|
+
expect(another_conn.options.open_timeout).to eq(200)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Endpoints::BaseEndpoint do
|
4
|
+
subject { described_class.new test_client }
|
5
|
+
|
6
|
+
let(:endpoint) { subject }
|
7
|
+
|
8
|
+
it { is_expected.to respond_to(:do_get) }
|
9
|
+
it { is_expected.to respond_to(:do_post) }
|
10
|
+
it { is_expected.not_to respond_to(:very_wrong_method) }
|
11
|
+
|
12
|
+
it 'raises an error when calling invalid methods' do
|
13
|
+
expect { endpoint.very_wrong_method }.to raise_error(NoMethodError)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Error do
|
4
|
+
it 'raises NotFound for 404 status code' do
|
5
|
+
expect do
|
6
|
+
VCR.use_cassette('error/error_404') do
|
7
|
+
test_client.player(3)
|
8
|
+
end
|
9
|
+
end.to raise_error(RatingChgkV2::Error::NotFound)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Models::CountryModel do
|
4
|
+
let!(:country) do
|
5
|
+
VCR.use_cassette('countries/country') do
|
6
|
+
test_client.country 20
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
specify '#update' do
|
11
|
+
stub_request(:put, 'https://api.rating.chgk.net/countries/20').
|
12
|
+
with(body: {name: 'Обновлённая страна'}).
|
13
|
+
to_return(
|
14
|
+
status: 200,
|
15
|
+
body: '{"id":20,"name":"Обновлённая страна"}',
|
16
|
+
headers: {}
|
17
|
+
)
|
18
|
+
|
19
|
+
updated_country = country.update name: 'Обновлённая страна'
|
20
|
+
expect(updated_country).to be_an_instance_of(described_class)
|
21
|
+
expect(updated_country.name).to eq('Обновлённая страна')
|
22
|
+
expect(updated_country.id).to eq(20)
|
23
|
+
end
|
24
|
+
|
25
|
+
specify '#destroy' do
|
26
|
+
stub_request(:delete, 'https://api.rating.chgk.net/countries/20').to_return(status: 204, body: '', headers: {})
|
27
|
+
|
28
|
+
expect(country.destroy).to eq('')
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Models::PlayerModel do
|
4
|
+
let(:player) do
|
5
|
+
VCR.use_cassette('players/player') do
|
6
|
+
test_client.player(player_id)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:player_id) { 1110 }
|
11
|
+
|
12
|
+
describe '#seasons' do
|
13
|
+
it 'returns all seasons' do
|
14
|
+
player_seasons = VCR.use_cassette('players/player_seasons') do
|
15
|
+
player.seasons
|
16
|
+
end
|
17
|
+
|
18
|
+
expect(player_seasons).to be_an_instance_of(RatingChgkV2::Collections::PlayerSeasonsCollection)
|
19
|
+
season = player_seasons.first
|
20
|
+
|
21
|
+
expect(season.idplayer).to eq(player_id)
|
22
|
+
expect(season.idseason).to eq(7)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns seasons by params' do
|
26
|
+
season = VCR.use_cassette('players/player_seasons_params') do
|
27
|
+
player.seasons itemsPerPage: 2, idseason: 8, idteam: 7456
|
28
|
+
end.first
|
29
|
+
|
30
|
+
expect(season.idplayer).to eq(player_id)
|
31
|
+
expect(season.idseason).to eq(8)
|
32
|
+
expect(season.idteam).to eq(7456)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#tournaments' do
|
37
|
+
it 'returns all tournaments' do
|
38
|
+
player_tournaments = VCR.use_cassette('players/player_tournaments') do
|
39
|
+
player.tournaments
|
40
|
+
end
|
41
|
+
|
42
|
+
expect(player_tournaments).to be_an_instance_of(RatingChgkV2::Collections::PlayerTournamentsCollection)
|
43
|
+
tour = player_tournaments.first
|
44
|
+
|
45
|
+
expect(tour.idtournament).to eq(314)
|
46
|
+
expect(tour.idteam).to eq(7121)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns tournaments by params' do
|
50
|
+
tour = VCR.use_cassette('players/player_tournaments_params') do
|
51
|
+
player.tournaments itemsPerPage: 2
|
52
|
+
end.first
|
53
|
+
|
54
|
+
expect(tour.idplayer).to eq(player_id)
|
55
|
+
expect(tour.idtournament).to eq(314)
|
56
|
+
expect(tour.idteam).to eq(7121)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Models::SeasonModel do
|
4
|
+
let!(:season) do
|
5
|
+
VCR.use_cassette('seasons/season') do
|
6
|
+
test_client.season 5
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
specify '#update' do
|
11
|
+
data = {
|
12
|
+
dateStart: '2021-02-05T19:37:45.004Z',
|
13
|
+
dateEnd: '2021-02-05T19:37:45.004Z'
|
14
|
+
}
|
15
|
+
|
16
|
+
stub_request(:put, 'https://api.rating.chgk.net/seasons/5').
|
17
|
+
with(body: data).
|
18
|
+
to_return(
|
19
|
+
status: 200,
|
20
|
+
body: JSON.dump(data.merge({id: season.id})),
|
21
|
+
headers: {}
|
22
|
+
)
|
23
|
+
|
24
|
+
updated_season = season.update data
|
25
|
+
expect(updated_season).to be_an_instance_of(described_class)
|
26
|
+
expect(updated_season.id).to eq(5)
|
27
|
+
expect(updated_season.dateStart).to eq(data[:dateStart])
|
28
|
+
expect(updated_season.dateEnd).to eq(data[:dateEnd])
|
29
|
+
end
|
30
|
+
|
31
|
+
specify '#destroy' do
|
32
|
+
stub_request(:delete, 'https://api.rating.chgk.net/seasons/5').to_return(status: 204, body: '', headers: {})
|
33
|
+
|
34
|
+
expect(season.destroy).to eq('')
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Models::TeamModel do
|
4
|
+
let(:team_id) { 2 }
|
5
|
+
let(:team) do
|
6
|
+
VCR.use_cassette('teams/team') do
|
7
|
+
test_client.team(team_id)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#seasons' do
|
12
|
+
it 'returns seasons by params' do
|
13
|
+
season = VCR.use_cassette('teams/team_seasons_params') do
|
14
|
+
team.seasons idseason: 9
|
15
|
+
end.first
|
16
|
+
|
17
|
+
expect(season).to be_an_instance_of(RatingChgkV2::Models::PlayerSeasonModel)
|
18
|
+
expect(season.idplayer).to eq(707)
|
19
|
+
expect(season.idseason).to eq(9)
|
20
|
+
expect(season.idteam).to eq(team_id)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#tournaments' do
|
25
|
+
it 'returns tournaments by params' do
|
26
|
+
tour = VCR.use_cassette('teams/team_tournaments_params') do
|
27
|
+
team.tournaments pagination: true
|
28
|
+
end[2]
|
29
|
+
|
30
|
+
expect(tour).to be_an_instance_of(RatingChgkV2::Models::TeamTournamentModel)
|
31
|
+
expect(tour.idtournament).to eq(8)
|
32
|
+
expect(tour.idteam).to eq(team_id)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Models::TournamentModel do
|
4
|
+
let(:tournament_id) { 7798 }
|
5
|
+
let(:tournament) do
|
6
|
+
VCR.use_cassette('tournaments/tournament') do
|
7
|
+
test_client.tournament(tournament_id)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
specify '#appeals' do
|
12
|
+
appeals = VCR.use_cassette('tournaments/appeals') do
|
13
|
+
tournament.appeals
|
14
|
+
end
|
15
|
+
|
16
|
+
expect(appeals[0].id).to eq(12_153)
|
17
|
+
expect(appeals[0].questionNumber).to eq(20)
|
18
|
+
end
|
19
|
+
|
20
|
+
specify '#requests' do
|
21
|
+
requests = VCR.use_cassette('tournaments/requests') do
|
22
|
+
tournament.requests
|
23
|
+
end
|
24
|
+
|
25
|
+
expect(requests[0].id).to eq(101_060)
|
26
|
+
expect(requests[0].status).to eq('A')
|
27
|
+
end
|
28
|
+
|
29
|
+
specify '#results' do
|
30
|
+
results = VCR.use_cassette('tournaments/results') do
|
31
|
+
tournament.results includeTeamMembers: 1, includeMasksAndControversials: 1,
|
32
|
+
includeTeamFlags: 1, includeRatingB: 1, town: 202
|
33
|
+
end.first
|
34
|
+
|
35
|
+
expect(results.team['id']).to eq(53_341)
|
36
|
+
expect(results.position).to eq(1)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Models::VenueModel do
|
4
|
+
let!(:venue) do
|
5
|
+
VCR.use_cassette('venues/venue') do
|
6
|
+
test_client.venue 3601
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
specify '#update' do
|
11
|
+
stub_request(:put, 'https://api.rating.chgk.net/venues/3601').
|
12
|
+
with(body: {name: 'Обновлённая'}).
|
13
|
+
to_return(
|
14
|
+
status: 201,
|
15
|
+
body: '{"id":3601,"name":"Обновлённая"}',
|
16
|
+
headers: {}
|
17
|
+
)
|
18
|
+
|
19
|
+
updated_venue = venue.update name: 'Обновлённая'
|
20
|
+
expect(updated_venue).to be_an_instance_of(described_class)
|
21
|
+
expect(updated_venue.name).to eq('Обновлённая')
|
22
|
+
expect(updated_venue.id).to eq(3601)
|
23
|
+
end
|
24
|
+
|
25
|
+
specify '#destroy' do
|
26
|
+
stub_request(:delete, 'https://api.rating.chgk.net/venues/3601').to_return(status: 204, body: '', headers: {})
|
27
|
+
|
28
|
+
expect(venue.destroy).to eq('')
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Rest::AuthenticationToken do
|
4
|
+
it 'raises 401 for incorrect email and password' do
|
5
|
+
expect do
|
6
|
+
VCR.use_cassette('authentication_token/token_401') do
|
7
|
+
test_client.authentication_token email: 'fake@example.com', password: '123'
|
8
|
+
end
|
9
|
+
end.to raise_error(RatingChgkV2::Error::Unauthorized)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns token for correct email and password' do
|
13
|
+
token_obj = VCR.use_cassette('authentication_token/token') do
|
14
|
+
test_client.authentication_token email: ENV['CHGK_EMAIL'], password: ENV['CHGK_PASSWORD']
|
15
|
+
end
|
16
|
+
|
17
|
+
expect(token_obj.token).to eq('stubbed_token')
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Rest::Countries do
|
4
|
+
describe '#countries' do
|
5
|
+
it 'returns a collection of countries' do
|
6
|
+
countries = VCR.use_cassette('countries/all_countries') do
|
7
|
+
test_client.countries
|
8
|
+
end
|
9
|
+
|
10
|
+
expect(countries[1].name).to eq('Австралия')
|
11
|
+
expect(countries[1].id).to eq(2)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns a collection of countries with params' do
|
15
|
+
countries = VCR.use_cassette('countries/all_countries_params') do
|
16
|
+
test_client.countries itemsPerPage: 2, name: 'Бе'
|
17
|
+
end
|
18
|
+
|
19
|
+
expect(countries.items.size).to eq(2)
|
20
|
+
expect(countries.first.name).to eq('Беларусь')
|
21
|
+
expect(countries.first.id).to eq(5)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#create_country' do
|
26
|
+
before { RatingChgkV2.reset_client! }
|
27
|
+
|
28
|
+
after { RatingChgkV2.reset_client! }
|
29
|
+
|
30
|
+
it 'raises an error when the token is invalid' do
|
31
|
+
custom_client = RatingChgkV2.client token: 'fake_token'
|
32
|
+
|
33
|
+
expect do
|
34
|
+
VCR.use_cassette('countries/create_country_incorrect_token') do
|
35
|
+
custom_client.create_country name: 'test'
|
36
|
+
end
|
37
|
+
end.to raise_error(RatingChgkV2::Error::Unauthorized)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'creates a country' do
|
41
|
+
stub_request(:post, 'https://api.rating.chgk.net/countries').
|
42
|
+
with(body: {name: 'Темерия'}).
|
43
|
+
to_return(
|
44
|
+
status: 200,
|
45
|
+
body: '{"id":0,"name":"Темерия"}',
|
46
|
+
headers: {}
|
47
|
+
)
|
48
|
+
|
49
|
+
country = test_client.create_country name: 'Темерия'
|
50
|
+
expect(country.name).to eq('Темерия')
|
51
|
+
expect(country.id).to eq(0)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
specify '#update_country' do
|
56
|
+
stub_request(:put, 'https://api.rating.chgk.net/countries/0').
|
57
|
+
with(body: {name: 'Лирия'}).
|
58
|
+
to_return(
|
59
|
+
status: 200,
|
60
|
+
body: '{"id":0,"name":"Лирия"}',
|
61
|
+
headers: {}
|
62
|
+
)
|
63
|
+
|
64
|
+
country = test_client.update_country 0, name: 'Лирия'
|
65
|
+
expect(country.name).to eq('Лирия')
|
66
|
+
expect(country.id).to eq(0)
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#delete_country' do
|
70
|
+
it 'raises an error when the token is invalid' do
|
71
|
+
expect do
|
72
|
+
VCR.use_cassette('countries/delete_country_incorrect_token') do
|
73
|
+
test_client.delete_country 1
|
74
|
+
end
|
75
|
+
end.to raise_error(RatingChgkV2::Error::Unauthorized)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'deletes a country' do
|
79
|
+
stub_request(:delete, 'https://api.rating.chgk.net/countries/1').to_return(status: 204, body: '', headers: {})
|
80
|
+
|
81
|
+
expect(test_client.delete_country(1)).to eq('')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
specify '#country' do
|
86
|
+
id = 20
|
87
|
+
country = VCR.use_cassette('countries/country') do
|
88
|
+
test_client.country id
|
89
|
+
end
|
90
|
+
|
91
|
+
expect(country.name).to eq('Нидерланды')
|
92
|
+
expect(country.id).to eq(id)
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Rest::Players do
|
4
|
+
let(:player_id) { 1110 }
|
5
|
+
|
6
|
+
specify '#player' do
|
7
|
+
player = VCR.use_cassette('players/player') do
|
8
|
+
test_client.player(player_id)
|
9
|
+
end
|
10
|
+
|
11
|
+
expect(player.id).to eq(player_id)
|
12
|
+
expect(player.name).to eq('Александр')
|
13
|
+
expect(player.surname).to eq('Андрианов')
|
14
|
+
expect(player.patronymic).to eq('Сергеевич')
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#player_tournaments' do
|
18
|
+
it 'returns a collection of player tournaments' do
|
19
|
+
player_tournaments = VCR.use_cassette('players/player_tournaments') do
|
20
|
+
test_client.player_tournaments player_id
|
21
|
+
end
|
22
|
+
|
23
|
+
expect(player_tournaments).to be_an_instance_of(RatingChgkV2::Collections::PlayerTournamentsCollection)
|
24
|
+
tour = player_tournaments.first
|
25
|
+
|
26
|
+
expect(tour.idplayer).to eq(player_id)
|
27
|
+
expect(tour.idtournament).to eq(314)
|
28
|
+
expect(tour.idteam).to eq(7121)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns a collection of player tournaments next page' do
|
32
|
+
player_tournaments = VCR.use_cassette('players/player_tournaments_params') do
|
33
|
+
test_client.player_tournaments player_id, itemsPerPage: 2
|
34
|
+
end
|
35
|
+
|
36
|
+
tour = player_tournaments[1]
|
37
|
+
|
38
|
+
expect(tour.idplayer).to eq(player_id)
|
39
|
+
expect(tour.idtournament).to eq(400)
|
40
|
+
expect(tour.idteam).to eq(7456)
|
41
|
+
|
42
|
+
VCR.use_cassette('players/player_tournaments_next_page') do
|
43
|
+
player_tournaments.next_page!
|
44
|
+
end
|
45
|
+
|
46
|
+
tour = player_tournaments[0]
|
47
|
+
|
48
|
+
expect(tour.idplayer).to eq(player_id)
|
49
|
+
expect(tour.idtournament).to eq(314)
|
50
|
+
expect(tour.idteam).to eq(7121)
|
51
|
+
expect(player_tournaments.endpoint.params[:itemsPerPage]).to eq(2)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#player_seasons' do
|
56
|
+
it 'returns a collection of player seasons' do
|
57
|
+
player_seasons = VCR.use_cassette('players/player_seasons') do
|
58
|
+
test_client.player_seasons player_id
|
59
|
+
end
|
60
|
+
|
61
|
+
expect(player_seasons).to be_an_instance_of(RatingChgkV2::Collections::PlayerSeasonsCollection)
|
62
|
+
season = player_seasons.first
|
63
|
+
|
64
|
+
expect(season.idplayer).to eq(player_id)
|
65
|
+
expect(season.idseason).to eq(7)
|
66
|
+
expect(season.idteam).to eq(7121)
|
67
|
+
expect(season.dateAdded).to eq('2007-09-23T00:00:00+04:00')
|
68
|
+
expect(season.dateRemoved).to be_nil
|
69
|
+
expect(season.playerNumber).to eq(0)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns seasons by params' do
|
73
|
+
player_seasons = VCR.use_cassette('players/player_seasons_params') do
|
74
|
+
test_client.player_seasons player_id, itemsPerPage: 2, idseason: 8, idteam: 7456
|
75
|
+
end
|
76
|
+
|
77
|
+
expect(player_seasons).to be_an_instance_of(RatingChgkV2::Collections::PlayerSeasonsCollection)
|
78
|
+
season = player_seasons.first
|
79
|
+
|
80
|
+
expect(season.idplayer).to eq(player_id)
|
81
|
+
expect(season.idseason).to eq(8)
|
82
|
+
expect(season.idteam).to eq(7456)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#players' do
|
87
|
+
it 'returns a collection of players' do
|
88
|
+
players = VCR.use_cassette('players/all_players') do
|
89
|
+
test_client.players
|
90
|
+
end
|
91
|
+
|
92
|
+
expect(players[0].surname).to eq('Абабилов')
|
93
|
+
expect(players[0].id).to eq(1)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'returns next page' do
|
97
|
+
players = VCR.use_cassette('players/all_players_params') do
|
98
|
+
test_client.players itemsPerPage: 3, page: 2
|
99
|
+
end
|
100
|
+
|
101
|
+
expect(players[0].name).to eq('Артур')
|
102
|
+
expect(players[0].id).to eq(12)
|
103
|
+
|
104
|
+
VCR.use_cassette('players/all_players_next_page') do
|
105
|
+
players.next_page!
|
106
|
+
end
|
107
|
+
|
108
|
+
expect(players[0].name).to eq('Олег')
|
109
|
+
expect(players[0].id).to eq(15)
|
110
|
+
expect(players.endpoint.params[:itemsPerPage]).to eq(3)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'returns previous page' do
|
114
|
+
players = VCR.use_cassette('players/all_players_params') do
|
115
|
+
test_client.players itemsPerPage: 3, page: 2
|
116
|
+
end
|
117
|
+
|
118
|
+
VCR.use_cassette('players/all_players_prev_page') do
|
119
|
+
players.prev_page!
|
120
|
+
end
|
121
|
+
|
122
|
+
expect(players[0].surname).to eq('Абабилов')
|
123
|
+
expect(players.endpoint.params[:itemsPerPage]).to eq(3)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Rest::Regions do
|
4
|
+
describe '#regions' do
|
5
|
+
it 'returns a collection of regions' do
|
6
|
+
regions = VCR.use_cassette('regions/all_regions') do
|
7
|
+
test_client.regions
|
8
|
+
end
|
9
|
+
|
10
|
+
expect(regions.last.name).to eq('Воронежская область')
|
11
|
+
expect(regions.last.id).to eq(30)
|
12
|
+
expect(regions.last.country['name']).to eq('Россия')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns a collection of regions with params' do
|
16
|
+
regions = VCR.use_cassette('regions/all_regions_params') do
|
17
|
+
test_client.regions itemsPerPage: 3, country: 'Россия'
|
18
|
+
end
|
19
|
+
|
20
|
+
expect(regions.items.size).to eq(3)
|
21
|
+
expect(regions[1].name).to eq('Адыгея')
|
22
|
+
expect(regions[1].country['name']).to eq('Россия')
|
23
|
+
expect(regions[1].id).to eq(2)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
specify '#region' do
|
28
|
+
id = 3
|
29
|
+
region = VCR.use_cassette('regions/region') do
|
30
|
+
test_client.region id
|
31
|
+
end
|
32
|
+
|
33
|
+
expect(region.name).to eq('Акмолинская область')
|
34
|
+
expect(region.country['name']).to eq('Казахстан')
|
35
|
+
expect(region.id).to eq(id)
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Rest::Releases do
|
4
|
+
describe '#releases' do
|
5
|
+
it 'returns a collection of releases' do
|
6
|
+
releases = VCR.use_cassette('releases/all_releases') do
|
7
|
+
test_client.releases
|
8
|
+
end
|
9
|
+
|
10
|
+
expect(releases.first.date).to eq('2003-07-01T00:00:00+04:00')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns a collection of releases with params' do
|
14
|
+
releases = VCR.use_cassette('releases/all_releases_params') do
|
15
|
+
test_client.releases itemsPerPage: 3, page: 2
|
16
|
+
end
|
17
|
+
|
18
|
+
expect(releases.items.size).to eq(3)
|
19
|
+
expect(releases.first.realDate).to eq('2005-04-01T00:00:00+04:00')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
specify '#release' do
|
24
|
+
id = 4
|
25
|
+
release = VCR.use_cassette('releases/release') do
|
26
|
+
test_client.release id
|
27
|
+
end
|
28
|
+
|
29
|
+
expect(release.lastRunRefresh).to eq('2015-02-09T15:51:22+03:00')
|
30
|
+
expect(release.realDate).to eq('2005-04-01T00:00:00+04:00')
|
31
|
+
expect(release.date).to eq('2005-04-01T00:00:00+04:00')
|
32
|
+
expect(release.id).to eq(id)
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Rest::Seasons do
|
4
|
+
describe '#seasons' do
|
5
|
+
it 'returns a collection of seasons' do
|
6
|
+
seasons = VCR.use_cassette('seasons/all_seasons') do
|
7
|
+
test_client.seasons
|
8
|
+
end
|
9
|
+
|
10
|
+
expect(seasons.first.dateStart).to eq('2002-09-01T00:00:00+04:00')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
specify '#season' do
|
15
|
+
id = 5
|
16
|
+
season = VCR.use_cassette('seasons/season') do
|
17
|
+
test_client.season id
|
18
|
+
end
|
19
|
+
|
20
|
+
expect(season.id).to eq(id)
|
21
|
+
expect(season.dateStart).to eq('1999-09-01T00:00:00+04:00')
|
22
|
+
expect(season.dateEnd).to eq('2000-08-31T00:00:00+04:00')
|
23
|
+
end
|
24
|
+
|
25
|
+
specify '#create_season' do
|
26
|
+
data = {
|
27
|
+
dateStart: '2022-02-05T19:37:45.004Z',
|
28
|
+
dateEnd: '2022-02-05T19:37:45.004Z'
|
29
|
+
}
|
30
|
+
stub_request(:post, 'https://api.rating.chgk.net/seasons').
|
31
|
+
with(body: data).
|
32
|
+
to_return(
|
33
|
+
status: 200,
|
34
|
+
body: JSON.dump(data.merge({id: 0})),
|
35
|
+
headers: {}
|
36
|
+
)
|
37
|
+
|
38
|
+
season = test_client.create_season data
|
39
|
+
|
40
|
+
expect(season.id).to eq(0)
|
41
|
+
expect(season.dateStart).to eq(data[:dateStart])
|
42
|
+
expect(season.dateEnd).to eq(data[:dateEnd])
|
43
|
+
end
|
44
|
+
|
45
|
+
specify '#update_season' do
|
46
|
+
data = {
|
47
|
+
dateStart: '2021-02-05T19:37:45.004Z',
|
48
|
+
dateEnd: '2021-02-05T19:37:45.004Z'
|
49
|
+
}
|
50
|
+
|
51
|
+
stub_request(:put, 'https://api.rating.chgk.net/seasons/0').
|
52
|
+
with(body: data).
|
53
|
+
to_return(
|
54
|
+
status: 200,
|
55
|
+
body: JSON.dump(data.merge({id: 0})),
|
56
|
+
headers: {}
|
57
|
+
)
|
58
|
+
|
59
|
+
season = test_client.update_season 0, data
|
60
|
+
|
61
|
+
expect(season.id).to eq(0)
|
62
|
+
expect(season.dateStart).to eq(data[:dateStart])
|
63
|
+
expect(season.dateEnd).to eq(data[:dateEnd])
|
64
|
+
end
|
65
|
+
|
66
|
+
specify '#delete_season' do
|
67
|
+
stub_request(:delete, 'https://api.rating.chgk.net/seasons/0').to_return(status: 204, body: '', headers: {})
|
68
|
+
|
69
|
+
expect(test_client.delete_season(0)).to eq('')
|
70
|
+
end
|
71
|
+
end
|