21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-05-07 19:18:39 +02:00

simplify checks test

This commit is contained in:
Jérémy Lecour 2019-03-02 11:01:33 +01:00
parent 1c5462743b
commit c100839691
3 changed files with 18 additions and 20 deletions

View file

@ -83,13 +83,5 @@ FactoryBot.define do
trait :inactive do trait :inactive do
active false active false
end end
trait :with_notifications do
after :create do |check|
create_list :check_notification, 2,
check: check,
notification: build(:notification, user: check.user)
end
end
end end
end end

View file

@ -31,7 +31,7 @@ FactoryBot.define do
user user
interval 30 interval 30
channel :email channel :email
label { "#{recipient} (#{interval})" } sequence(:label) { |n| "#{recipient}-#{n} (#{interval})" }
recipient "recipient@domain.fr" recipient "recipient@domain.fr"
trait :email do trait :email do

View file

@ -53,48 +53,54 @@ class ChecksTest < ApplicationSystemTestCase
fill_and_valid_new_check fill_and_valid_new_check
end end
test "dissociate a notification" do test "dettach a notification from a check" do
check = create(:check, :with_notifications, user: @user) initial_notifications_count = 2
check = create(:check, user: @user)
existing_notifications = create_list(:notification, initial_notifications_count, user: @user)
check.notifications << existing_notifications
notification = create(:notification, label: "label-notification", user: @user) notification = create(:notification, label: "label-notification", user: @user)
check.notifications << notification check.notifications << notification
visit edit_check_path(check) visit edit_check_path(check)
uncheck notification.label uncheck notification.label
click_button "Update Check" click_button "Update Check"
notification.reload notification.reload
check.reload
assert_equal 0, notification.checks_count assert_equal 0, notification.checks_count
assert_equal 2, check.check_notifications.count assert_equal initial_notifications_count, check.notifications.count
end end
test "associate a notification" do test "attach a notification to a check" do
check = create(:check, user: @user) check = create(:check, user: @user)
notification = create(:notification, label: "label-notification", user: @user) notification = create(:notification, label: "label-notification", user: @user)
visit edit_check_path(check)
visit edit_check_path(check)
check notification.label check notification.label
click_button "Update Check" click_button "Update Check"
notification.reload notification.reload
check.reload
assert_equal 1, notification.checks_count assert_equal 1, notification.checks_count
assert_equal 1, check.check_notifications.count assert_equal 1, check.check_notifications.count
end end
test "update a check" do test "update a check" do
check = create(:check, :with_notifications, domain: "dom-with-notif.net", user: @user) check = create(:check, domain: "dom-with-notif.net", user: @user)
check.notifications << create_list(:notification, 2, user: @user)
visit edit_check_path(check) visit edit_check_path(check)
fill_in "check[comment]", with: "My comment" fill_in "check[comment]", with: "My comment"
click_button "Update Check" click_button "Update Check"
assert_equal checks_path, page.current_path assert_equal checks_path, page.current_path
assert page.has_css?(".alert-success") assert page.has_css?(".alert-success")
check.reload check.reload
assert_equal "My comment", check.comment assert_equal "My comment", check.comment
end end