Sha256: da336fb1eda67cedc3768a965b20dc89175a8e132170e217ad68f5aed449a0e6

Contents?: true

Size: 1.21 KB

Versions: 42

Compression:

Stored size: 1.21 KB

Contents

require 'test_helper'

module Shipit
  class DeliveryTest < ActiveSupport::TestCase
    setup do
      @hook = shipit_hooks(:shipit_deploys)
      @delivery = shipit_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
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
shipit-engine-0.28.0 test/models/delivery_test.rb
shipit-engine-0.27.1 test/models/delivery_test.rb
shipit-engine-0.27.0 test/models/delivery_test.rb
shipit-engine-0.26.0 test/models/delivery_test.rb
shipit-engine-0.25.1 test/models/delivery_test.rb
shipit-engine-0.25.0 test/models/delivery_test.rb
shipit-engine-0.24.0 test/models/delivery_test.rb
shipit-engine-0.23.1 test/models/delivery_test.rb
shipit-engine-0.23.0 test/models/delivery_test.rb
shipit-engine-0.22.0 test/models/delivery_test.rb
shipit-engine-0.21.0 test/models/delivery_test.rb
shipit-engine-0.20.1 test/models/delivery_test.rb
shipit-engine-0.20.0 test/models/delivery_test.rb
shipit-engine-0.19.0 test/models/delivery_test.rb
shipit-engine-0.18.1 test/models/delivery_test.rb
shipit-engine-0.18.0 test/models/delivery_test.rb
shipit-engine-0.17.0 test/models/delivery_test.rb
shipit-engine-0.16.0 test/models/delivery_test.rb
shipit-engine-0.15.0 test/models/delivery_test.rb
shipit-engine-0.14.0 test/models/delivery_test.rb