Sha256: 1042dbde9dc0a3dfe520e47c78cf92c10a6de33a465a53826dc6740d80423e5e

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

require 'spec_helper'

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

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

  let(:expected_body) {{
    "api_key"       => "lolapi",
    "contact_email" => "test@example.com",
    "template_name" => "test",
    "template_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(
      :to            => contact_email,
      :template_name => template_name,
      :template_data => template_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(
        :to            => contact_email,
        :template_name => template_name,
        :template_data => template_data
      )
    end.to raise_error(Mailstro::Error::AuthorisationError, "api_key not authorised")
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mailstro-0.0.9 spec/integration/delivery_spec.rb
mailstro-0.0.8 spec/integration/delivery_spec.rb
mailstro-0.0.7 spec/integration/delivery_spec.rb