Sha256: 08d61eab52f081f58a1ca2b16d428ddd0c8433780f41f1acee0fb3da644e948d

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

require File.expand_path('../test_helper', __FILE__)

module Propono
  class QueueSubscriptionTest < Minitest::Test
    def test_create_topic
      topic_id = 'foobar'
      topic = Topic.new(topic_id)
      TopicCreator.expects(:find_or_create).with(topic_id).returns(topic)
      QueueSubscription.create(topic_id)
    end

    def test_sqs_create_is_called
      topic_id = "Foobar"
      subscription = QueueSubscription.new(topic_id)

      TopicCreator.stubs(find_or_create: Topic.new("1123"))

      sqs = mock()
      sqs.expects(:create_queue).with(subscription.send(:queue_name)).returns(mock(body: {'QueueUrl' => Fog::AWS::SQS::Mock::QueueUrl}))
      QueueCreator.any_instance.stubs(sqs: sqs)

      subscription.create
    end

    def test_subscription_queue_name
      config.application_name = "MyApp"

      topic_id = "Foobar"
      subscription = QueueSubscription.new(topic_id)

      assert_equal subscription.send(:queue_name), "MyApp::Foobar"
    end

    def test_subscription_queue_name_with_spaces
      config.application_name = "My App"

      topic_id = "Foobar"
      subscription = QueueSubscription.new(topic_id)

      assert_equal subscription.send(:queue_name), "My_App::Foobar"
    end

    def test_create_calls_create
      arn = "arn123"

      TopicCreator.stubs(find_or_create: Topic.new(arn))
      QueueCreator.stubs(find_or_create: Queue.new(Fog::AWS::SQS::Mock::QueueUrl))

      sns = mock()
      sns.expects(:subscribe).with(arn, Fog::AWS::SQS::Mock::QueueArn, 'sqs')
      subscription = QueueSubscription.new("Some topic")
      subscription.stubs(sns: sns)
      subscription.create
    end

    def test_create_saves_queue
      queue = Queue.new(Fog::AWS::SQS::Mock::QueueUrl)

      QueueCreator.expects(:find_or_create).returns(queue)
      subscription = QueueSubscription.new("Some Topic")
      subscription.create
      assert_equal queue, subscription.queue
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
propono-0.4.0 test/queue_subscription_test.rb