Skip to content

Commit

Permalink
Add a test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Artheanos committed Mar 26, 2024
1 parent 1057463 commit 6a41adc
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
4 changes: 3 additions & 1 deletion examples/action_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# (in Rails projects located in `config/$ENVIRONMENT.rb`)
config.action_mailer.delivery_method = :mailtrap
config.action_mailer.mailtrap_settings = {
api_key: ENV.fetch('MAILTRAP_API_KEY')
api_key: ENV.fetch('MAILTRAP_API_KEY'),
# bulk: true, # Bulk sending (@see https://help.mailtrap.io/article/113-sending-streams)
# sandbox: true, inbox_id: 12, # Sandbox sending (@see https://help.mailtrap.io/article/109-getting-started-with-mailtrap-email-testing)
}
# And continue to use ActionMailer as usual.

Expand Down
6 changes: 3 additions & 3 deletions examples/full.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@

client = Mailtrap::Client.new(api_key: 'your-api-key')

# Custom host
# Custom host / port
# client = Mailtrap::Client.new(api_key: 'your-api-key', api_host: 'alternative.host.mailtrap.io', api_port: 8080)

# Bulk sending
# Bulk sending (@see https://help.mailtrap.io/article/113-sending-streams)
# client = Mailtrap::Client.new(api_key: 'your-api-key', bulk: true)

# Sandbox sending
# Sandbox sending (@see https://help.mailtrap.io/article/109-getting-started-with-mailtrap-email-testing)g
# client = Mailtrap::Client.new(api_key: 'your-api-key', sandbox: true, inbox_id: 12)

client.send(mail)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions spec/mailtrap/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@
described_class.new(api_key: api_key, sandbox: true)
end

it { expect { send }.to raise_error(ArgumentError) }
it { expect { send }.to raise_error(ArgumentError, 'inbox_id is required for sandbox API') }
end

context 'with bulk and sandbox flag' do
let(:client) do
described_class.new(api_key: api_key, bulk: true, sandbox: true)
end

it { expect { send }.to raise_error(ArgumentError) }
it { expect { send }.to raise_error(ArgumentError, 'bulk mode is not applicable for sandbox API') }
end
end

Expand Down Expand Up @@ -152,6 +152,16 @@
end
end
end

context 'when using sandbox' do
let(:client) do
described_class.new(api_key: api_key, sandbox: true, inbox_id: 13)
end

it 'sending is successful' do
expect(send).to eq({ message_ids: ['617103b5-7b2c-11ed-b344-0242ac1c0107'], success: true })
end
end
end
end

Expand Down

0 comments on commit 6a41adc

Please sign in to comment.