Prevent betting on running/finished matches
This commit is contained in:
parent
6d12f889c5
commit
175870ab42
|
|
@ -19,5 +19,7 @@ class UserService
|
||||||
raise UserServiceError, 'The given team is not involved in the given match' unless match.teams.include? team
|
raise UserServiceError, 'The given team is not involved in the given match' unless match.teams.include? team
|
||||||
end
|
end
|
||||||
raise UserServiceError, 'This user already created a bet on this match' if match.bets.map(&:user).include? @user
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ RSpec.describe UserService do
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_match(involved_team = team, factory = :playoff_match)
|
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
|
end
|
||||||
|
|
||||||
describe '#bet!' do
|
describe '#bet!' do
|
||||||
|
|
@ -26,6 +26,16 @@ RSpec.describe UserService do
|
||||||
end
|
end
|
||||||
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
|
context 'with an existing team' do
|
||||||
let(:match) do
|
let(:match) do
|
||||||
build_match
|
build_match
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue