Files
MySMSAPio/test/integration/admin/notifications_flow_test.rb

50 lines
1.6 KiB
Ruby

require "test_helper"
class AdminNotificationsFlowTest < ActionDispatch::IntegrationTest
setup do
@admin = AdminUser.create!(name: "Flow Admin", email: "flow@example.com", password: "password123")
post admin_login_path, params: { email: "flow@example.com", password: "password123" }
end
test "can view notification settings page" do
get admin_notifications_path
assert_response :success
assert_match "Notification Settings", response.body
assert_match "ntfy Topic", response.body
end
test "can update ntfy settings" do
patch admin_notifications_path, params: {
admin_user: {
ntfy_enabled: "1",
ntfy_topic: "flow-topic",
ntfy_token: "tk_flow",
ntfy_server_url: "https://ntfy.example.com"
}
}
assert_redirected_to admin_notifications_path
@admin.reload
assert_equal true, @admin.ntfy_enabled
assert_equal "flow-topic", @admin.ntfy_topic
assert_equal "tk_flow", @admin.ntfy_token
end
test "test notification redirects with alert when not configured" do
post test_admin_notifications_path
assert_redirected_to admin_notifications_path
follow_redirect!
assert_match "Configure ntfy", response.body
end
test "test notification sends and redirects with notice when configured" do
@admin.update!(ntfy_enabled: true, ntfy_topic: "t", ntfy_token: "tk", ntfy_server_url: "https://ntfy.example.com")
stub_request(:post, "https://ntfy.example.com/t").to_return(status: 200)
post test_admin_notifications_path
assert_redirected_to admin_notifications_path
follow_redirect!
assert_match "Test notification sent", response.body
end
end