Skip to content

Commit

Permalink
pmdk total score unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSipayung committed Jan 26, 2024
1 parent 7910dcb commit b0e8ea0
Showing 1 changed file with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,41 @@ def setup
assert_not_nil PmdkTotalScoreInformation.find_by_jumlah_pelajaran_semester_4 15
assert_not_nil PmdkTotalScoreInformation.find_by_jumlah_pelajaran_semester_5 14
end
test "should reject non permited params while create total pmdk score" do
get new_pmdk_total_score_information_path
assert_response :success
assert_difference 'PmdkTotalScoreInformation.count' do
post pmdk_total_score_informations_path, params: {
pmdk_total_score_information: {
jumlah_nilai_semester_1: 120.5,
jumlah_nilai_semester_2: 122.5, jumlah_nilai_semester_3: 130.9,
jumlah_nilai_semester_4: 189.9, jumlah_nilai_semester_5: 189.98,
jumlah_pelajaran_semester_1: 3, jumlah_pelajaran_semester_2: 6,
jumlah_pelajaran_semester_3: 12, jumlah_pelajaran_semester_4: 15,
jumlah_pelajaran_semester_5: 14, user_id: 98999809
}
}
end
assert_nil PmdkTotalScoreInformation.find_by_user_id 98999809
end
test "should reject to create pmdk total score for invalid information" do
get new_pmdk_total_score_information_path
assert_response :success
assert_no_difference 'PmdkTotalScoreInformation.count' do
post pmdk_total_score_informations_path, params: {
pmdk_total_score_information: {
jumlah_nilai_semester_1: 0,
jumlah_nilai_semester_2: 122.5, jumlah_nilai_semester_3: 130.9,
jumlah_nilai_semester_4: 189.9, jumlah_nilai_semester_5: 189.98,
jumlah_pelajaran_semester_1: 3, jumlah_pelajaran_semester_2: 6,
jumlah_pelajaran_semester_3: 12, jumlah_pelajaran_semester_4: 15,
jumlah_pelajaran_semester_5: 14
}
}
end
assert_nil PmdkTotalScoreInformation.find_by_jumlah_nilai_semester_1 0
assert_nil PmdkTotalScoreInformation.find_by_jumlah_nilai_semester_3 130.9
end
test "should update pmdk total score information" do
get login_path
post login_path, params: {session: {
Expand Down Expand Up @@ -75,7 +110,44 @@ def setup
assert_equal 12, pmdk_total_score_informations(:pmdk_total_one).jumlah_pelajaran_semester_3
assert_equal 15, pmdk_total_score_informations(:pmdk_total_one).jumlah_pelajaran_semester_4
assert_equal 14, pmdk_total_score_informations(:pmdk_total_one).jumlah_pelajaran_semester_5

end
test "should not update non-permited params for total score pmdk" do
get login_path
post login_path, params: {session: {
email: users(:archer).email, password: 'password'
}}
get edit_pmdk_total_score_information_path(pmdk_total_score_informations(:pmdk_total_one))
assert_response :success
patch pmdk_total_score_information_path(pmdk_total_score_informations(:pmdk_total_one)),params: {
pmdk_total_score_information: {
jumlah_nilai_semester_1: 120.5,
jumlah_nilai_semester_2: 122.5, jumlah_nilai_semester_3: 130.9,
jumlah_nilai_semester_4: 189.9, jumlah_nilai_semester_5: 189.98,
jumlah_pelajaran_semester_1: 3, jumlah_pelajaran_semester_2: 6,
jumlah_pelajaran_semester_3: 12, jumlah_pelajaran_semester_4: 15,
jumlah_pelajaran_semester_5: 14, user_id: 9888898910
}
}
assert_not_equal 9888898910, pmdk_total_score_informations(:pmdk_total_one).reload.user_id
end
test "should not update for wrong information for total score pmdk" do
get login_path
post login_path, params: {session: {
email: users(:archer).email, password: 'password'
}}
get edit_pmdk_total_score_information_path(pmdk_total_score_informations(:pmdk_total_one))
assert_response :success
patch pmdk_total_score_information_path(pmdk_total_score_informations(:pmdk_total_one)),params: {
pmdk_total_score_information: {
jumlah_nilai_semester_1: 120.5,
jumlah_nilai_semester_2: 122.5, jumlah_nilai_semester_3: 130.9,
jumlah_nilai_semester_4: 189.9, jumlah_nilai_semester_5: 189.98,
jumlah_pelajaran_semester_1: 3, jumlah_pelajaran_semester_2: 6,
jumlah_pelajaran_semester_3: 12, jumlah_pelajaran_semester_4: 15,
jumlah_pelajaran_semester_5: 0
}
}
assert_not_equal 0, pmdk_total_score_informations(:pmdk_total_one).reload.jumlah_pelajaran_semester_5
end
# test "should get show" do
# get pmdk_total_score_informations_show_url
Expand Down

0 comments on commit b0e8ea0

Please sign in to comment.