Module: GdsApi::TestHelpers::Router

Defined in:
lib/gds_api/test_helpers/router.rb

Constant Summary collapse

ROUTER_API_ENDPOINT =
Plek.current.find('router-api')

Instance Method Summary collapse

Instance Method Details

#stub_all_router_registrationObject


8
9
10
11
12
# File 'lib/gds_api/test_helpers/router.rb', line 8

def stub_all_router_registration
  stub_request(:put, %r{\A#{ROUTER_API_ENDPOINT}/backends/[a-z0-9-]+\z})
  stub_request(:put, "#{ROUTER_API_ENDPOINT}/routes")
  stub_request(:post, "#{ROUTER_API_ENDPOINT}/routes/commit")
end

#stub_gone_route_registration(path, type) ⇒ Object


49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gds_api/test_helpers/router.rb', line 49

def stub_gone_route_registration(path, type)
  route = { route: {
                incoming_path: path,
                route_type: type,
                handler: 'gone' }
            }

  register_stub = stub_route_put(route)
  commit_stub = stub_router_commit
  [register_stub, commit_stub]
end

#stub_redirect_registration(path, type, destination, redirect_type, segments_mode = nil) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gds_api/test_helpers/router.rb', line 34

def stub_redirect_registration(path, type, destination, redirect_type, segments_mode = nil)
  redirect = { route: {
                incoming_path: path,
                route_type: type,
                handler: 'redirect',
                redirect_to: destination,
                redirect_type: redirect_type,
                segments_mode: segments_mode }
            }

  register_stub = stub_route_put(redirect)
  commit_stub = stub_router_commit
  [register_stub, commit_stub]
end

#stub_route_registration(path, type, backend_id) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gds_api/test_helpers/router.rb', line 21

def stub_route_registration(path, type, backend_id)
  route = { route: {
              incoming_path: path,
              route_type: type,
              handler: 'backend',
              backend_id: backend_id }
          }

  register_stub = stub_route_put(route)
  commit_stub = stub_router_commit
  [register_stub, commit_stub]
end

#stub_router_backend_registration(backend_id, backend_url) ⇒ Object


14
15
16
17
18
19
# File 'lib/gds_api/test_helpers/router.rb', line 14

def stub_router_backend_registration(backend_id, backend_url)
  backend = { "backend" => { "backend_url" => backend_url } }
  stub_http_request(:put, "#{ROUTER_API_ENDPOINT}/backends/#{backend_id}")
      .with(body: backend.to_json)
      .to_return(status: 201)
end

#stub_router_commitObject


61
62
63
# File 'lib/gds_api/test_helpers/router.rb', line 61

def stub_router_commit
  stub_http_request(:post, "#{ROUTER_API_ENDPOINT}/routes/commit")
end