Sha256: acc3147ae65d0ce297e003645fe1b804eee8ccd895f40faaff8255835005a400

Contents?: true

Size: 838 Bytes

Versions: 2

Compression:

Stored size: 838 Bytes

Contents

# frozen_string_literal: true

require 'api-tester/reporter/missing_field_report'

module ApiTester
  # Ensures all fields defined in contract are returned during test suite
  module UnusedFields
    def self.go(contract)
      reports = []

      contract.endpoints.each do |endpoint|
        endpoint.methods.each do |method|
          method.expected_response.body.filter(&:has_key).each do |field|
            next unless field.is_seen.zero?

            reports << MissingFieldReport.new(url: endpoint.url,
                                              verb: method.verb,
                                              expected_field: field.name,
                                              description: 'UnusedFieldsModule')
          end
        end
      end

      reports
    end

    def self.order
      99
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
api-tester-1.1.3 lib/api-tester/modules/unused_fields.rb
api-tester-1.1.2 lib/api-tester/modules/unused_fields.rb