spec/rest/asm/suppressions_spec.rb in sendgrid4r-0.5.0 vs spec/rest/asm/suppressions_spec.rb in sendgrid4r-1.0.0

- old
+ new

@@ -4,145 +4,100 @@ describe SendGrid4r::REST::Asm::Suppressions do describe 'integration test', :it do before do begin Dotenv.load - @client = SendGrid4r::Client.new( - username: ENV['SENDGRID_USERNAME'], - password: ENV['SENDGRID_PASSWORD']) + @client = SendGrid4r::Client.new(api_key: ENV['API_KEY']) @email1 = 'test1@test.com' @email2 = 'test2@test.com' @email3 = 'test3@test.com' @group_name = 'suppressions_test' @group_desc = 'group_desc' # celan up test env grps = @client.get_groups grps.each do |grp| next if grp.name != @group_name - emails = @client.get_suppressed_emails(grp.id) + emails = @client.get_suppressed_emails(group_id: grp.id) emails.each do |email| - @client.delete_suppressed_email(grp.id, email) + @client.delete_suppressed_email( + group_id: grp.id, email_address: email + ) end - @client.delete_group(grp.id) + @client.delete_group(group_id: grp.id) end # post a group - @group = @client.post_group(@group_name, @group_desc) + @group = @client.post_group(name: @group_name, description: @group_desc) # post suppressed email - @client.post_suppressed_emails(@group.id, [@email1]) - rescue => e + @client.post_suppressed_emails( + group_id: @group.id, recipient_emails: [@email1] + ) + rescue RestClient::ExceptionWithResponse => e puts e.inspect raise e end end context 'wthout block call' do it '#post_suppressed_emails' do begin emails = @client.post_suppressed_emails( - @group.id, [@email2, @email3] + group_id: @group.id, recipient_emails: [@email2, @email3] ) expect(emails.recipient_emails.length).to eq(2) expect(emails.recipient_emails[0]).to eq(@email2) expect(emails.recipient_emails[1]).to eq(@email3) - rescue => e + rescue RestClient::ExceptionWithResponse => e puts e.inspect raise e end end it '#get_suppressed_emails' do begin - emails = @client.get_suppressed_emails(@group.id) + emails = @client.get_suppressed_emails(group_id: @group.id) expect(emails.length).to eq(1) expect(emails[0]).to eq(@email1) - rescue => e + rescue RestClient::ExceptionWithResponse => e puts e.inspect raise e end end it '#get_suppressions' do begin - suppressions = @client.get_suppressions(@email1) + suppressions = @client.get_suppressions(email_address: @email1) expect(suppressions.suppressions).to be_a(Array) suppressions.suppressions.each do |suppression| next unless suppression.name == @group_name expect(suppression.name).to eq(@group_name) expect(suppression.description).to eq(@group_desc) expect(suppression.suppressed).to eq(true) end - rescue => e + rescue RestClient::ExceptionWithResponse => e puts e.inspect raise e end end it '#delete_suppressed_email' do begin - @client.delete_suppressed_email(@group.id, @email1) - @client.delete_suppressed_email(@group.id, @email2) - @client.delete_suppressed_email(@group.id, @email3) - rescue => e + @client.delete_suppressed_email( + group_id: @group.id, email_address: @email1 + ) + @client.delete_suppressed_email( + group_id: @group.id, email_address: @email2 + ) + @client.delete_suppressed_email( + group_id: @group.id, email_address: @email3 + ) + rescue RestClient::ExceptionWithResponse => e puts e.inspect raise e end end end - - context 'with block call' do - it '#post_suppressed_emails' do - @client.post_suppressed_emails( - @group.id, [@email2, @email3] - ) do |resp, req, res| - resp = - SendGrid4r::REST::Asm.create_recipient_emails( - JSON.parse(resp) - ) - expect(resp).to be_a( - SendGrid4r::REST::Asm::RecipientEmails - ) - expect(req).to be_a(RestClient::Request) - expect(res).to be_a(Net::HTTPCreated) - end - end - - it '#get_suppressed_emails' do - @client.get_suppressed_emails(@group.id) do |resp, req, res| - resp = - SendGrid4r::REST::Asm::Suppressions.create_emails(JSON.parse(resp)) - expect(resp).to be_a(Array) - resp.each do |email| - expect(email).to be_a(String) - end - expect(req).to be_a(RestClient::Request) - expect(res).to be_a(Net::HTTPOK) - end - end - - it '#get_suppressions' do - @client.get_suppressions(@email1) do |resp, req, res| - resp = - SendGrid4r::REST::Asm::Suppressions.create_suppressions( - JSON.parse(resp) - ) - expect(resp).to be_a( - SendGrid4r::REST::Asm::Suppressions::Suppressions - ) - expect(req).to be_a(RestClient::Request) - expect(res).to be_a(Net::HTTPOK) - end - end - - it '#delete_suppressed_email' do - @client.delete_suppressed_email(@group.id, @email1) do |resp, req, res| - expect(resp).to eq('') - expect(req).to be_a(RestClient::Request) - expect(res).to be_a(Net::HTTPNoContent) - end - end - end end describe 'unit test', :ut do let(:client) do SendGrid4r::Client.new(api_key: '') @@ -205,33 +160,35 @@ ) end it '#post_suppressed_emails' do allow(client).to receive(:execute).and_return(recipient_emails) - actual = client.post_suppressed_emails(0, ['', '']) + actual = client.post_suppressed_emails( + group_id: 0, recipient_emails: ['', ''] + ) expect(actual).to be_a(SendGrid4r::REST::Asm::RecipientEmails) end it '#get_suppressed_emails' do allow(client).to receive(:execute).and_return(emails) - actual = client.get_suppressed_emails(0) + actual = client.get_suppressed_emails(group_id: 0) expect(actual).to be_a(Array) end it '#get_suppressions' do allow(client).to receive(:execute).and_return(suppressions) - actual = client.get_suppressions('') + actual = client.get_suppressions(email_address: '') expect(actual.suppressions).to be_a(Array) actual.suppressions.each do |suppression| expect(suppression).to be_a( SendGrid4r::REST::Asm::Suppressions::Suppression ) end end it '#delete_suppressed_email' do allow(client).to receive(:execute).and_return('') - actual = client.delete_suppressed_email(0, '') + actual = client.delete_suppressed_email(group_id: 0, email_address: '') expect(actual).to eq('') end it 'creates suppression instance' do actual = SendGrid4r::REST::Asm::Suppressions.create_suppression(