-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
custom matcher moved to appropriate matchers location
- Loading branch information
Showing
11 changed files
with
112 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
require 'spec_helper' | ||
|
||
describe "Sending messages as Ruby hashes with Postmark::ApiClient" do | ||
let(:message_id_format) { /<.+@.+>/ } | ||
let(:postmark_message_id_format) { /\w{8}\-\w{4}-\w{4}-\w{4}-\w{12}/ } | ||
let(:api_client) { Postmark::ApiClient.new('POSTMARK_API_TEST', :http_open_timeout => 15, :http_read_timeout => 15) } | ||
let(:message_id_format) {/<.+@.+>/} | ||
let(:postmark_message_id_format) {/\w{8}\-\w{4}-\w{4}-\w{4}-\w{12}/} | ||
let(:api_client) {Postmark::ApiClient.new('POSTMARK_API_TEST', :http_open_timeout => 15, :http_read_timeout => 15)} | ||
|
||
let(:message) { | ||
{ | ||
:from => "[email protected]", | ||
:to => "[email protected]", | ||
:subject => "Mail::Message object", | ||
:text_body => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " \ | ||
:from => "[email protected]", | ||
:to => "[email protected]", | ||
:subject => "Mail::Message object", | ||
:text_body => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " \ | ||
"sed do eiusmod tempor incididunt ut labore et dolore " \ | ||
"magna aliqua." | ||
} | ||
} | ||
|
||
let(:message_with_no_body) { | ||
{ | ||
:from => "[email protected]", | ||
:to => "[email protected]", | ||
:from => "[email protected]", | ||
:to => "[email protected]", | ||
} | ||
} | ||
|
||
|
@@ -29,66 +29,60 @@ | |
end | ||
} | ||
|
||
let(:message_with_invalid_to) { | ||
{ | ||
:from => "[email protected]", | ||
:to => "@postmarkapp.com" | ||
} | ||
} | ||
let(:message_with_invalid_to) {{:from => "[email protected]", :to => "@postmarkapp.com"}} | ||
let(:valid_messages) {[message, message.dup]} | ||
let(:partially_valid_messages) {[message, message.dup, message_with_no_body]} | ||
let(:invalid_messages) {[message_with_no_body, message_with_no_body.dup]} | ||
|
||
let(:valid_messages) { [message, message.dup] } | ||
let(:partially_valid_messages) { [message, message.dup, message_with_no_body] } | ||
let(:invalid_messages) { [message_with_no_body, message_with_no_body.dup] } | ||
|
||
context "message by message" do | ||
it 'delivers a plain text message' do | ||
context "single message" do | ||
it 'plain text message' do | ||
expect(api_client.deliver(message)).to have_key(:message_id) | ||
end | ||
|
||
it 'updates a message object with Message-ID' do | ||
expect(api_client.deliver(message)[:message_id]).to be =~ postmark_message_id_format | ||
it 'message with attachment' do | ||
expect(api_client.deliver(message_with_attachment)).to have_key(:message_id) | ||
end | ||
|
||
it 'returns full Postmark response' do | ||
expect(api_client.deliver(message)).to be_a Hash | ||
it 'response Message-ID' do | ||
expect(api_client.deliver(message)[:message_id]).to be =~ postmark_message_id_format | ||
end | ||
|
||
it 'delivers a message with attachment' do | ||
expect(api_client.deliver(message_with_attachment)).to have_key(:message_id) | ||
it 'response is Hash' do | ||
expect(api_client.deliver(message)).to be_a Hash | ||
end | ||
|
||
it 'fails to deliver a message without body' do | ||
expect { api_client.deliver(message_with_no_body) }.to raise_error(Postmark::InvalidMessageError) | ||
expect {api_client.deliver(message_with_no_body)}.to raise_error(Postmark::InvalidMessageError) | ||
end | ||
|
||
it 'fails to deliver a message with invalid To address' do | ||
expect { api_client.deliver(message_with_invalid_to) }.to raise_error(Postmark::InvalidMessageError) | ||
expect {api_client.deliver(message_with_invalid_to)}.to raise_error(Postmark::InvalidMessageError) | ||
end | ||
end | ||
|
||
context "in batches" do | ||
it 'returns as many responses as many messages were sent' do | ||
context "batch message" do | ||
it 'response messages count' do | ||
expect(api_client.deliver_in_batches(valid_messages).count).to eq valid_messages.count | ||
end | ||
|
||
context "given custom max_batch_size" do | ||
context "custom max_batch_size" do | ||
before do | ||
api_client.max_batch_size = 1 | ||
end | ||
|
||
it 'returns as many responses as many messages were sent' do | ||
it 'response message count' do | ||
expect(api_client.deliver_in_batches(valid_messages).count).to eq valid_messages.count | ||
end | ||
end | ||
|
||
it 'partially delivers a batch of partially valid Mail::Message objects' do | ||
response = api_client.deliver_in_batches(partially_valid_messages) | ||
expect(response).to satisfy { |r| r.count { |mr| mr[:error_code].to_i.zero? } == 2 } | ||
expect(response).to satisfy {|r| r.count {|mr| mr[:error_code].to_i.zero?} == 2} | ||
end | ||
|
||
it "doesn't deliver a batch of invalid Mail::Message objects" do | ||
response = api_client.deliver_in_batches(invalid_messages) | ||
expect(response).to satisfy { |r| r.all? { |mr| !!mr[:error_code] } } | ||
expect(response).to satisfy {|r| r.all? {|mr| !!mr[:error_code]}} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.