Prevent betting on running/finished matches

This commit is contained in:
Thor77 2019-06-14 19:04:18 +02:00
parent 6d12f889c5
commit 175870ab42
No known key found for this signature in database
GPG Key ID: 5051E71B46AA669A
2 changed files with 13 additions and 1 deletions

View File

@ -19,5 +19,7 @@ class UserService
raise UserServiceError, 'The given team is not involved in the given match' unless match.teams.include? team
end
raise UserServiceError, 'This user already created a bet on this match' if match.bets.map(&:user).include? @user
raise UserServiceError, "Betting is not supported while match is #{match.state}" \
unless %w[not_ready not_started].include? match.state
end
end

View File

@ -14,7 +14,7 @@ RSpec.describe UserService do
end
def build_match(involved_team = team, factory = :playoff_match)
create(factory, match_scores: [create(:match_score, team: involved_team)])
create(factory, state: :not_started, match_scores: [create(:match_score, team: involved_team)])
end
describe '#bet!' do
@ -26,6 +26,16 @@ RSpec.describe UserService do
end
end
context 'on a running match' do
it 'throws an exception' do
match = build_match
match.state = :in_progress
expect do
user_service.bet! match, team
end.to raise_error(UserServiceError, 'Betting is not supported while match is in_progress')
end
end
context 'with an existing team' do
let(:match) do
build_match