Sha256: 36ec0aed87e368d7225d98fc9521eebe61e9b7d96be66152327b8152fd62adac

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require 'spec_helper'

describe 'posting a delivery', :integration do
  let(:contact_email) { "test@example.com" }
  let(:email_name)    { :test }
  let(:data)          { { :greeting => "Gday!" } }

  before do
    Mailstro.configure do |config|
      config.api_key = 'lolapi'
    end
  end

  let(:expected_body) {{
    "api_key"    => "lolapi",
    "to"         => "test@example.com",
    "email_name" => "test",
    "data"       => { "greeting"        => "Gday!" }
  }}

  it "succesfully submits a delivery to mailstro" do
    stub_request(:post, "https://api.mailstroapp.com/v1/deliveries").
      with(:body => expected_body).to_return(:status => 200, :body => fixture("response.json"))

    response = Mailstro.deliver(email_name,
      :to   => contact_email,
      :data => data
    )
    response['success'].should == true
  end

  it "raises an error if the api key is not authorized" do
    stub_request(:post, "https://api.mailstroapp.com/v1/deliveries").
      to_return(:status => 401)

    expect do
      Mailstro.deliver(email_name,
        :to   => contact_email,
        :data => data
      )
    end.to raise_error(Mailstro::Error::AuthorisationError, "api_key not authorised")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mailstro-0.0.10 spec/integration/delivery_spec.rb