Sha256: bc4eec0415547008cb8e026ebbdb62860d0edfb11d72a0d8b8edff75d5bf2357

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 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'
      config.enabled = true
    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.1.0 spec/integration/delivery_spec.rb