diff options
author | Marius Peter <marius.peter@tutanota.com> | 2025-01-01 18:02:02 +0100 |
---|---|---|
committer | Marius Peter <marius.peter@tutanota.com> | 2025-01-01 18:02:02 +0100 |
commit | 0f3c5a381924cb10abbe57c67c3f5a00e5b790a6 (patch) | |
tree | de11d090421f8c5bdd33b3e2dc26b2460476da16 /test/services/tartiflette_scoring_service.rb | |
parent | 46c534cfef50a05937ce3354de3cd7ccddf3ab69 (diff) |
Updated more tests.
Diffstat (limited to 'test/services/tartiflette_scoring_service.rb')
-rw-r--r-- | test/services/tartiflette_scoring_service.rb | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/test/services/tartiflette_scoring_service.rb b/test/services/tartiflette_scoring_service.rb index 6796342..0a66d5b 100644 --- a/test/services/tartiflette_scoring_service.rb +++ b/test/services/tartiflette_scoring_service.rb @@ -2,8 +2,9 @@ require "test_helper" class TartifletteScoringServiceTest < ActiveSupport::TestCase setup do - @tartiflette = Tartiflette.new(scoring_id: 1) - @session = {} + @tartiflette = tartiflettes(:one) + @existing_score = scores(:one) + @session = { id: @existing_score.session_id } end test "should check if tartiflette is already scored" do @@ -16,6 +17,43 @@ class TartifletteScoringServiceTest < ActiveSupport::TestCase assert_includes @session[:scored_tartiflettes], @tartiflette.id end + test "should process scores for tartiflette" do + scores = { + "1" => { value: 4, id: nil }, # New score for criterium_id 1 + "2" => { value: 5, id: @existing_score.id } # Update existing score + } + + assert_nothing_raised do + TartifletteScoringService.process_scores(@tartiflette, scores, @session) + end + + # Assertions for new score + new_score = Score.find_by(scoring_criterium_id: 1, tartiflette: @tartiflette) + assert_equal 4, new_score.value + assert_equal @session[:id], new_score.session_id + + # Assertions for updated score + @existing_score.reload + assert_equal 5, @existing_score.value + end + + test "should raise error for invalid data" do + scores = { + "1" => { value: nil, id: nil }, # Missing value + "2" => { value: 5, id: nil } # Valid score + } + + assert_raises(StandardError, /Failed to process scores/) do + TartifletteScoringService.process_scores(@tartiflette, scores, @session) + end + end + + test "should mark tartiflette as scored in session" do + session = { scored_tartiflettes: [] } + TartifletteScoringService.mark_as_scored(@tartiflette, session) + assert_includes session[:scored_tartiflettes], @tartiflette.id + end + test "should calculate average of all scores for a tartiflette" do Score.create!(tartiflette: @tartiflette, scoring_criterium: scoring_criteria(:one), |