Sha256: 6def62d15d0405ab244fe2b1df205c3ace03af11bb3a0e68c94e131964426ec5

Contents?: true

Size: 1.24 KB

Versions: 10

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true
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' }
      stub_request(:post, @delivery.url).to_return(headers: headers, 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

10 entries across 10 versions & 1 rubygems

Version Path
shipit-engine-0.39.0 test/models/delivery_test.rb
shipit-engine-0.38.0 test/models/delivery_test.rb
shipit-engine-0.37.0 test/models/delivery_test.rb
shipit-engine-0.36.1 test/models/delivery_test.rb
shipit-engine-0.36.0 test/models/delivery_test.rb
shipit-engine-0.35.1 test/models/delivery_test.rb
shipit-engine-0.35.0 test/models/delivery_test.rb
shipit-engine-0.34.0 test/models/delivery_test.rb
shipit-engine-0.33.0 test/models/delivery_test.rb
shipit-engine-0.32.0 test/models/delivery_test.rb