Module: ApiTester::Typo

Defined in:
lib/api-tester/modules/typo.rb

Overview

Module checking various not found scenarios

Class Method Summary collapse

Class Method Details

.allowances(endpoint) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/api-tester/modules/typo.rb', line 48

def self.allowances(endpoint)
  allowances = []
  endpoint.methods.each do |method|
    allowances << method.verb
  end
  allowances.uniq
end

.check_typo_url(base_url, endpoint) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/api-tester/modules/typo.rb', line 23

def self.check_typo_url(base_url, endpoint)
  bad_url = "#{endpoint.url}gibberishadsfasdf"
  bad_endpoint = ApiTester::Endpoint.new name: 'Bad URL',
                                         relative_url: bad_url
  typo_case = BoundaryCase.new description: 'Typo URL check',
                               payload: {},
                               headers: {}
  method = ApiTester::Method.new verb: ApiTester::SupportedVerbs::GET,
                                 response: ApiTester::Response.new(
                                   status_code: 200
                                 ),
                                 request: ApiTester::Request.new
  response = bad_endpoint.call base_url: base_url,
                               method: method,
                               payload: typo_case.payload,
                               headers: typo_case.headers

  test = TypoClass.new response,
                       typo_case.payload,
                       endpoint.not_found_response,
                       bad_url,
                       ApiTester::SupportedVerbs::GET
  test.check
end

.go(contract) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/api-tester/modules/typo.rb', line 9

def self.go(contract)
  reports = []

  # Filtering out endpoints with ids since not a better way to check this
  # Need to redesign system to handle this better
  contract.endpoints.reject { |e| e.relative_url.include?('{') }.each do |endpoint|
    allowances(endpoint).each do
      reports.concat check_typo_url(contract.base_url, endpoint)
    end
  end

  reports
end

.orderObject



56
57
58
# File 'lib/api-tester/modules/typo.rb', line 56

def self.order
  4
end