Module: GdsApi::TestHelpers::NeedApi

Includes:
CommonResponses
Defined in:
lib/gds_api/test_helpers/need_api.rb

Constant Summary collapse

NEED_API_ENDPOINT =
Plek.current.find('need-api')

Instance Method Summary collapse

Methods included from CommonResponses

#acronymize_slug, #plural_response_base, #response_base, #titleize_slug

Instance Method Details

#need_api_has_needs(needs) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/gds_api/test_helpers/need_api.rb', line 34

def need_api_has_needs(needs)
  url = NEED_API_ENDPOINT + "/needs"

  body = response_base.merge(
    "results" => needs
  )
  stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
end

#need_api_has_needs_for_organisation(organisation, needs) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/gds_api/test_helpers/need_api.rb', line 25

def need_api_has_needs_for_organisation(organisation, needs)
  url = NEED_API_ENDPOINT + "/needs?organisation_id=#{organisation}"

  body = response_base.merge(
    "results" => needs
  )
  stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
end

#need_api_has_organisations(organisations) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gds_api/test_helpers/need_api.rb', line 11

def need_api_has_organisations(organisations)
  url = NEED_API_ENDPOINT + "/organisations"

  body = response_base.merge(
    "organisations" => organisations.map {|id, name|
      {
        "id" => id,
        "name" => name
      }
    }
  )
  stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
end