Module: GdsApi::TestHelpers::AssetManager

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

Constant Summary collapse

ASSET_MANAGER_ENDPOINT =
Plek.current.find('asset-manager')

Instance Method Summary collapse

Instance Method Details

#asset_manager_does_not_have_a_whitehall_asset(legacy_url_path) ⇒ Object


29
30
31
32
33
34
35
36
# File 'lib/gds_api/test_helpers/asset_manager.rb', line 29

def asset_manager_does_not_have_a_whitehall_asset(legacy_url_path)
  response = {
    "_response_info" => { "status" => "not found" }
  }

  stub_request(:get, "#{ASSET_MANAGER_ENDPOINT}/whitehall_assets/#{legacy_url_path}")
    .to_return(body: response.to_json, status: 404)
end

#asset_manager_does_not_have_an_asset(id) ⇒ Object


20
21
22
23
24
25
26
27
# File 'lib/gds_api/test_helpers/asset_manager.rb', line 20

def asset_manager_does_not_have_an_asset(id)
  response = {
    "_response_info" => { "status" => "not found" }
  }

  stub_request(:get, "#{ASSET_MANAGER_ENDPOINT}/assets/#{id}")
    .to_return(body: response.to_json, status: 404)
end

#asset_manager_has_a_whitehall_asset(legacy_url_path, atts) ⇒ Object


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

def asset_manager_has_a_whitehall_asset(legacy_url_path, atts)
  response = atts.merge("_response_info" => { "status" => "ok" })

  stub_request(:get, "#{ASSET_MANAGER_ENDPOINT}/whitehall_assets/#{legacy_url_path}")
    .to_return(body: response.to_json, status: 200)
end

#asset_manager_has_an_asset(id, atts) ⇒ Object


6
7
8
9
10
11
# File 'lib/gds_api/test_helpers/asset_manager.rb', line 6

def asset_manager_has_an_asset(id, atts)
  response = atts.merge("_response_info" => { "status" => "ok" })

  stub_request(:get, "#{ASSET_MANAGER_ENDPOINT}/assets/#{id}")
    .to_return(body: response.to_json, status: 200)
end

#asset_manager_receives_an_asset(response_url) ⇒ Object


38
39
40
# File 'lib/gds_api/test_helpers/asset_manager.rb', line 38

def asset_manager_receives_an_asset(response_url)
  stub_request(:post, "#{ASSET_MANAGER_ENDPOINT}/assets").to_return(body: { file_url: response_url }.to_json, status: 200)
end

#asset_manager_upload_failureObject


42
43
44
# File 'lib/gds_api/test_helpers/asset_manager.rb', line 42

def asset_manager_upload_failure
  stub_request(:post, "#{ASSET_MANAGER_ENDPOINT}/assets").to_return(status: 500)
end