Sha256: f0231602c0e95de6863684a37fa39270eeaf83cddd8c8114adeb12a7ffe6e6d1

Contents?: true

Size: 1.12 KB

Versions: 22

Compression:

Stored size: 1.12 KB

Contents

require 'test_helper'

class DeliveryTest < ActiveSupport::TestCase
  setup do
    @hook = hooks(:shipit_deploys)
    @delivery = deliveries(:scheduled_shipit_deploy)
  end

  test "#schedule! enqueue a DeliverHookJob and update the status to `scheduled`" do
    delivery = @hook.deliveries.create!(
      event: 'deploy',
      url: 'http://example.com',
      content_type: 'application/json',
      payload: '{}',
    )
    assert_equal 'pending', delivery.status

    assert_enqueued_with(job: DeliverHookJob, args: [delivery]) do
      delivery.schedule!
    end
    assert_equal 'scheduled', delivery.status
  end

  test "#send! post the payload and update the status to `sent`" do
    headers = {'content-type' => 'text/plain', 'content-length' => '2'}
    FakeWeb.register_uri(:post, @delivery.url, headers.merge(body: 'OK'))

    assert_equal 'scheduled', @delivery.status
    @delivery.send!

    assert_equal 'sent', @delivery.status
    assert_not_nil @delivery.delivered_at
    assert_equal 200, @delivery.response_code
    assert_equal headers, @delivery.response_headers
    assert_equal 'OK', @delivery.response_body
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
shipit-engine-0.5.2 test/models/delivery_test.rb
shipit-engine-0.5.1 test/models/delivery_test.rb
shipit-engine-0.5.0 test/models/delivery_test.rb
shipit-engine-0.4.10 test/models/delivery_test.rb
shipit-engine-0.4.9 test/models/delivery_test.rb
shipit-engine-0.4.8 test/models/delivery_test.rb
shipit-engine-0.4.7 test/models/delivery_test.rb
shipit-engine-0.4.6 test/models/delivery_test.rb
shipit-engine-0.4.5 test/models/delivery_test.rb
shipit-engine-0.4.4 test/models/delivery_test.rb
shipit-engine-0.4.3 test/models/delivery_test.rb
shipit-engine-0.4.2 test/models/delivery_test.rb
shipit-engine-0.4.1 test/models/delivery_test.rb
shipit-engine-0.4.0 test/models/delivery_test.rb
shipit-engine-0.3.1 test/models/delivery_test.rb
shipit-engine-0.3.0 test/models/delivery_test.rb
shipit-engine-0.2.3 test/models/delivery_test.rb
shipit-engine-0.2.2 test/models/delivery_test.rb
shipit-engine-0.2.1 test/models/delivery_test.rb
shipit-engine-0.2.0 test/models/delivery_test.rb