Sha256: 8ff60d10894e1d5de07f28f84a8744342c1aa2da1fc43f3468725ea0c5df1f98

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

require 'action_mailbox_amazon_ingress/rspec/email'
require 'action_mailbox_amazon_ingress/rspec/subscription_confirmation'

module ActionMailboxAmazonIngress
  module RSpec
    def amazon_ingress_deliver_subscription_confirmation(options = {})
      subscription_confirmation = SubscriptionConfirmation.new(**options)
      stub_aws_sns_message_verifier(subscription_confirmation)
      stub_aws_sns_subscription_request

      post subscription_confirmation.url,
           params: subscription_confirmation.params,
           headers: subscription_confirmation.headers,
           as: :json
    end

    def amazon_ingress_deliver_email(options = {})
      email = Email.new(**options)
      stub_aws_sns_message_verifier(email)

      post email.url,
           params: email.params,
           headers: email.headers,
           as: :json
    end

    private

    def message_verifier(subscription_confirmation)
      instance_double(Aws::SNS::MessageVerifier, authentic?: subscription_confirmation.authentic?)
    end

    def stub_aws_sns_message_verifier(notification)
      allow(Aws::SNS::MessageVerifier).to receive(:new) { message_verifier(notification) }
    end

    def stub_aws_sns_subscription_request
      allow(Net::HTTP).to receive(:get_response).and_call_original
      allow(Net::HTTP)
        .to receive(:get_response)
          .with(URI('http://example.com/subscribe')) { double(code: '200') }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
action_mailbox_amazon_ingress-0.2.0 lib/action_mailbox_amazon_ingress/rspec.rb