Sha256: 7ab773353b1ba7406f9b8be402b910a18175dce802353bec79da602be44b4d1d

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'spec_helper'

describe 'posting a delivery', :integration do
  let(:template_name) { :test }
  let(:contact_email) { "test@example.com" }
  let(:data)          { { :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",
    "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(template_name, contact_email, 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(template_name, contact_email, 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.6 spec/integration/delivery_spec.rb