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,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Rest::Teams do
|
4
|
+
let(:team_id) { 2 }
|
5
|
+
|
6
|
+
specify '#team' do
|
7
|
+
team = VCR.use_cassette('teams/team') do
|
8
|
+
test_client.team(team_id)
|
9
|
+
end
|
10
|
+
|
11
|
+
expect(team.id).to eq(team_id)
|
12
|
+
expect(team.name).to eq('Афина')
|
13
|
+
expect(team.town['id']).to eq(201)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#teams' do
|
17
|
+
it 'returns a collection of teams' do
|
18
|
+
teams = VCR.use_cassette('teams/all_teams') do
|
19
|
+
test_client.teams
|
20
|
+
end
|
21
|
+
|
22
|
+
expect(teams[1].name).to eq('Афина')
|
23
|
+
expect(teams[1].id).to eq(2)
|
24
|
+
expect(teams[1].town['id']).to eq(201)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns a collection of teams with params' do
|
28
|
+
teams = VCR.use_cassette('teams/all_teams_params') do
|
29
|
+
test_client.teams itemsPerPage: 2, name: 'Н', page: 3
|
30
|
+
end
|
31
|
+
|
32
|
+
expect(teams.count).to eq(2)
|
33
|
+
expect(teams[0].name).to eq('Миллениум')
|
34
|
+
expect(teams[0].id).to eq(11)
|
35
|
+
expect(teams[0].town['id']).to eq(282)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#team_seasons' do
|
40
|
+
it 'returns seasons by params' do
|
41
|
+
team_seasons = VCR.use_cassette('teams/team_seasons_params') do
|
42
|
+
test_client.team_seasons team_id, idseason: 9
|
43
|
+
end
|
44
|
+
|
45
|
+
expect(team_seasons).to be_an_instance_of(RatingChgkV2::Collections::PlayerSeasonsCollection)
|
46
|
+
season = team_seasons.first
|
47
|
+
|
48
|
+
expect(season.idplayer).to eq(707)
|
49
|
+
expect(season.idseason).to eq(9)
|
50
|
+
expect(season.idteam).to eq(team_id)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#team_tournaments' do
|
55
|
+
it 'returns a collection of team tournaments with params' do
|
56
|
+
team_tournaments = VCR.use_cassette('teams/team_tournaments_params') do
|
57
|
+
test_client.team_tournaments team_id, pagination: true
|
58
|
+
end
|
59
|
+
|
60
|
+
tour = team_tournaments[2]
|
61
|
+
|
62
|
+
expect(tour.idtournament).to eq(8)
|
63
|
+
expect(tour.idteam).to eq(team_id)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Rest::TournamentFlags do
|
4
|
+
let(:id) { 2 }
|
5
|
+
|
6
|
+
describe '#tournament_flags' do
|
7
|
+
it 'returns a collection of tournament flags' do
|
8
|
+
flag = VCR.use_cassette('tournament_flags/all_tournament_flags') do
|
9
|
+
test_client.tournament_flags
|
10
|
+
end.first
|
11
|
+
|
12
|
+
expect(flag.id).to eq(1)
|
13
|
+
expect(flag.shortName).to eq('!')
|
14
|
+
expect(flag.longName).to eq('Общий зачёт')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
specify '#tournament_flag' do
|
19
|
+
flag = VCR.use_cassette('tournament_flags/tournament_flag') do
|
20
|
+
test_client.tournament_flag id
|
21
|
+
end
|
22
|
+
|
23
|
+
expect(flag.id).to eq(id)
|
24
|
+
expect(flag.shortName).to eq('МШ')
|
25
|
+
expect(flag.longName).to eq('Младшие школьники (5-9 классы)')
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Rest::TournamentSynchAppeals do
|
4
|
+
let(:id) { 1000 }
|
5
|
+
|
6
|
+
specify '#tournament_synch_appeal' do
|
7
|
+
appeal = VCR.use_cassette('tournament_synch_appeals/tournament_synch_appeal') do
|
8
|
+
test_client.tournament_synch_appeal id
|
9
|
+
end
|
10
|
+
|
11
|
+
expect(appeal.id).to eq(id)
|
12
|
+
expect(appeal.idtournament).to eq(2225)
|
13
|
+
expect(appeal.type).to eq('A')
|
14
|
+
expect(appeal.issuedAt).to eq('2013-04-19T22:28:10+04:00')
|
15
|
+
expect(appeal.status).to eq('D')
|
16
|
+
expect(appeal.appeal).to include('Из текста вопроса следует')
|
17
|
+
expect(appeal.comment).to include('В воспоминаниях фигурирует')
|
18
|
+
expect(appeal.overriddenBy).to be_nil
|
19
|
+
expect(appeal.questionNumber).to eq(8)
|
20
|
+
expect(appeal.answer).to be_nil
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Rest::TournamentSynchControversials do
|
4
|
+
let(:id) { 1000 }
|
5
|
+
|
6
|
+
specify '#tournament_synch_controversial' do
|
7
|
+
contr = VCR.use_cassette('tournament_synch_controversial/tournament_synch_controversia') do
|
8
|
+
test_client.tournament_synch_controversial id
|
9
|
+
end
|
10
|
+
|
11
|
+
expect(contr.id).to eq(id)
|
12
|
+
expect(contr.questionNumber).to eq(26)
|
13
|
+
expect(contr.answer).to eq('валяться')
|
14
|
+
expect(contr.issuedAt).to eq('2012-01-31T09:26:32+04:00')
|
15
|
+
expect(contr.status).to eq('D')
|
16
|
+
expect(contr.comment).to eq('')
|
17
|
+
expect(contr.resolvedAt).to eq('2012-01-31T15:26:32+04:00')
|
18
|
+
expect(contr.appealJuryComment).to be_nil
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Rest::TournamentSynchRequests do
|
4
|
+
let(:id) { 1000 }
|
5
|
+
|
6
|
+
specify '#tournament_synch_requests' do
|
7
|
+
req = VCR.use_cassette('tournament_synch_requests/tournament_synch_request') do
|
8
|
+
test_client.tournament_synch_request id
|
9
|
+
end
|
10
|
+
|
11
|
+
expect(req.id).to eq(id)
|
12
|
+
expect(req.status).to eq('A')
|
13
|
+
expect(req.venue['name']).to eq('Павлодар')
|
14
|
+
expect(req.representative['name']).to eq('Айбек')
|
15
|
+
expect(req.narrators.first['surname']).to eq('Логвиненко')
|
16
|
+
expect(req.approximateTeamsCount).to be_nil
|
17
|
+
expect(req.issuedAt).to eq('2012-09-21T10:30:14+04:00')
|
18
|
+
expect(req.tournamentId).to eq(2180)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Rest::TournamentTypes do
|
4
|
+
let(:id) { 3 }
|
5
|
+
|
6
|
+
specify '#tournament_types' do
|
7
|
+
t_type = VCR.use_cassette('tournament_types/tournament_types') do
|
8
|
+
test_client.tournament_types
|
9
|
+
end.first
|
10
|
+
|
11
|
+
expect(t_type.id).to eq(1)
|
12
|
+
expect(t_type.name).to eq('Неизвестный')
|
13
|
+
end
|
14
|
+
|
15
|
+
specify '#tournament_type' do
|
16
|
+
t_type = VCR.use_cassette('tournament_types/tournament_type') do
|
17
|
+
test_client.tournament_type id
|
18
|
+
end
|
19
|
+
|
20
|
+
expect(t_type.id).to eq(id)
|
21
|
+
expect(t_type.name).to eq('Синхрон')
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Rest::Tournaments do
|
4
|
+
let(:tournament_id) { 7798 }
|
5
|
+
|
6
|
+
# rubocop:disable RSpec/MultipleExpectations
|
7
|
+
specify '#tournament' do
|
8
|
+
tournament = VCR.use_cassette('tournaments/tournament') do
|
9
|
+
test_client.tournament(tournament_id)
|
10
|
+
end
|
11
|
+
|
12
|
+
expect(tournament.id).to eq(tournament_id)
|
13
|
+
expect(tournament.name).to eq('Игры доброй воли')
|
14
|
+
expect(tournament.lastEditDate).to eq('2022-03-30T09:34:21+03:00')
|
15
|
+
expect(tournament.dateStart).to eq('2022-03-13T13:00:00+03:00')
|
16
|
+
expect(tournament.dateEnd).to eq('2022-03-20T13:00:00+03:00')
|
17
|
+
expect(tournament.type['id']).to eq(3)
|
18
|
+
expect(tournament.orgcommittee.first['id']).to eq(14_450)
|
19
|
+
expect(tournament.synchData['dateRequestsAllowedTo']).to eq('2022-03-19T23:55:00+03:00')
|
20
|
+
expect(tournament.mainPayment).to eq(300)
|
21
|
+
expect(tournament.discountedPayment).to eq(100)
|
22
|
+
expect(tournament.discountedPaymentReason).to eq('школьные команды')
|
23
|
+
expect(tournament.currency).to eq('r')
|
24
|
+
expect(tournament.editors.first['id']).to eq(14_450)
|
25
|
+
expect(tournament.tournamentInRatingBalanced).to be(true)
|
26
|
+
expect(tournament.difficultyForecast).to eq(2.5)
|
27
|
+
expect(tournament.maiiAegis).to be(true)
|
28
|
+
expect(tournament.maiiAegisUpdatedAt).to eq('2022-02-12T08:35:02.372430Z')
|
29
|
+
expect(tournament.maiiRating).to be(true)
|
30
|
+
expect(tournament.maiiRatingUpdatedAt).to eq('2022-02-12T08:35:02.372192Z')
|
31
|
+
expect(tournament.questionQty['1']).to eq(9)
|
32
|
+
end
|
33
|
+
# rubocop:enable RSpec/MultipleExpectations
|
34
|
+
|
35
|
+
describe '#tournaments' do
|
36
|
+
it 'returns a collection of tournaments' do
|
37
|
+
tournaments = VCR.use_cassette('tournaments/all_tournaments') do
|
38
|
+
test_client.tournaments
|
39
|
+
end
|
40
|
+
|
41
|
+
expect(tournaments[0].name).to eq('Чемпионат Южного Кавказа')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns a collection of tournaments with params' do
|
45
|
+
tournaments = VCR.use_cassette('tournaments/all_tournaments_params') do
|
46
|
+
test_client.tournaments itemsPerPage: 2, page: 3
|
47
|
+
end
|
48
|
+
|
49
|
+
expect(tournaments.count).to eq(2)
|
50
|
+
expect(tournaments[0].name).to eq('Бостонское чаепитие')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
specify '#tournament_appeals' do
|
55
|
+
appeals = VCR.use_cassette('tournaments/appeals') do
|
56
|
+
test_client.tournament_appeals tournament_id
|
57
|
+
end
|
58
|
+
|
59
|
+
expect(appeals[0].id).to eq(12_153)
|
60
|
+
expect(appeals[0].questionNumber).to eq(20)
|
61
|
+
end
|
62
|
+
|
63
|
+
specify '#tournament_requests' do
|
64
|
+
requests = VCR.use_cassette('tournaments/requests') do
|
65
|
+
test_client.tournament_requests tournament_id
|
66
|
+
end
|
67
|
+
|
68
|
+
expect(requests[0].id).to eq(101_060)
|
69
|
+
expect(requests[0].status).to eq('A')
|
70
|
+
end
|
71
|
+
|
72
|
+
specify '#tournament_results' do
|
73
|
+
results = VCR.use_cassette('tournaments/results') do
|
74
|
+
test_client.tournament_results tournament_id, includeTeamMembers: 1, includeMasksAndControversials: 1,
|
75
|
+
includeTeamFlags: 1, includeRatingB: 1, town: 202
|
76
|
+
end.first
|
77
|
+
|
78
|
+
expect(results.team['id']).to eq(53_341)
|
79
|
+
expect(results.mask).to eq('011111111111011110001000000011111110111011111')
|
80
|
+
expect(results.current['name']).to eq('Парадные ватники')
|
81
|
+
expect(results.rating['b']).to eq(1216)
|
82
|
+
expect(results.controversials).to be_empty
|
83
|
+
expect(results.flags).to be_empty
|
84
|
+
expect(results.teamMembers.first['flag']).to eq('Б')
|
85
|
+
expect(results.questionsTotal).to eq(31)
|
86
|
+
expect(results.synchRequest['id']).to eq(103_475)
|
87
|
+
expect(results.position).to eq(1)
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Rest::Towns do
|
4
|
+
let(:town_id) { 1 }
|
5
|
+
|
6
|
+
specify '#town' do
|
7
|
+
town = VCR.use_cassette('towns/town') do
|
8
|
+
test_client.town(town_id)
|
9
|
+
end
|
10
|
+
|
11
|
+
expect(town.id).to eq(town_id)
|
12
|
+
expect(town.name).to eq('Абакан')
|
13
|
+
expect(town.region['name']).to eq('Хакасия')
|
14
|
+
expect(town.country['name']).to eq('Россия')
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#towns' do
|
18
|
+
it 'returns a collection of towns' do
|
19
|
+
towns = VCR.use_cassette('towns/all_towns') do
|
20
|
+
test_client.towns
|
21
|
+
end
|
22
|
+
|
23
|
+
expect(towns[0].name).to eq('Абакан')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns a collection of towns with params' do
|
27
|
+
towns = VCR.use_cassette('towns/all_towns_params') do
|
28
|
+
test_client.towns itemsPerPage: 2, page: 3
|
29
|
+
end
|
30
|
+
|
31
|
+
expect(towns.count).to eq(2)
|
32
|
+
expect(towns[0].name).to eq('Анапа')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Rest::VenueTypes do
|
4
|
+
let(:type_id) { 1 }
|
5
|
+
|
6
|
+
specify '#venue_type' do
|
7
|
+
venue_type = VCR.use_cassette('venue_types/venue_type') do
|
8
|
+
test_client.venue_type(type_id)
|
9
|
+
end
|
10
|
+
|
11
|
+
expect(venue_type.id).to eq(type_id)
|
12
|
+
expect(venue_type.name).to eq('Постоянная')
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#venue_types' do
|
16
|
+
it 'returns a collection of venue types' do
|
17
|
+
types = VCR.use_cassette('venue_types/venue_types') do
|
18
|
+
test_client.venue_types
|
19
|
+
end
|
20
|
+
|
21
|
+
expect(types[0].name).to eq('Постоянная')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns a collection of venue types with params' do
|
25
|
+
types = VCR.use_cassette('venue_types/all_venue_types_params') do
|
26
|
+
test_client.venue_types itemsPerPage: 3, page: 2
|
27
|
+
end
|
28
|
+
|
29
|
+
expect(types[0].name).to eq('Разовая')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
specify '#create_venue_type' do
|
34
|
+
stub_request(:post, 'https://api.rating.chgk.net/venue_types').
|
35
|
+
with(body: {name: 'Фейковая'}).
|
36
|
+
to_return(
|
37
|
+
status: 201,
|
38
|
+
body: '{"id":0,"name":"Фейковая"}',
|
39
|
+
headers: {}
|
40
|
+
)
|
41
|
+
|
42
|
+
venue_type = test_client.create_venue_type name: 'Фейковая'
|
43
|
+
expect(venue_type.name).to eq('Фейковая')
|
44
|
+
expect(venue_type.id).to eq(0)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Rest::Venues do
|
4
|
+
let(:venue_id) { 3601 }
|
5
|
+
|
6
|
+
specify '#venue' do
|
7
|
+
venue = VCR.use_cassette('venues/venue') do
|
8
|
+
test_client.venue(venue_id)
|
9
|
+
end
|
10
|
+
|
11
|
+
expect(venue.id).to eq(venue_id)
|
12
|
+
expect(venue.name).to eq('Библиотека')
|
13
|
+
expect(venue.town['name']).to eq('Витебск')
|
14
|
+
expect(venue.type['name']).to eq('Постоянная')
|
15
|
+
expect(venue.address).to eq('Витебск, пр. Фрунзе 30а')
|
16
|
+
expect(venue.urls.first).to include('vk.com')
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#venues' do
|
20
|
+
it 'returns a collection of venues' do
|
21
|
+
venues = VCR.use_cassette('venues/venues') do
|
22
|
+
test_client.venues
|
23
|
+
end
|
24
|
+
|
25
|
+
expect(venues[0].id).to eq(3030)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns a collection of venues with params' do
|
29
|
+
venues = VCR.use_cassette('venues/all_venues_params') do
|
30
|
+
test_client.venues itemsPerPage: 3, page: 2
|
31
|
+
end
|
32
|
+
|
33
|
+
expect(venues.count).to eq(3)
|
34
|
+
expect(venues[0].name).to eq('Ереван')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
specify '#create_venue' do
|
39
|
+
stub_request(:post, 'https://api.rating.chgk.net/venues').
|
40
|
+
with(body: {name: 'Фейк', type: {name: 'Фейковый тип'}}).
|
41
|
+
to_return(
|
42
|
+
status: 201,
|
43
|
+
body: '{"id":0,"name":"Фейк","type":{"id":0,"name":"Фейковый тип"}}',
|
44
|
+
headers: {}
|
45
|
+
)
|
46
|
+
|
47
|
+
venue = test_client.create_venue name: 'Фейк', type: {name: 'Фейковый тип'}
|
48
|
+
expect(venue.name).to eq('Фейк')
|
49
|
+
expect(venue.type['id']).to eq(0)
|
50
|
+
end
|
51
|
+
|
52
|
+
specify '#update_venue' do
|
53
|
+
stub_request(:put, 'https://api.rating.chgk.net/venues/0').
|
54
|
+
with(body: {name: 'Обновлённая'}).
|
55
|
+
to_return(
|
56
|
+
status: 200,
|
57
|
+
body: '{"id":0,"name":"Обновлённая"}',
|
58
|
+
headers: {}
|
59
|
+
)
|
60
|
+
|
61
|
+
venue = test_client.update_venue 0, name: 'Обновлённая'
|
62
|
+
expect(venue.name).to eq('Обновлённая')
|
63
|
+
expect(venue.id).to eq(0)
|
64
|
+
end
|
65
|
+
|
66
|
+
specify '#delete_country' do
|
67
|
+
stub_request(:delete, 'https://api.rating.chgk.net/venues/1').to_return(status: 204, body: '', headers: {})
|
68
|
+
|
69
|
+
expect(test_client.delete_venue(1)).to eq('')
|
70
|
+
end
|
71
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dotenv/load'
|
4
|
+
require 'simplecov'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
|
7
|
+
SimpleCov.start do
|
8
|
+
add_filter 'spec/'
|
9
|
+
add_filter '.github/'
|
10
|
+
end
|
11
|
+
|
12
|
+
if ENV['CI'] == 'true'
|
13
|
+
require 'codecov'
|
14
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'rating_chgk_v2'
|
18
|
+
|
19
|
+
# Support files
|
20
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
|
21
|
+
|
22
|
+
RSpec.configure do |config|
|
23
|
+
config.include TestClient
|
24
|
+
|
25
|
+
WebMock.allow_net_connect!
|
26
|
+
WebMock::API.prepend(Module.new do
|
27
|
+
extend self
|
28
|
+
# disable VCR when a WebMock stub is created
|
29
|
+
# for clearer spec failure messaging
|
30
|
+
def stub_request(*args)
|
31
|
+
VCR.turn_off!
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end)
|
35
|
+
|
36
|
+
config.before { VCR.turn_on! }
|
37
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.shared_examples 'paginated' do
|
4
|
+
let(:endpoint) { RatingChgkV2::Endpoints::BaseEndpoint.new test_client }
|
5
|
+
let(:collection) { described_class.new [], endpoint }
|
6
|
+
|
7
|
+
specify '#next_page!' do
|
8
|
+
allow(endpoint).to receive(:do_get).and_return([{paginated: true}])
|
9
|
+
expect(endpoint.params[:page]).to be_nil
|
10
|
+
|
11
|
+
expect(collection.next_page!).to be_an_instance_of(described_class)
|
12
|
+
expect(endpoint).to have_received(:do_get)
|
13
|
+
|
14
|
+
expect(collection.first.class.superclass).to eq(RatingChgkV2::Models::BaseModel)
|
15
|
+
expect(endpoint.params[:page]).to eq(2)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#prev_page!' do
|
19
|
+
it 'fetches the previous page' do
|
20
|
+
allow(endpoint).to receive(:do_get).and_return([{paginated: true}])
|
21
|
+
allow(endpoint.params).to receive(:[]).with(:page).and_return(3)
|
22
|
+
|
23
|
+
expect(collection.prev_page!).to be_an_instance_of(described_class)
|
24
|
+
expect(endpoint).to have_received(:do_get)
|
25
|
+
|
26
|
+
expect(collection.first.class.superclass).to eq(RatingChgkV2::Models::BaseModel)
|
27
|
+
expect(endpoint.params[:page]).to eq(2)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'does not fetch anything when the page is the first one' do
|
31
|
+
allow(endpoint).to receive(:do_get).and_return([{paginated: true}])
|
32
|
+
expect(endpoint.params[:page]).to be_nil
|
33
|
+
|
34
|
+
expect(collection.prev_page!).to be_nil
|
35
|
+
expect(endpoint).not_to have_received(:do_get)
|
36
|
+
|
37
|
+
expect(collection.first).to be_nil
|
38
|
+
expect(endpoint.params[:page]).to be_nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/support/vcr.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'vcr'
|
4
|
+
|
5
|
+
VCR.configure do |c|
|
6
|
+
c.ignore_hosts 'codeclimate.com'
|
7
|
+
c.hook_into :faraday
|
8
|
+
c.default_cassette_options = {
|
9
|
+
decode_compressed_response: true
|
10
|
+
}
|
11
|
+
c.cassette_library_dir = File.join(File.dirname(__FILE__), '..', 'fixtures', 'vcr_cassettes')
|
12
|
+
c.filter_sensitive_data('<API_TOKEN>') { ENV.fetch('API_TOKEN', 'hidden') }
|
13
|
+
c.filter_sensitive_data('<CHGK_EMAIL>') { ENV.fetch('CHGK_EMAIL', 'fake') }
|
14
|
+
c.filter_sensitive_data('<CHGK_PASSWORD>') { ENV.fetch('CHGK_PASSWORD', 'fake') }
|
15
|
+
end
|