Module: GdsApi::TestHelpers::NeedApi
Constant Summary
collapse
- NEED_API_ENDPOINT =
Plek.current.find('need-api')
Instance Method Summary
collapse
#acronymize_slug, #plural_response_base, #response_base, #titleize_slug
Instance Method Details
#need_api_has_need(need) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/gds_api/test_helpers/need_api.rb', line 63
def need_api_has_need(need)
need_id = need["id"] || need[:id]
raise ArgumentError, "Test need is missing an ID" unless need_id
url = NEED_API_ENDPOINT + "/needs/#{need_id}"
stub_request(:get, url).to_return(status: 200, body: need.to_json, headers: {})
end
|
#need_api_has_need_ids(needs) ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/gds_api/test_helpers/need_api.rb', line 53
def need_api_has_need_ids(needs)
ids = needs.map {|need| (need["id"] || need[:id]).to_i }.sort.join(',')
url = NEED_API_ENDPOINT + "/needs?ids=#{ids}"
body = response_base.merge(
"results" => needs
)
stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
end
|
#need_api_has_needs(needs) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/gds_api/test_helpers/need_api.rb', line 44
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
26
27
28
29
30
31
32
33
|
# File 'lib/gds_api/test_helpers/need_api.rb', line 26
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_needs_for_search(search_term, needs) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/gds_api/test_helpers/need_api.rb', line 35
def need_api_has_needs_for_search(search_term, needs)
url = NEED_API_ENDPOINT + "/needs?q=#{search_term}"
body = response_base.merge(
"results" => needs
)
stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
end
|
#need_api_has_no_need(need_id) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/gds_api/test_helpers/need_api.rb', line 78
def need_api_has_no_need(need_id)
url = NEED_API_ENDPOINT + "/needs/#{need_id}"
not_found_body = {
"_response_info" => {"status" => "not_found"},
"error" => "No need exists with this ID"
}
stub_request(:get, url).to_return(
status: 404,
body: not_found_body.to_json,
headers: {}
)
end
|
#need_api_has_organisations(organisations) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# 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, attrs|
if attrs.is_a? String
{ "id" => id }.merge("name" => attrs)
else
{ "id" => id }.merge(attrs)
end
}
)
stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
end
|
#need_api_has_raw_response_for_page(response, page = nil) ⇒ Object
71
72
73
74
75
76
|
# File 'lib/gds_api/test_helpers/need_api.rb', line 71
def need_api_has_raw_response_for_page(response, page = nil)
url = NEED_API_ENDPOINT + "/needs"
url << "?page=#{page}" unless page.nil?
stub_request(:get, url).to_return(status: 200, body: response, headers: {})
end
|
#stub_create_note(note_details = nil) ⇒ Object
91
92
93
94
95
|
# File 'lib/gds_api/test_helpers/need_api.rb', line 91
def stub_create_note(note_details = nil)
post_stub = stub_request(:post, NEED_API_ENDPOINT + "/notes")
post_stub.with(:body => note_details.to_json) unless note_details.nil?
post_stub.to_return(:status => 201)
end
|