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
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue