Sha256: cc9cb07702b763353d373cfae0a86b1610a528ad05afeea5e8540ec26c239dbf

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require 'spec_helper'

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

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

  let(:expected_body) {{
    "api_key"       => "lolapi",
    "template_name" => "test",
    "contact_email" => "test@example.com",
    "payload"       => { "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("deliveries.json"))

    response = Mailstro.deliver(template_name, contact_email, payload)
    response['ok'].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(template_name, contact_email, payload)
    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.4 spec/integration/posting_a_delivery_spec.rb