Sha256: bf0b9d64afaf3fe9b2b5b2a0ac8d4be1169f59dfd58783357919661d279e4d40

Contents?: true

Size: 1009 Bytes

Versions: 11

Compression:

Stored size: 1009 Bytes

Contents

# frozen_string_literal: true

require 'webmock/rspec'

module Shark
  module RSpec
    module FakeMailingService
      class Request
        include Singleton

        def self.setup
          instance = self.instance
          instance.stub_requests
        end

        def stub_requests
          WebMock.stub_request(:post, %r{^#{host}/mails}).to_return do |request|
            log_info "[Shark][MailingService] Faking POST request with body: #{request.body}"

            id = SecureRandom.uuid
            payload_data = JSON.parse(request.body)['data']

            SharkSpec.fake_response(201, data: {
                                      type: 'mails',
                                      id: id,
                                      attributes: payload_data
                                    })
          end
        end

        def host
          Shark.configuration.mailing_service.site
        end

        def log_info(message)
          message
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
bima-shark-sdk-3.1.1 lib/shark/rspec/fake_mailing_service/request.rb
bima-shark-sdk-2.5.0 lib/shark/rspec/fake_mailing_service/request.rb
bima-shark-sdk-3.1.0 lib/shark/rspec/fake_mailing_service/request.rb
bima-shark-sdk-3.0.0 lib/shark/rspec/fake_mailing_service/request.rb
bima-shark-sdk-2.4.4 lib/shark/rspec/fake_mailing_service/request.rb
bima-shark-sdk-2.4.3 lib/shark/rspec/fake_mailing_service/request.rb
bima-shark-sdk-2.4.2 lib/shark/rspec/fake_mailing_service/request.rb
bima-shark-sdk-2.4.1 lib/shark/rspec/fake_mailing_service/request.rb
bima-shark-sdk-2.4.0 lib/shark/rspec/fake_mailing_service/request.rb
bima-shark-sdk-2.3.1 lib/shark/rspec/fake_mailing_service/request.rb
bima-shark-sdk-2.3.0 lib/shark/rspec/fake_mailing_service/request.rb