gds-api-adapters 8.2.1 → 8.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/gds_api/test_helpers/content_api.rb +50 -25
- data/lib/gds_api/version.rb +1 -1
- metadata +4 -4
@@ -10,8 +10,11 @@ module GdsApi
|
|
10
10
|
# you could redefine/override the constant or stub directly.
|
11
11
|
CONTENT_API_ENDPOINT = Plek.current.find('contentapi')
|
12
12
|
|
13
|
-
#
|
14
|
-
#
|
13
|
+
# Legacy section test helpers
|
14
|
+
#
|
15
|
+
# Use of these should be retired in favour of the other test helpers in this
|
16
|
+
# module which work with any tag type.
|
17
|
+
|
15
18
|
def content_api_has_root_sections(slugs_or_sections)
|
16
19
|
content_api_has_root_tags("section", slugs_or_sections)
|
17
20
|
end
|
@@ -24,6 +27,21 @@ module GdsApi
|
|
24
27
|
content_api_has_child_tags("section", parent_slug_or_hash, subsection_slugs)
|
25
28
|
end
|
26
29
|
|
30
|
+
def content_api_has_artefacts_in_a_section(slug, artefact_slugs=nil)
|
31
|
+
content_api_has_artefacts_with_a_tag("section", slug, artefact_slugs)
|
32
|
+
end
|
33
|
+
|
34
|
+
def artefact_for_slug_in_a_section(slug, section_slug)
|
35
|
+
artefact_for_slug_with_a_tag("section", slug, section_slug)
|
36
|
+
end
|
37
|
+
|
38
|
+
def artefact_for_slug_in_a_subsection(slug, subsection_slug)
|
39
|
+
artefact_for_slug_with_a_child_tag("section", slug, subsection_slug)
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# Takes an array of slugs, or hashes with section details (including a slug).
|
44
|
+
# Will stub out content_api calls for tags of type section to return these sections
|
27
45
|
def content_api_has_root_tags(tag_type, slugs_or_tags)
|
28
46
|
body = plural_response_base.merge(
|
29
47
|
"results" => slugs_or_tags.map { |tag| tag_result(tag, tag_type) }
|
@@ -36,14 +54,14 @@ module GdsApi
|
|
36
54
|
end
|
37
55
|
end
|
38
56
|
|
39
|
-
def content_api_has_tag(tag_type, slug_or_hash,
|
40
|
-
|
41
|
-
body = tag_result(
|
57
|
+
def content_api_has_tag(tag_type, slug_or_hash, parent_tag_id=nil)
|
58
|
+
tag = tag_hash(slug_or_hash, tag_type).merge(parent: parent_tag_id)
|
59
|
+
body = tag_result(tag)
|
42
60
|
|
43
|
-
urls = ["#{CONTENT_API_ENDPOINT}/tags/#{CGI.escape(tag_type)}/#{CGI.escape(
|
61
|
+
urls = ["#{CONTENT_API_ENDPOINT}/tags/#{CGI.escape(tag_type)}/#{CGI.escape(tag[:slug])}.json"]
|
44
62
|
|
45
63
|
if tag_type == "section"
|
46
|
-
urls << "#{CONTENT_API_ENDPOINT}/tags/#{CGI.escape(
|
64
|
+
urls << "#{CONTENT_API_ENDPOINT}/tags/#{CGI.escape(tag[:slug])}.json"
|
47
65
|
end
|
48
66
|
|
49
67
|
urls.each do |url|
|
@@ -60,27 +78,32 @@ module GdsApi
|
|
60
78
|
stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
|
61
79
|
end
|
62
80
|
|
63
|
-
def content_api_has_child_tags(tag_type, parent_slug_or_hash,
|
64
|
-
|
65
|
-
|
66
|
-
tag_hash(
|
81
|
+
def content_api_has_child_tags(tag_type, parent_slug_or_hash, child_tag_ids)
|
82
|
+
parent_tag = tag_hash(parent_slug_or_hash, tag_type)
|
83
|
+
child_tags = child_tag_ids.map { |id|
|
84
|
+
tag_hash(id, tag_type).merge(parent: parent_tag)
|
67
85
|
}
|
68
86
|
body = plural_response_base.merge(
|
69
|
-
"results" =>
|
87
|
+
"results" => child_tags.map { |s| tag_result(s, tag_type) }
|
70
88
|
)
|
71
|
-
url = "#{CONTENT_API_ENDPOINT}/tags.json?type=#{tag_type}&parent_id=#{CGI.escape(
|
89
|
+
url = "#{CONTENT_API_ENDPOINT}/tags.json?type=#{tag_type}&parent_id=#{CGI.escape(parent_tag[:slug])}"
|
72
90
|
stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
|
73
91
|
end
|
74
92
|
|
75
|
-
def
|
93
|
+
def content_api_has_artefacts_with_a_tag(tag_type, slug, artefact_slugs=[])
|
76
94
|
body = plural_response_base.merge(
|
77
95
|
"results" => artefact_slugs.map do |artefact_slug|
|
78
|
-
|
96
|
+
artefact_ slug(artefact_slug)
|
79
97
|
end
|
80
98
|
)
|
81
99
|
sort_orders = ["alphabetical", "curated"]
|
82
100
|
sort_orders.each do |order|
|
83
|
-
|
101
|
+
if tag_type == "section"
|
102
|
+
section_url = "#{CONTENT_API_ENDPOINT}/with_tag.json?sort=#{order}&tag=#{CGI.escape(slug)}"
|
103
|
+
stub_request(:get, section_url).to_return(status: 200, body: body.to_json, headers: {})
|
104
|
+
end
|
105
|
+
|
106
|
+
url = "#{CONTENT_API_ENDPOINT}/with_tag.json?sort=#{order}&#{CGI.escape(tag_type)}=#{CGI.escape(slug)}"
|
84
107
|
stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
|
85
108
|
end
|
86
109
|
end
|
@@ -170,13 +193,13 @@ module GdsApi
|
|
170
193
|
)
|
171
194
|
end
|
172
195
|
|
173
|
-
def
|
196
|
+
def artefact_for_slug_with_a_tag(tag_type, slug, tag_id)
|
174
197
|
artefact = artefact_for_slug(slug)
|
175
|
-
artefact["tags"] << tag_for_slug(
|
198
|
+
artefact["tags"] << tag_for_slug(tag_id, tag_type)
|
176
199
|
artefact
|
177
200
|
end
|
178
201
|
|
179
|
-
def
|
202
|
+
def artefact_for_slug_with_a_child_tag(tag_type, slug, child_tag_id)
|
180
203
|
artefact = artefact_for_slug(slug)
|
181
204
|
|
182
205
|
# for each "part" of the path, we want to reduce across the
|
@@ -185,18 +208,20 @@ module GdsApi
|
|
185
208
|
# Tag{ thing2, parent: Tag{ thing1 } }
|
186
209
|
|
187
210
|
tag_tree = nil
|
188
|
-
|
189
|
-
|
190
|
-
|
211
|
+
child_tag_id.split('/').inject(nil) do |parent_tag, child_tag|
|
212
|
+
child_tag = [parent_tag, child_tag].join('/') if parent_tag
|
213
|
+
next_level_tag = tag_for_slug(child_tag, tag_type)
|
191
214
|
if tag_tree
|
192
215
|
# Because tags are nested within one another, this makes
|
193
216
|
# the current part the top, and the rest we've seen the
|
194
217
|
# ancestors
|
195
|
-
tag_tree =
|
218
|
+
tag_tree = next_level_tag.merge("parent" => tag_tree)
|
196
219
|
else
|
197
|
-
tag_tree =
|
220
|
+
tag_tree = next_level_tag
|
198
221
|
end
|
199
|
-
|
222
|
+
|
223
|
+
# This becomes the parent tag in the next iteration of the block
|
224
|
+
child_tag
|
200
225
|
end
|
201
226
|
artefact["tags"] << tag_tree
|
202
227
|
artefact
|
data/lib/gds_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.2.
|
4
|
+
version: 8.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: plek
|
@@ -364,7 +364,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
364
364
|
version: '0'
|
365
365
|
segments:
|
366
366
|
- 0
|
367
|
-
hash:
|
367
|
+
hash: -3236500390538841432
|
368
368
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
369
369
|
none: false
|
370
370
|
requirements:
|
@@ -373,7 +373,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
373
373
|
version: '0'
|
374
374
|
segments:
|
375
375
|
- 0
|
376
|
-
hash:
|
376
|
+
hash: -3236500390538841432
|
377
377
|
requirements: []
|
378
378
|
rubyforge_project:
|
379
379
|
rubygems_version: 1.8.23
|