spec/integration/email_validation_spec.rb in mailgun-ruby-1.1.0 vs spec/integration/email_validation_spec.rb in mailgun-ruby-1.1.1

- old
+ new

@@ -1,29 +1,57 @@ require 'spec_helper' + require 'mailgun' +require 'mailgun/address' vcr_opts = { :cassette_name => "email_validation" } -describe 'For the Email Validation endpoint', vcr: vcr_opts do +describe 'For the email validation endpoint', order: :defined, vcr: vcr_opts do before(:all) do - @mg_obj = Mailgun::Client.new(PUB_APIKEY) + @mg_obj = Mailgun::Address.new(PUB_APIKEY) + + @valid = ["Alice <alice@example.com>", "bob@example.com"] + @invalid = ["example.org"] + + @all_addrs = @valid + @invalid end - it 'validates an address.' do - result = @mg_obj.get("address/validate", - {:address => "test@#{TESTDOMAIN}"}) + it 'returns parsed and unparsable lists' do + res = @mg_obj.parse(@all_addrs) - result.to_h! - expect(result.body["is_valid"]).to eq(true) - expect(result.body["address"]).to eq("test@#{TESTDOMAIN}") + expect(res["parsed"]).to eq(@valid) + expect(res["unparseable"]).to eq(@invalid) end - it 'parses an address.' do - result = @mg_obj.get("address/parse", - {:addresses => "Alice <alice@#{TESTDOMAIN}>,bob@#{TESTDOMAIN},#{TESTDOMAIN}"}) + it 'validates alice@mailgun.net with info' do + res = @mg_obj.validate("alice@mailgun.net") - result.to_h! - expect(result.body["parsed"]).to include("Alice <alice@#{TESTDOMAIN}>") - expect(result.body["parsed"]).to include("bob@#{TESTDOMAIN}") - expect(result.body["unparseable"]).to include("#{TESTDOMAIN}") + expected = { + "address" => "alice@mailgun.net", + "did_you_mean" => nil, + "is_valid" => true, + "parts" => { + "display_name" => nil, + "domain" => "mailgun.net", + "local_part" => "alice", + }, + } + expect(res).to eq(expected) end + + it 'fails to validate example.org' do + res = @mg_obj.validate("example.org") + + expected = { + "address" => "example.org", + "did_you_mean" => nil, + "is_valid" => false, + "parts" => { + "display_name" => nil, + "domain" => nil, + "local_part" => nil, + }, + } + expect(res).to eq(expected) + end + end