From e567d12ca2032665942a679286a47ce547724688 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Sat, 1 Jun 2019 19:35:12 +0200 Subject: [PATCH] Test if match_score point change triggers group score calculation --- .../match_scores_controller_spec.rb | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/spec/controllers/match_scores_controller_spec.rb b/spec/controllers/match_scores_controller_spec.rb index 67f9b1a..99d1af5 100644 --- a/spec/controllers/match_scores_controller_spec.rb +++ b/spec/controllers/match_scores_controller_spec.rb @@ -61,4 +61,41 @@ RSpec.describe MatchScoresController, type: :controller do end end end + + describe 'triggers group point calculation' do + before(:each) do + apply_authentication_headers_for @match_score.owner + end + + before do + @tournament = create(:group_stage_tournament, stage_count: 0, match_factory: :filled_group_match) + @group = @tournament.stages.first.groups.first + @match_score = @group.matches.first.match_scores.first + expect(UpdateGroupsGroupScoresAndSave).to receive(:call).once.with(group: @group).and_return(context) + end + + let(:valid_update) do + { + points: 42 + } + end + + context 'when successful' do + let(:context) { double(:context, success?: true) } + + it 'returns a 200 status code' do + put :update, params: { id: @match_score.to_param }.merge(valid_update) + expect(response).to be_successful + end + end + + context 'when unsuccessful' do + let(:context) { double(:context, success?: false) } + + it 'returns a 200 status code' do + put :update, params: { id: @match_score.to_param }.merge(valid_update) + expect(response).to be_successful + end + end + end end