Sha256: 3c8c73c9e2fa2c74466e0a46dac4cadd0141e3824e791f2e80e692f552ce6c19

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

require 'spec_helper'

describe DispatchRider::NotificationServices::AwsSns do
  let(:amazon_resource_name) { "arn:aws:sns:us-west-2:123456789012:GeneralTopic" }

  describe "#notifier_builder" do
    it "returns the notifier builder" do
      expect(subject.notifier_builder).to eq(Aws::SNS::Client)
    end
  end

  describe "#channel_registrar_builder" do
    it "returns the channel registrar builder" do
      expect(subject.channel_registrar_builder).to eq(DispatchRider::Registrars::SnsChannel)
    end
  end

  describe "#publish_to_channel" do
    let(:channel) { double(:channel) }
    let(:message) { DispatchRider::Message.new(subject: :test_handler, body: { "bar" => "baz" }) }

    # @note: This is tested this way cause you don't really wanna post a message to the actual service.
    it "publishes the message to the channels" do
      expect(channel).to receive(:publish).with(kind_of Hash) do |serialized_message|
                           expected = {
                             "subject" => "test_handler",
                             "body" => { "bar" => "baz" }
                           }
                           expect(JSON.parse(serialized_message[:message])).to eq(expected)
                         end

      subject.publish_to_channel(channel, message: message)
    end
  end

  describe "#channel" do
    before { allow(subject).to receive(:channel_registrar).and_return(foo: amazon_resource_name) }

    let(:topics) { double :sns_topics }
    let(:topic) { double :sns_topic }

    it "returns the channel" do
      expect(subject.channel(:foo).arn).to eq(amazon_resource_name)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dispatch-rider-2.1.0 spec/lib/dispatch-rider/notification_services/aws_sns_spec.rb
dispatch-rider-2.0.0 spec/lib/dispatch-rider/notification_services/aws_sns_spec.rb