Skip to content

Commit

Permalink
Add missing assertions to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Sep 6, 2024
1 parent 9f57d03 commit d865e48
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 14 deletions.
17 changes: 13 additions & 4 deletions test/bulk_delivery_methods/webhook_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class WebhookBulkDeliveryMethodTest < ActiveSupport::TestCase
)
stub_request(:post, "https://example.org/webhook").with(body: "{\"foo\":\"bar\"}")

@delivery_method.deliver
assert_nothing_raised do
@delivery_method.deliver
end
end

test "webhook with form payload" do
Expand All @@ -21,7 +23,9 @@ class WebhookBulkDeliveryMethodTest < ActiveSupport::TestCase
form: {foo: :bar}
)
stub_request(:post, "https://example.org/webhook").with(headers: {"Content-Type" => /application\/x-www-form-urlencoded/})
@delivery_method.deliver
assert_nothing_raised do
@delivery_method.deliver
end
end

test "webhook with basic auth" do
Expand All @@ -30,7 +34,9 @@ class WebhookBulkDeliveryMethodTest < ActiveSupport::TestCase
basic_auth: {user: "username", pass: "password"}
)
stub_request(:post, "https://example.org/webhook").with(headers: {"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ="})
@delivery_method.deliver
assert_nothing_raised do
@delivery_method.deliver
end
end

test "webhook with headers" do
Expand All @@ -39,7 +45,10 @@ class WebhookBulkDeliveryMethodTest < ActiveSupport::TestCase
headers: {"Content-Type" => "application/json"}
)
stub_request(:post, "https://example.org/webhook").with(headers: {"Content-Type" => "application/json"})
@delivery_method.deliver

assert_nothing_raised do
@delivery_method.deliver
end
end

test "webhook raises error with unsuccessful status codes" do
Expand Down
4 changes: 3 additions & 1 deletion test/delivery_methods/fcm_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def fetch_access_token!
stub_request(:post, "https://fcm.googleapis.com/v1/projects/p_1234/messages:send").with(body: "{\"message\":{\"token\":\"a\",\"notification\":{\"title\":\"Title\",\"body\":\"Body\"}}}")
stub_request(:post, "https://fcm.googleapis.com/v1/projects/p_1234/messages:send").with(body: "{\"message\":{\"token\":\"b\",\"notification\":{\"title\":\"Title\",\"body\":\"Body\"}}}")

@delivery_method.deliver
assert_nothing_raised do
@delivery_method.deliver
end
end

test "notifies of invalid tokens for clean up" do
Expand Down
4 changes: 3 additions & 1 deletion test/delivery_methods/microsoft_teams_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class MicrosoftTeamsTest < ActiveSupport::TestCase

test "sends a message" do
stub_request(:post, "https://teams.microsoft.com").with(body: "{\"foo\":\"bar\"}")
@delivery_method.deliver
assert_nothing_raised do
@delivery_method.deliver
end
end

test "raises error on failure" do
Expand Down
4 changes: 3 additions & 1 deletion test/delivery_methods/slack_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class SlackTest < ActiveSupport::TestCase

test "sends a slack message" do
stub_request(:post, Noticed::DeliveryMethods::Slack::DEFAULT_URL).with(body: "{\"foo\":\"bar\"}")
@delivery_method.deliver
assert_nothing_raised do
@delivery_method.deliver
end
end

test "raises error on failure" do
Expand Down
5 changes: 4 additions & 1 deletion test/delivery_methods/twilio_messaging_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ class TwilioMessagingTest < ActiveSupport::TestCase
Body: "Hello world"
}
).to_return(status: 200)
@delivery_method.deliver

assert_nothing_raised do
@delivery_method.deliver
end
end

test "raises error on failure" do
Expand Down
4 changes: 3 additions & 1 deletion test/delivery_methods/vonage_sms_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class VonageSmsTest < ActiveSupport::TestCase
test "sends sms" do
set_config(json: {foo: :bar})
stub_request(:post, Noticed::DeliveryMethods::VonageSms::DEFAULT_URL).with(body: "{\"foo\":\"bar\"}").to_return(status: 200, body: "{\"messages\":[{\"status\":\"0\"}]}")
@delivery_method.deliver
assert_nothing_raised do
@delivery_method.deliver
end
end

test "raises error on failure" do
Expand Down
19 changes: 15 additions & 4 deletions test/delivery_methods/webhook_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class WebhookDeliveryMethodTest < ActiveSupport::TestCase
)
stub_request(:post, "https://example.org/webhook").with(body: "{\"foo\":\"bar\"}")

@delivery_method.deliver
assert_nothing_raised do
@delivery_method.deliver
end
end

test "webhook with form payload" do
Expand All @@ -21,7 +23,10 @@ class WebhookDeliveryMethodTest < ActiveSupport::TestCase
form: {foo: :bar}
)
stub_request(:post, "https://example.org/webhook").with(headers: {"Content-Type" => /application\/x-www-form-urlencoded/})
@delivery_method.deliver

assert_nothing_raised do
@delivery_method.deliver
end
end

test "webhook with basic auth" do
Expand All @@ -30,7 +35,10 @@ class WebhookDeliveryMethodTest < ActiveSupport::TestCase
basic_auth: {user: "username", pass: "password"}
)
stub_request(:post, "https://example.org/webhook").with(headers: {"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ="})
@delivery_method.deliver

assert_nothing_raised do
@delivery_method.deliver
end
end

test "webhook with headers" do
Expand All @@ -39,7 +47,10 @@ class WebhookDeliveryMethodTest < ActiveSupport::TestCase
headers: {"Content-Type" => "application/json"}
)
stub_request(:post, "https://example.org/webhook").with(headers: {"Content-Type" => "application/json"})
@delivery_method.deliver

assert_nothing_raised do
@delivery_method.deliver
end
end

test "webhook raises error with unsuccessful status codes" do
Expand Down
4 changes: 3 additions & 1 deletion test/notifier_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def recipients
end

test "deliver without recipients" do
ReceiptNotifier.deliver
assert_nothing_raised do
ReceiptNotifier.deliver
end
end

test "deliver creates an event" do
Expand Down

0 comments on commit d865e48

Please sign in to comment.