From b3302cf1368f34b59651458f35484ef606659a78 Mon Sep 17 00:00:00 2001 From: Chonlasith Jucksriporn Date: Tue, 29 Oct 2024 15:30:05 +0700 Subject: [PATCH] chore: Add tests --- cdmm/test/controllers/cdmm_controller_test.rb | 24 +++++++++++++++++++ cdmm/test/controllers/home_controller_test.rb | 14 +++++++++++ 2 files changed, 38 insertions(+) diff --git a/cdmm/test/controllers/cdmm_controller_test.rb b/cdmm/test/controllers/cdmm_controller_test.rb index 8824ef2..2864a68 100644 --- a/cdmm/test/controllers/cdmm_controller_test.rb +++ b/cdmm/test/controllers/cdmm_controller_test.rb @@ -4,4 +4,28 @@ class CdmmControllerTest < ActionDispatch::IntegrationTest # test "the truth" do # assert true # end + test "accessing the cdmm without key will create a draft blank form" do + assert_difference("Evaluation.count") do + get evaluation_index_path + + assert_response :redirect + redirect_path = response.location + form_key = redirect_path.split("/").last + + ev = Evaluation.find_by(form_key: form_key) + assert_equal "draft", ev.form_status + end + end + + test "get existing evaluation" do + get evaluation_show_path(:team_a_form_key) + + assert_response :success + end + + test "get non-exising evaluation" do + get evaluation_show_path(:no_such_a_form_key) + + assert_response :not_found + end end diff --git a/cdmm/test/controllers/home_controller_test.rb b/cdmm/test/controllers/home_controller_test.rb index eac0e33..a432087 100644 --- a/cdmm/test/controllers/home_controller_test.rb +++ b/cdmm/test/controllers/home_controller_test.rb @@ -4,4 +4,18 @@ class HomeControllerTest < ActionDispatch::IntegrationTest # test "the truth" do # assert true # end + test "root access should redirect to cdmm which will create a blank form and redirect to that form path" do + get root_path + + # redirect from / to /cdmm + assert_response :redirect + assert_redirected_to evaluation_index_path + follow_redirect! + # redirect from /cdmm to /cdmm/ + assert_response :redirect + redirect_path = response.location + assert_redirected_to redirect_path + follow_redirect! + assert_response :success + end end