diff options
author | Marius Peter <marius.peter@tutanota.com> | 2024-12-29 15:14:43 +0100 |
---|---|---|
committer | Marius Peter <marius.peter@tutanota.com> | 2024-12-29 15:14:43 +0100 |
commit | be2a93525069de2dfa3c23b0c23e7a9f7ad4c03d (patch) | |
tree | b5493e9d35d024ce7be072ec2168b4a98ba0e63f /test/services/tartiflette_scoring_service.rb |
First commit.
Diffstat (limited to 'test/services/tartiflette_scoring_service.rb')
-rw-r--r-- | test/services/tartiflette_scoring_service.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/services/tartiflette_scoring_service.rb b/test/services/tartiflette_scoring_service.rb new file mode 100644 index 0000000..6796342 --- /dev/null +++ b/test/services/tartiflette_scoring_service.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class TartifletteScoringServiceTest < ActiveSupport::TestCase + setup do + @tartiflette = Tartiflette.new(scoring_id: 1) + @session = {} + end + + test "should check if tartiflette is already scored" do + @session[:scored_tartiflettes] = [ @tartiflette.id ] + assert TartifletteScoringService.scored?(@tartiflette, @session) + end + + test "should mark tartiflette as scored" do + 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), + value: 4) + Score.create!(tartiflette: @tartiflette, + scoring_criterium: scoring_criteria(:two), + value: 5) + assert_equal 4.5, TartifletteScoringService.average_score(@tartiflette) + end + + test "should calculate average score by category for a tartiflette" do + Score.create!(tartiflette: @tartiflette, + scoring_criterium: scoring_criteria(:one), + value: 1) + Score.create!(tartiflette: @tartiflette, + scoring_criterium: scoring_criteria(:one), + value: 2) + Score.create!(tartiflette: @tartiflette, + scoring_criterium: scoring_criteria(:four), + value: 4) + Score.create!(tartiflette: @tartiflette, + scoring_criterium: scoring_criteria(:four), + value: 5) + average_score_by_category = { scoring_criteria(:one)[:category] => 1.5, + scoring_criteria(:four)[:category] => 4.5 + } + assert_equal average_score_by_category, + TartifletteScoringService.average_score_by_category(@tartiflette) + end +end |