Sha256: 0e217dc8f683fa3d7eed1f66fd5eed4f7a32aee7da266b9809f031d89bd575bf

Contents?: true

Size: 1.99 KB

Versions: 1

Compression:

Stored size: 1.99 KB

Contents

require 'tester/reporter/status_code_report'
require 'tester/modules/module'
require 'tester/util/supported_verbs'

class Typo < Module
    def go(definition, report)
        super

        contract = allowances(definition)

        contract.each do |url, verbs|
            check_verbs definition, url, verbs

            check_typo_url definition, url
        end

        report.reports == []
    end

    def check_verbs definition, url, verbs
        missing_verbs = SupportedVerbs.all - verbs
        missing_verbs.each do |verb|
            check_method = create_api_method url, verb
            typo_case = BoundaryCase.new("Typo verb check #{verb}", {}, {})
            response = self.call check_method, typo_case

            test = TypoClass.new response, typo_case.payload, definition.not_allowed_response, url, verb
            reports = test.check
            self.report.reports.concat reports
        end
    end

    def check_typo_url definition, url
        bad_url = "#{url}gibberishadsfasdf"
        typo_case = BoundaryCase.new("Typo URL check", {}, {})
        check_method = create_api_method bad_url, SupportedVerbs::GET
        response = self.call check_method, typo_case

        test = TypoClass.new response, typo_case.payload, definition.not_found_response, bad_url, SupportedVerbs::GET
            reports = test.check
        self.report.reports.concat reports
    end

    def create_api_method url, verb
      method = SupportedVerbs.get_method_for(verb)
      method.new url
    end

    def allowances(definition)
        allowances = {}
        definition.methods.each do |method|
            url = method.url
            if allowances[url]
                allowances[url] << method.verb
            else
                allowances[url] = [method.verb]
            end
        end
        allowances
    end
end

class TypoClass < MethodCaseTest
    def initialize response, payload, expected_response, url, verb
        super response, payload, expected_response, url, verb, "TypoModule"
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
api-tester-0.0.1 lib/tester/modules/typo.rb