Sha256: c3cfbecc011370821667e4599b5819abf4f676653c8affa05bae4418356e59dd

Contents?: true

Size: 1.86 KB

Versions: 24

Compression:

Stored size: 1.86 KB

Contents

require 'spec_helper'
require 'mailgun'

vcr_opts = { :cassette_name => "webhooks" }

describe 'For the webhooks endpoint', order: :defined, vcr: vcr_opts do
  before(:all) do
    @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
    @domain = TESTDOMAIN
    @testhook = 'bounce'
    @testhookup = 'bounceup'
  end

  it 'creates a webhook' do
    result = @mg_obj.post("domains/#{@domain}/webhooks", { id: 'bounce',
                                                           url: "http://example.com/mailgun/events/#{@testhook}" } )

    result.to_h!
    expect(result.body["message"]).to eq("Webhook has been created")
    expect(result.body["webhook"]["url"]).to eq("http://example.com/mailgun/events/#{@testhook}")
  end

  it 'gets a webhook.' do
    result = @mg_obj.get("domains/#{@domain}/webhooks/#{@testhook}")

    result.to_h!
    expect(result.body["webhook"]["url"]).to eq("http://example.com/mailgun/events/#{@testhook}")
  end

  it 'gets a list of all webhooks.' do
    result = @mg_obj.get("domains/#{@domain}/webhooks")

    result.to_h!
    expect(result.body["webhooks"]["bounce"]["url"]).to eq("http://example.com/mailgun/events/#{@testhook}")
  end

  it 'updates a webhook.' do
    result = @mg_obj.put("domains/#{@domain}/webhooks/bounce", {:id => 'bounce',
                                                                :url => "http://example.com/mailgun/events/#{@testhookup}"})

    result.to_h!
    expect(result.body["message"]).to eq("Webhook has been updated")
    expect(result.body["webhook"]["url"]).to eq("http://example.com/mailgun/events/#{@testhookup}")
  end

  it 'removes a webhook' do
    result = @mg_obj.delete("domains/#{@domain}/webhooks/bounce")

    result.to_h!
    expect(result.body['message']).to eq("Webhook has been deleted")
    expect(result.body['webhook']['url']).to eq("http://example.com/mailgun/events/#{@testhookup}")
  end

end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
mailgun-ruby-1.2.13 spec/integration/webhook_spec.rb
mailgun-ruby-1.2.12 spec/integration/webhook_spec.rb
mailgun-ruby-1.2.11 spec/integration/webhook_spec.rb
mailgun-ruby-1.2.10 spec/integration/webhook_spec.rb
mailgun-ruby-1.2.9 spec/integration/webhook_spec.rb
mailgun-ruby-1.2.8 spec/integration/webhook_spec.rb
mailgun-ruby-1.2.7 spec/integration/webhook_spec.rb
mailgun-ruby-1.2.6 spec/integration/webhook_spec.rb
mailgun-ruby-1.2.5 spec/integration/webhook_spec.rb
mailgun-ruby-1.2.4 spec/integration/webhook_spec.rb
mailgun-ruby-1.2.3 spec/integration/webhook_spec.rb
mailgun-ruby-1.2.0 spec/integration/webhook_spec.rb
mailgun-ruby-1.1.11 spec/integration/webhook_spec.rb
mailgun-ruby-1.1.10 spec/integration/webhook_spec.rb
mailgun-ruby-1.1.9 spec/integration/webhook_spec.rb
wj-mailgun-ruby-1.1.7 spec/integration/webhook_spec.rb
mailgun-ruby-1.1.8 spec/integration/webhook_spec.rb
mailgun-ruby-1.1.6 spec/integration/webhook_spec.rb
mailgun-ruby-1.1.5 spec/integration/webhook_spec.rb
mailgun-ruby-1.1.4 spec/integration/webhook_spec.rb