Module: GdsApi::TestHelpers::LinkCheckerApi
- Defined in:
- lib/gds_api/test_helpers/link_checker_api.rb
Constant Summary collapse
- LINK_CHECKER_API_ENDPOINT =
Plek.current.find("link-checker-api")
Instance Method Summary collapse
- #link_checker_api_batch_report_hash(id:, status: :completed, links: [], totals: {}, completed_at: nil) ⇒ Object
- #link_checker_api_link_report_hash(uri:, status: :ok, checked: nil, errors: [], warnings: [], problem_summary: nil, suggested_fix: nil) ⇒ Object
- #stub_link_checker_api_check(uri:, status: :ok, checked: nil, errors: [], warnings: [], problem_summary: nil, suggested_fix: nil) ⇒ Object
- #stub_link_checker_api_create_batch(uris:, checked_within: nil, webhook_uri: nil, webhook_secret_token: nil, id: 0, status: :in_progress, links: nil, totals: {}, completed_at: nil) ⇒ Object
- #stub_link_checker_api_get_batch(id:, status: :completed, links: [], totals: {}, completed_at: nil) ⇒ Object
- #stub_link_checker_api_upsert_resource_monitor(app:, reference:, links:) ⇒ Object
Instance Method Details
#link_checker_api_batch_report_hash(id:, status: :completed, links: [], totals: {}, completed_at: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/gds_api/test_helpers/link_checker_api.rb', line 20 def link_checker_api_batch_report_hash(id:, status: :completed, links: [], totals: {}, completed_at: nil) { id: id, status: status, links: links.map { |hash| link_checker_api_link_report_hash(**hash) }, totals: totals, completed_at: completed_at || Time.now.iso8601, } end |
#link_checker_api_link_report_hash(uri:, status: :ok, checked: nil, errors: [], warnings: [], problem_summary: nil, suggested_fix: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/gds_api/test_helpers/link_checker_api.rb', line 8 def link_checker_api_link_report_hash(uri:, status: :ok, checked: nil, errors: [], warnings: [], problem_summary: nil, suggested_fix: nil) { uri: uri, status: status, checked: checked || Time.now.iso8601, errors: errors, warnings: warnings, problem_summary: problem_summary, suggested_fix: suggested_fix, } end |
#stub_link_checker_api_check(uri:, status: :ok, checked: nil, errors: [], warnings: [], problem_summary: nil, suggested_fix: nil) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/gds_api/test_helpers/link_checker_api.rb', line 30 def stub_link_checker_api_check(uri:, status: :ok, checked: nil, errors: [], warnings: [], problem_summary: nil, suggested_fix: nil) body = link_checker_api_link_report_hash( uri: uri, status: status, checked: checked, errors: errors, warnings: warnings, problem_summary: problem_summary, suggested_fix: suggested_fix, ).to_json stub_request(:get, "#{LINK_CHECKER_API_ENDPOINT}/check") .with(query: { uri: uri }) .to_return(body: body, status: 200, headers: { "Content-Type" => "application/json" }) end |
#stub_link_checker_api_create_batch(uris:, checked_within: nil, webhook_uri: nil, webhook_secret_token: nil, id: 0, status: :in_progress, links: nil, totals: {}, completed_at: nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gds_api/test_helpers/link_checker_api.rb', line 49 def stub_link_checker_api_create_batch(uris:, checked_within: nil, webhook_uri: nil, webhook_secret_token: nil, id: 0, status: :in_progress, links: nil, totals: {}, completed_at: nil) links = uris.map { |uri| { uri: uri } } if links.nil? response_body = link_checker_api_batch_report_hash( id: id, status: status, links: links, totals: totals, completed_at: completed_at, ).to_json request_body = { uris: uris, checked_within: checked_within, webhook_uri: webhook_uri, webhook_secret_token: webhook_secret_token, }.delete_if { |_, v| v.nil? }.to_json stub_request(:post, "#{LINK_CHECKER_API_ENDPOINT}/batch") .with(body: request_body) .to_return( body: response_body, status: status == :in_progress ? 202 : 201, headers: { "Content-Type" => "application/json" }, ) end |
#stub_link_checker_api_get_batch(id:, status: :completed, links: [], totals: {}, completed_at: nil) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/gds_api/test_helpers/link_checker_api.rb', line 40 def stub_link_checker_api_get_batch(id:, status: :completed, links: [], totals: {}, completed_at: nil) body = link_checker_api_batch_report_hash( id: id, status: status, links: links, totals: totals, completed_at: completed_at, ).to_json stub_request(:get, "#{LINK_CHECKER_API_ENDPOINT}/batch/#{id}") .to_return(body: body, status: 200, headers: { "Content-Type" => "application/json" }) end |
#stub_link_checker_api_upsert_resource_monitor(app:, reference:, links:) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/gds_api/test_helpers/link_checker_api.rb', line 76 def stub_link_checker_api_upsert_resource_monitor(app:, reference:, links:) response_body = { id: 1 }.to_json request_body = { links: links, app: app, reference: reference, }.to_json stub_request(:post, "#{LINK_CHECKER_API_ENDPOINT}/monitor") .with(body: request_body) .to_return( body: response_body, headers: { "Content-Type" => "application/json" }, ) end |