Sha256: de9bd3372688c3ab18e7f306d40938047aab6b9f2cdacd78943504bd5774b9da

Contents?: true

Size: 957 Bytes

Versions: 13

Compression:

Stored size: 957 Bytes

Contents

# typed: true
# frozen_string_literal: true

module Workato
  module Testing
    class VCRMultipartBodyMatcher
      MULTIPART_HEADER_MATCHER = %r{^multipart/form-data; boundary=(.+)$}.freeze
      private_constant :MULTIPART_HEADER_MATCHER

      class << self
        def call(request1, request2)
          normalized_multipart_body(request1) == normalized_multipart_body(request2)
        end

        private

        def normalized_multipart_body(request)
          content_type = (request.headers['Content-Type'] || []).first.to_s

          return request.body unless multipart_request?(content_type)

          boundary = MULTIPART_HEADER_MATCHER.match(content_type)[1]
          request.body.gsub(boundary, '----RubyFormBoundaryTsqIBL0iujC5POpr')
        end

        def multipart_request?(content_type)
          return false if content_type.empty?

          MULTIPART_HEADER_MATCHER.match?(content_type)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
workato-connector-sdk-1.3.13 lib/workato/testing/vcr_multipart_body_matcher.rb
workato-connector-sdk-1.3.12 lib/workato/testing/vcr_multipart_body_matcher.rb
workato-connector-sdk-1.3.11 lib/workato/testing/vcr_multipart_body_matcher.rb
workato-connector-sdk-1.3.10 lib/workato/testing/vcr_multipart_body_matcher.rb
workato-connector-sdk-1.3.9 lib/workato/testing/vcr_multipart_body_matcher.rb
workato-connector-sdk-1.3.8 lib/workato/testing/vcr_multipart_body_matcher.rb
workato-connector-sdk-1.3.7 lib/workato/testing/vcr_multipart_body_matcher.rb
workato-connector-sdk-1.3.6 lib/workato/testing/vcr_multipart_body_matcher.rb
workato-connector-sdk-1.3.5 lib/workato/testing/vcr_multipart_body_matcher.rb
workato-connector-sdk-1.3.4 lib/workato/testing/vcr_multipart_body_matcher.rb
workato-connector-sdk-1.3.3 lib/workato/testing/vcr_multipart_body_matcher.rb
workato-connector-sdk-1.3.2 lib/workato/testing/vcr_multipart_body_matcher.rb
workato-connector-sdk-1.3.1 lib/workato/testing/vcr_multipart_body_matcher.rb