gds-api-adapters 38.1.0 → 39.0.0
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.
- checksums.yaml +4 -4
- data/lib/gds_api/test_helpers/need_api.rb +0 -15
- data/lib/gds_api/test_helpers/organisations.rb +5 -0
- data/lib/gds_api/version.rb +1 -1
- metadata +3 -103
- data/test/asset_manager_test.rb +0 -94
- data/test/business_support_api_test.rb +0 -45
- data/test/content_api_test.rb +0 -712
- data/test/content_store_test.rb +0 -55
- data/test/email_alert_api_test.rb +0 -189
- data/test/fixtures/finder_api/cma-case-schema.json +0 -103
- data/test/fixtures/hello.txt +0 -1
- data/test/fixtures/new_policies_for_dwp.json +0 -298
- data/test/fixtures/no_services_and_info_data_found_fixture.json +0 -14
- data/test/fixtures/old_policies_for_dwp.json +0 -413
- data/test/fixtures/services_and_info_fixture.json +0 -73
- data/test/fixtures/sub_sector_organisations.json +0 -57
- data/test/fixtures/world_organisations_australia.json +0 -490
- data/test/gds_api_base_test.rb +0 -110
- data/test/gov_uk_delivery_test.rb +0 -67
- data/test/govuk_headers_test.rb +0 -30
- data/test/helpers_test.rb +0 -23
- data/test/imminence_api_test.rb +0 -196
- data/test/json_client_test.rb +0 -879
- data/test/licence_application_api_test.rb +0 -196
- data/test/list_response_test.rb +0 -189
- data/test/local_links_manager_api_test.rb +0 -236
- data/test/mapit_test.rb +0 -117
- data/test/maslow_test.rb +0 -12
- data/test/middleware/govuk_header_sniffer_test.rb +0 -18
- data/test/need_api_test.rb +0 -345
- data/test/organisations_api_test.rb +0 -58
- data/test/panopticon_registerer_test.rb +0 -118
- data/test/panopticon_test.rb +0 -190
- data/test/pp_data_in_test.rb +0 -52
- data/test/pp_data_out_test.rb +0 -24
- data/test/publishing_api/special_route_publisher_test.rb +0 -104
- data/test/publishing_api_test.rb +0 -186
- data/test/publishing_api_v2/get_expanded_links_test.rb +0 -85
- data/test/publishing_api_v2/get_links_test.rb +0 -89
- data/test/publishing_api_v2/lookup_test.rb +0 -70
- data/test/publishing_api_v2_test.rb +0 -1649
- data/test/response_test.rb +0 -245
- data/test/router_test.rb +0 -456
- data/test/rummager_helpers_test.rb +0 -20
- data/test/rummager_test.rb +0 -150
- data/test/support_api_test.rb +0 -189
- data/test/support_test.rb +0 -95
- data/test/test_helper.rb +0 -55
- data/test/test_helpers/email_alert_api_test.rb +0 -24
- data/test/test_helpers/pact_helper.rb +0 -13
- data/test/test_helpers/panopticon_test.rb +0 -44
- data/test/test_helpers/publishing_api_test.rb +0 -129
- data/test/test_helpers/publishing_api_v2_test.rb +0 -170
- data/test/worldwide_api_test.rb +0 -82
data/test/publishing_api_test.rb
DELETED
@@ -1,186 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'gds_api/publishing_api'
|
3
|
-
require 'gds_api/test_helpers/publishing_api'
|
4
|
-
|
5
|
-
describe GdsApi::PublishingApi do
|
6
|
-
include GdsApi::TestHelpers::PublishingApi
|
7
|
-
include PactTest
|
8
|
-
|
9
|
-
before do
|
10
|
-
@base_api_url = Plek.current.find("publishing-api")
|
11
|
-
@api_client = GdsApi::PublishingApi.new(publishing_api_host)
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#put_intent" do
|
15
|
-
it "responds with 200 OK if publish intent is valid" do
|
16
|
-
base_path = "/test-intent"
|
17
|
-
publish_intent = intent_for_publishing_api(base_path)
|
18
|
-
|
19
|
-
publishing_api
|
20
|
-
.given("no content exists")
|
21
|
-
.upon_receiving("a request to create a publish intent")
|
22
|
-
.with(
|
23
|
-
method: :put,
|
24
|
-
path: "/publish-intent#{base_path}",
|
25
|
-
body: publish_intent,
|
26
|
-
headers: {
|
27
|
-
"Content-Type" => "application/json"
|
28
|
-
},
|
29
|
-
)
|
30
|
-
.will_respond_with(
|
31
|
-
status: 200,
|
32
|
-
body: {},
|
33
|
-
headers: {
|
34
|
-
"Content-Type" => "application/json; charset=utf-8"
|
35
|
-
},
|
36
|
-
)
|
37
|
-
|
38
|
-
response = @api_client.put_intent(base_path, publish_intent)
|
39
|
-
assert_equal 200, response.code
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "#delete_intent" do
|
44
|
-
it "returns 200 OK if intent existed and was deleted" do
|
45
|
-
base_path = "/test-intent"
|
46
|
-
|
47
|
-
publishing_api
|
48
|
-
.given("a publish intent exists at /test-intent")
|
49
|
-
.upon_receiving("a request to delete a publish intent")
|
50
|
-
.with(
|
51
|
-
method: :delete,
|
52
|
-
path: "/publish-intent#{base_path}",
|
53
|
-
)
|
54
|
-
.will_respond_with(
|
55
|
-
status: 200,
|
56
|
-
body: {},
|
57
|
-
headers: {
|
58
|
-
"Content-Type" => "application/json; charset=utf-8"
|
59
|
-
}
|
60
|
-
)
|
61
|
-
|
62
|
-
response = @api_client.destroy_intent(base_path)
|
63
|
-
assert_equal 200, response.code
|
64
|
-
end
|
65
|
-
|
66
|
-
it "returns 404 Not found if the intent does not exist" do
|
67
|
-
base_path = "/test-intent"
|
68
|
-
|
69
|
-
publishing_api
|
70
|
-
.given("no content exists")
|
71
|
-
.upon_receiving("a request to delete a publish intent")
|
72
|
-
.with(
|
73
|
-
method: :delete,
|
74
|
-
path: "/publish-intent#{base_path}",
|
75
|
-
)
|
76
|
-
.will_respond_with(
|
77
|
-
status: 404,
|
78
|
-
body: {},
|
79
|
-
headers: {
|
80
|
-
"Content-Type" => "application/json; charset=utf-8"
|
81
|
-
}
|
82
|
-
)
|
83
|
-
|
84
|
-
response = @api_client.destroy_intent(base_path)
|
85
|
-
assert_equal 404, response.code
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "#put_path" do
|
90
|
-
it "returns 200 if the path was successfully reserved" do
|
91
|
-
base_path = "/test-intent"
|
92
|
-
payload = {
|
93
|
-
publishing_app: "publisher"
|
94
|
-
}
|
95
|
-
|
96
|
-
publishing_api
|
97
|
-
.given("no content exists")
|
98
|
-
.upon_receiving("a request to put a path")
|
99
|
-
.with(
|
100
|
-
method: :put,
|
101
|
-
path: "/paths#{base_path}",
|
102
|
-
body: payload,
|
103
|
-
headers: {
|
104
|
-
"Content-Type" => "application/json"
|
105
|
-
},
|
106
|
-
)
|
107
|
-
.will_respond_with(
|
108
|
-
status: 200,
|
109
|
-
body: {},
|
110
|
-
headers: {
|
111
|
-
"Content-Type" => "application/json; charset=utf-8"
|
112
|
-
}
|
113
|
-
)
|
114
|
-
|
115
|
-
response = @api_client.put_path(base_path, payload)
|
116
|
-
assert_equal 200, response.code
|
117
|
-
end
|
118
|
-
|
119
|
-
it "returns 422 if the request is invalid" do
|
120
|
-
base_path = "/test-item"
|
121
|
-
payload = {
|
122
|
-
publishing_app: "whitehall"
|
123
|
-
}
|
124
|
-
|
125
|
-
publishing_api
|
126
|
-
.given("/test-item has been reserved by the Publisher application")
|
127
|
-
.upon_receiving("a request to change publishing app")
|
128
|
-
.with(
|
129
|
-
method: :put,
|
130
|
-
path: "/paths#{base_path}",
|
131
|
-
body: payload,
|
132
|
-
headers: {
|
133
|
-
"Content-Type" => "application/json"
|
134
|
-
},
|
135
|
-
|
136
|
-
)
|
137
|
-
.will_respond_with(
|
138
|
-
status: 422,
|
139
|
-
body: {
|
140
|
-
"error" => {
|
141
|
-
"code" => 422,
|
142
|
-
"message" => Pact.term(generate: "Unprocessable", matcher: /\S+/),
|
143
|
-
"fields" => {
|
144
|
-
"base_path" => Pact.each_like("has been reserved", min: 1),
|
145
|
-
},
|
146
|
-
},
|
147
|
-
},
|
148
|
-
)
|
149
|
-
|
150
|
-
error = assert_raises GdsApi::HTTPClientError do
|
151
|
-
@api_client.put_path(base_path, payload)
|
152
|
-
end
|
153
|
-
assert_equal "Unprocessable", error.error_details["error"]["message"]
|
154
|
-
end
|
155
|
-
|
156
|
-
it "returns 200 if an existing path was overridden" do
|
157
|
-
base_path = "/test-item"
|
158
|
-
payload = {
|
159
|
-
publishing_app: "whitehall",
|
160
|
-
override_existing: "true",
|
161
|
-
}
|
162
|
-
|
163
|
-
publishing_api
|
164
|
-
.given("/test-item has been reserved by the Publisher application")
|
165
|
-
.upon_receiving("a request to change publishing app with override_existing set")
|
166
|
-
.with(
|
167
|
-
method: :put,
|
168
|
-
path: "/paths#{base_path}",
|
169
|
-
body: payload,
|
170
|
-
headers: {
|
171
|
-
"Content-Type" => "application/json"
|
172
|
-
},
|
173
|
-
)
|
174
|
-
.will_respond_with(
|
175
|
-
status: 200,
|
176
|
-
body: {},
|
177
|
-
headers: {
|
178
|
-
"Content-Type" => "application/json; charset=utf-8"
|
179
|
-
}
|
180
|
-
)
|
181
|
-
|
182
|
-
response = @api_client.put_path(base_path, payload)
|
183
|
-
assert_equal 200, response.code
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'gds_api/publishing_api_v2'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
describe GdsApi::PublishingApiV2 do
|
6
|
-
include PactTest
|
7
|
-
|
8
|
-
before do
|
9
|
-
@api_client = GdsApi::PublishingApiV2.new(publishing_api_host)
|
10
|
-
@content_id = "bed722e6-db68-43e5-9079-063f623335a7"
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#get_expanded_links" do
|
14
|
-
it "responds with the links when there's a links entry with links" do
|
15
|
-
publishing_api
|
16
|
-
.given("organisation links exist for content_id #{@content_id}")
|
17
|
-
.upon_receiving("a get-expanded-links request")
|
18
|
-
.with(
|
19
|
-
method: :get,
|
20
|
-
path: "/v2/expanded-links/#{@content_id}",
|
21
|
-
)
|
22
|
-
.will_respond_with(
|
23
|
-
status: 200,
|
24
|
-
body: {
|
25
|
-
expanded_links: {
|
26
|
-
organisations: [
|
27
|
-
{ content_id: "20583132-1619-4c68-af24-77583172c070" }
|
28
|
-
]
|
29
|
-
}
|
30
|
-
}
|
31
|
-
)
|
32
|
-
|
33
|
-
response = @api_client.get_expanded_links(@content_id)
|
34
|
-
|
35
|
-
expected_body = {
|
36
|
-
"expanded_links" => {
|
37
|
-
"organisations" => [
|
38
|
-
{ "content_id" => "20583132-1619-4c68-af24-77583172c070" }
|
39
|
-
]
|
40
|
-
}
|
41
|
-
}
|
42
|
-
assert_equal 200, response.code
|
43
|
-
assert_equal expected_body, response.to_h
|
44
|
-
end
|
45
|
-
|
46
|
-
it "responds with the empty thing set if there's an empty link set" do
|
47
|
-
publishing_api
|
48
|
-
.given("empty links exist for content_id #{@content_id}")
|
49
|
-
.upon_receiving("a get-expanded-links request")
|
50
|
-
.with(
|
51
|
-
method: :get,
|
52
|
-
path: "/v2/expanded-links/#{@content_id}",
|
53
|
-
)
|
54
|
-
.will_respond_with(
|
55
|
-
status: 200,
|
56
|
-
body: {
|
57
|
-
expanded_links: {
|
58
|
-
}
|
59
|
-
}
|
60
|
-
)
|
61
|
-
|
62
|
-
response = @api_client.get_expanded_links(@content_id)
|
63
|
-
|
64
|
-
assert_equal 200, response.code
|
65
|
-
assert_equal({}, response.to_h['expanded_links'])
|
66
|
-
end
|
67
|
-
|
68
|
-
it "responds with 404 if there's no link set entry" do
|
69
|
-
publishing_api
|
70
|
-
.given("no links exist for content_id #{@content_id}")
|
71
|
-
.upon_receiving("a get-expanded-links request")
|
72
|
-
.with(
|
73
|
-
method: :get,
|
74
|
-
path: "/v2/expanded-links/#{@content_id}",
|
75
|
-
)
|
76
|
-
.will_respond_with(
|
77
|
-
status: 404
|
78
|
-
)
|
79
|
-
|
80
|
-
assert_raises(GdsApi::HTTPNotFound) do
|
81
|
-
@api_client.get_expanded_links(@content_id)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'gds_api/publishing_api_v2'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
describe GdsApi::PublishingApiV2 do
|
6
|
-
include PactTest
|
7
|
-
|
8
|
-
before do
|
9
|
-
@api_client = GdsApi::PublishingApiV2.new(publishing_api_host)
|
10
|
-
@content_id = "bed722e6-db68-43e5-9079-063f623335a7"
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#get_links" do
|
14
|
-
describe "when there's a links entry with links" do
|
15
|
-
before do
|
16
|
-
publishing_api
|
17
|
-
.given("organisation links exist for content_id #{@content_id}")
|
18
|
-
.upon_receiving("a get-links request")
|
19
|
-
.with(
|
20
|
-
method: :get,
|
21
|
-
path: "/v2/links/#{@content_id}",
|
22
|
-
)
|
23
|
-
.will_respond_with(
|
24
|
-
status: 200,
|
25
|
-
body: {
|
26
|
-
links: {
|
27
|
-
organisations: ["20583132-1619-4c68-af24-77583172c070"]
|
28
|
-
}
|
29
|
-
}
|
30
|
-
)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "responds with the links" do
|
34
|
-
response = @api_client.get_links(@content_id)
|
35
|
-
assert_equal 200, response.code
|
36
|
-
assert_equal(
|
37
|
-
["20583132-1619-4c68-af24-77583172c070"],
|
38
|
-
response['links']['organisations']
|
39
|
-
)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "when there's an empty links entry" do
|
44
|
-
before do
|
45
|
-
publishing_api
|
46
|
-
.given("empty links exist for content_id #{@content_id}")
|
47
|
-
.upon_receiving("a get-links request")
|
48
|
-
.with(
|
49
|
-
method: :get,
|
50
|
-
path: "/v2/links/#{@content_id}",
|
51
|
-
)
|
52
|
-
.will_respond_with(
|
53
|
-
status: 200,
|
54
|
-
body: {
|
55
|
-
links: {
|
56
|
-
}
|
57
|
-
}
|
58
|
-
)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "responds with the empty link set" do
|
62
|
-
response = @api_client.get_links(@content_id)
|
63
|
-
assert_equal 200, response.code
|
64
|
-
assert_equal({}, response['links'])
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "when there's no links entry" do
|
69
|
-
before do
|
70
|
-
publishing_api
|
71
|
-
.given("no links exist for content_id #{@content_id}")
|
72
|
-
.upon_receiving("a get-links request")
|
73
|
-
.with(
|
74
|
-
method: :get,
|
75
|
-
path: "/v2/links/#{@content_id}",
|
76
|
-
)
|
77
|
-
.will_respond_with(
|
78
|
-
status: 404
|
79
|
-
)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "responds with 404" do
|
83
|
-
assert_raises(GdsApi::HTTPNotFound) do
|
84
|
-
@api_client.get_links(@content_id)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'gds_api/publishing_api_v2'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
describe GdsApi::PublishingApiV2 do
|
6
|
-
include PactTest
|
7
|
-
|
8
|
-
before do
|
9
|
-
@api_client = GdsApi::PublishingApiV2.new(publishing_api_host)
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "#lookup_content_id" do
|
13
|
-
it "returns the content_id for a base_path" do
|
14
|
-
publishing_api
|
15
|
-
.given("there are live content items with base_paths /foo and /bar")
|
16
|
-
.upon_receiving("a /lookup-by-base-path-request")
|
17
|
-
.with(
|
18
|
-
method: :post,
|
19
|
-
path: "/lookup-by-base-path",
|
20
|
-
body: {
|
21
|
-
base_paths: ["/foo"]
|
22
|
-
},
|
23
|
-
headers: {
|
24
|
-
"Content-Type" => "application/json",
|
25
|
-
},
|
26
|
-
)
|
27
|
-
.will_respond_with(
|
28
|
-
status: 200,
|
29
|
-
body: {
|
30
|
-
"/foo" => "08f86d00-e95f-492f-af1d-470c5ba4752e"
|
31
|
-
}
|
32
|
-
)
|
33
|
-
|
34
|
-
content_id = @api_client.lookup_content_id(base_path: "/foo")
|
35
|
-
|
36
|
-
assert_equal "08f86d00-e95f-492f-af1d-470c5ba4752e", content_id
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "#lookup_content_ids" do
|
41
|
-
it "returns the content_id for a base_path" do
|
42
|
-
reponse_hash = {
|
43
|
-
"/foo" => "08f86d00-e95f-492f-af1d-470c5ba4752e",
|
44
|
-
"/bar" => "ca6c58a6-fb9d-479d-b3e6-74908781cb18",
|
45
|
-
}
|
46
|
-
|
47
|
-
publishing_api
|
48
|
-
.given("there are live content items with base_paths /foo and /bar")
|
49
|
-
.upon_receiving("a request for multiple base_paths")
|
50
|
-
.with(
|
51
|
-
method: :post,
|
52
|
-
path: "/lookup-by-base-path",
|
53
|
-
body: {
|
54
|
-
base_paths: ["/foo", "/bar"]
|
55
|
-
},
|
56
|
-
headers: {
|
57
|
-
"Content-Type" => "application/json",
|
58
|
-
},
|
59
|
-
)
|
60
|
-
.will_respond_with(
|
61
|
-
status: 200,
|
62
|
-
body: reponse_hash,
|
63
|
-
)
|
64
|
-
|
65
|
-
content_id = @api_client.lookup_content_ids(base_paths: ["/foo", "/bar"])
|
66
|
-
|
67
|
-
assert_equal(reponse_hash, content_id)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,1649 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'gds_api/publishing_api_v2'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
describe GdsApi::PublishingApiV2 do
|
6
|
-
include PactTest
|
7
|
-
|
8
|
-
def content_item_for_content_id(content_id, attrs = {})
|
9
|
-
{
|
10
|
-
"base_path" => "/robots.txt",
|
11
|
-
"content_id" => content_id,
|
12
|
-
"title" => "Instructions for crawler robots",
|
13
|
-
"description" => "robots.txt provides rules for which parts of GOV.UK are permitted to be crawled by different bots.",
|
14
|
-
"schema_name" => "special_route",
|
15
|
-
"document_type" => "special_route",
|
16
|
-
"public_updated_at" => "2015-07-30T13:58:11.000Z",
|
17
|
-
"publishing_app" => "static",
|
18
|
-
"rendering_app" => "static",
|
19
|
-
"routes" => [
|
20
|
-
{
|
21
|
-
"path" => attrs["base_path"] || "/robots.txt",
|
22
|
-
"type" => "exact"
|
23
|
-
}
|
24
|
-
],
|
25
|
-
"update_type" => "major"
|
26
|
-
}.merge(attrs)
|
27
|
-
end
|
28
|
-
|
29
|
-
before do
|
30
|
-
@bearer_token = "example-bearer-token"
|
31
|
-
@base_api_url = Plek.current.find("publishing-api")
|
32
|
-
@api_client = GdsApi::PublishingApiV2.new(
|
33
|
-
publishing_api_host,
|
34
|
-
bearer_token: @bearer_token,
|
35
|
-
)
|
36
|
-
|
37
|
-
@content_id = "bed722e6-db68-43e5-9079-063f623335a7"
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "#put_content" do
|
41
|
-
describe "if the entry is valid" do
|
42
|
-
before do
|
43
|
-
@content_item = content_item_for_content_id(@content_id)
|
44
|
-
|
45
|
-
publishing_api
|
46
|
-
.given("no content exists")
|
47
|
-
.upon_receiving("a request to create a content item without links")
|
48
|
-
.with(
|
49
|
-
method: :put,
|
50
|
-
path: "/v2/content/#{@content_id}",
|
51
|
-
body: @content_item,
|
52
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
53
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
54
|
-
),
|
55
|
-
)
|
56
|
-
.will_respond_with(
|
57
|
-
status: 200,
|
58
|
-
)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "responds with 200 OK" do
|
62
|
-
response = @api_client.put_content(@content_id, @content_item)
|
63
|
-
assert_equal 200, response.code
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "if the path is reserved by a different app" do
|
68
|
-
before do
|
69
|
-
@content_item = content_item_for_content_id(@content_id, "base_path" => "/test-item", "publishing_app" => "whitehall")
|
70
|
-
|
71
|
-
publishing_api
|
72
|
-
.given("/test-item has been reserved by the Publisher application")
|
73
|
-
.upon_receiving("a request from the Whitehall application to create a content item at /test-item")
|
74
|
-
.with(
|
75
|
-
method: :put,
|
76
|
-
path: "/v2/content/#{@content_id}",
|
77
|
-
body: @content_item,
|
78
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
79
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
80
|
-
),
|
81
|
-
)
|
82
|
-
.will_respond_with(
|
83
|
-
status: 422,
|
84
|
-
body: {
|
85
|
-
"error" => {
|
86
|
-
"code" => 422,
|
87
|
-
"message" => Pact.term(generate: "Conflict", matcher: /\S+/),
|
88
|
-
"fields" => {
|
89
|
-
"base_path" => Pact.each_like("is already in use by the 'publisher' app", min: 1),
|
90
|
-
},
|
91
|
-
},
|
92
|
-
},
|
93
|
-
headers: {
|
94
|
-
"Content-Type" => "application/json; charset=utf-8"
|
95
|
-
}
|
96
|
-
)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "responds with 422 Unprocessable Entity" do
|
100
|
-
error = assert_raises GdsApi::HTTPClientError do
|
101
|
-
@api_client.put_content(@content_id, @content_item)
|
102
|
-
end
|
103
|
-
assert_equal "Conflict", error.error_details["error"]["message"]
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe "with an invalid item" do
|
108
|
-
before do
|
109
|
-
@content_item = content_item_for_content_id(@content_id, "base_path" => "not a url path")
|
110
|
-
|
111
|
-
publishing_api
|
112
|
-
.given("no content exists")
|
113
|
-
.upon_receiving("a request to create an invalid content-item")
|
114
|
-
.with(
|
115
|
-
method: :put,
|
116
|
-
path: "/v2/content/#{@content_id}",
|
117
|
-
body: @content_item,
|
118
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
119
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
120
|
-
),
|
121
|
-
)
|
122
|
-
.will_respond_with(
|
123
|
-
status: 422,
|
124
|
-
body: [
|
125
|
-
{
|
126
|
-
fragment: "#/base_path",
|
127
|
-
failed_attribute: "Pattern"
|
128
|
-
}
|
129
|
-
],
|
130
|
-
headers: {
|
131
|
-
"Content-Type" => "application/json; charset=utf-8"
|
132
|
-
}
|
133
|
-
)
|
134
|
-
end
|
135
|
-
|
136
|
-
it "responds with 422 Unprocessable Entity" do
|
137
|
-
assert_raises GdsApi::HTTPClientError do
|
138
|
-
@api_client.put_content(@content_id, @content_item)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe "optimistic locking" do
|
144
|
-
describe "if the content item has not changed since it was requested" do
|
145
|
-
before do
|
146
|
-
@content_item = content_item_for_content_id(@content_id,
|
147
|
-
"document_type" => "manual",
|
148
|
-
"schema_name" => "manual",
|
149
|
-
"locale" => "en",
|
150
|
-
"details" => { "body" => [] },
|
151
|
-
"previous_version" => "3"
|
152
|
-
)
|
153
|
-
|
154
|
-
publishing_api
|
155
|
-
.given("the content item #{@content_id} is at version 3")
|
156
|
-
.upon_receiving("a request to update the content item at version 3")
|
157
|
-
.with(
|
158
|
-
method: :put,
|
159
|
-
path: "/v2/content/#{@content_id}",
|
160
|
-
body: @content_item,
|
161
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
162
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
163
|
-
),
|
164
|
-
)
|
165
|
-
.will_respond_with(
|
166
|
-
status: 200,
|
167
|
-
)
|
168
|
-
end
|
169
|
-
|
170
|
-
it "responds with 200 OK" do
|
171
|
-
response = @api_client.put_content(@content_id, @content_item)
|
172
|
-
assert_equal 200, response.code
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe "if the content item has changed in the meantime" do
|
177
|
-
before do
|
178
|
-
@content_item = content_item_for_content_id(@content_id,
|
179
|
-
"document_type" => "manual",
|
180
|
-
"schema_name" => "manual",
|
181
|
-
"locale" => "en",
|
182
|
-
"details" => { "body" => [] },
|
183
|
-
"previous_version" => "2"
|
184
|
-
)
|
185
|
-
|
186
|
-
publishing_api
|
187
|
-
.given("the content item #{@content_id} is at version 3")
|
188
|
-
.upon_receiving("a request to update the content item at version 2")
|
189
|
-
.with(
|
190
|
-
method: :put,
|
191
|
-
path: "/v2/content/#{@content_id}",
|
192
|
-
body: @content_item,
|
193
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
194
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
195
|
-
),
|
196
|
-
)
|
197
|
-
.will_respond_with(
|
198
|
-
status: 409,
|
199
|
-
body: {
|
200
|
-
"error" => {
|
201
|
-
"code" => 409,
|
202
|
-
"message" => Pact.term(generate: "Conflict", matcher: /\S+/),
|
203
|
-
"fields" => {
|
204
|
-
"previous_version" => Pact.each_like("does not match", min: 1),
|
205
|
-
},
|
206
|
-
},
|
207
|
-
},
|
208
|
-
headers: {
|
209
|
-
"Content-Type" => "application/json; charset=utf-8"
|
210
|
-
}
|
211
|
-
)
|
212
|
-
end
|
213
|
-
|
214
|
-
it "responds with 409 Conflict" do
|
215
|
-
error = assert_raises GdsApi::HTTPClientError do
|
216
|
-
@api_client.put_content(@content_id, @content_item)
|
217
|
-
end
|
218
|
-
assert_equal 409, error.code
|
219
|
-
assert_equal "Conflict", error.error_details["error"]["message"]
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
describe "#get_content" do
|
226
|
-
describe "when the content item exists" do
|
227
|
-
before do
|
228
|
-
@content_item = content_item_for_content_id(@content_id)
|
229
|
-
|
230
|
-
publishing_api
|
231
|
-
.given("a content item exists with content_id: #{@content_id}")
|
232
|
-
.upon_receiving("a request to return the content item")
|
233
|
-
.with(
|
234
|
-
method: :get,
|
235
|
-
path: "/v2/content/#{@content_id}",
|
236
|
-
headers: GdsApi::JsonClient.default_request_headers.merge(
|
237
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
238
|
-
),
|
239
|
-
)
|
240
|
-
.will_respond_with(
|
241
|
-
status: 200,
|
242
|
-
body: {
|
243
|
-
"content_id" => @content_id,
|
244
|
-
"document_type" => Pact.like("special_route"),
|
245
|
-
"schema_name" => Pact.like("special_route"),
|
246
|
-
"publishing_app" => Pact.like("publisher"),
|
247
|
-
"rendering_app" => Pact.like("frontend"),
|
248
|
-
"locale" => Pact.like("en"),
|
249
|
-
"routes" => Pact.like([{}]),
|
250
|
-
"public_updated_at" => Pact.like("2015-07-30T13:58:11.000Z"),
|
251
|
-
"details" => Pact.like({})
|
252
|
-
},
|
253
|
-
headers: {
|
254
|
-
"Content-Type" => "application/json; charset=utf-8",
|
255
|
-
},
|
256
|
-
)
|
257
|
-
end
|
258
|
-
|
259
|
-
it "responds with 200 and the content item" do
|
260
|
-
response = @api_client.get_content(@content_id)
|
261
|
-
assert_equal 200, response.code
|
262
|
-
assert_equal @content_item["document_type"], response["document_type"]
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
describe "when a content item exists in multiple locales" do
|
267
|
-
before do
|
268
|
-
@content_item = content_item_for_content_id(@content_id)
|
269
|
-
|
270
|
-
publishing_api
|
271
|
-
.given("a content item exists in multiple locales with content_id: #{@content_id}")
|
272
|
-
.upon_receiving("a request to return the content item")
|
273
|
-
.with(
|
274
|
-
method: :get,
|
275
|
-
path: "/v2/content/#{@content_id}",
|
276
|
-
query: "locale=fr",
|
277
|
-
headers: GdsApi::JsonClient.default_request_headers.merge(
|
278
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
279
|
-
),
|
280
|
-
)
|
281
|
-
.will_respond_with(
|
282
|
-
status: 200,
|
283
|
-
body: {
|
284
|
-
"content_id" => @content_id,
|
285
|
-
"document_type" => Pact.like("special_route"),
|
286
|
-
"schema_name" => Pact.like("special_route"),
|
287
|
-
"publishing_app" => Pact.like("publisher"),
|
288
|
-
"rendering_app" => Pact.like("frontend"),
|
289
|
-
"locale" => "fr",
|
290
|
-
"routes" => Pact.like([{}]),
|
291
|
-
"public_updated_at" => Pact.like("2015-07-30T13:58:11.000Z"),
|
292
|
-
"details" => Pact.like({})
|
293
|
-
},
|
294
|
-
headers: {
|
295
|
-
"Content-Type" => "application/json; charset=utf-8",
|
296
|
-
},
|
297
|
-
)
|
298
|
-
end
|
299
|
-
|
300
|
-
it "responds with 200 and the content item" do
|
301
|
-
response = @api_client.get_content(@content_id, locale: "fr")
|
302
|
-
assert_equal 200, response.code
|
303
|
-
assert_equal response["locale"], "fr"
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
describe "when a content item exists in with a superseded version" do
|
308
|
-
describe "when requesting the superseded version" do
|
309
|
-
before do
|
310
|
-
@content_item = content_item_for_content_id(@content_id)
|
311
|
-
|
312
|
-
publishing_api
|
313
|
-
.given("a content item exists in with a superseded version with content_id: #{@content_id}")
|
314
|
-
.upon_receiving("a request to return the superseded content item")
|
315
|
-
.with(
|
316
|
-
method: :get,
|
317
|
-
path: "/v2/content/#{@content_id}",
|
318
|
-
query: "version=1",
|
319
|
-
headers: GdsApi::JsonClient.default_request_headers.merge(
|
320
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
321
|
-
),
|
322
|
-
)
|
323
|
-
.will_respond_with(
|
324
|
-
status: 200,
|
325
|
-
body: {
|
326
|
-
"content_id" => @content_id,
|
327
|
-
"document_type" => Pact.like("special_route"),
|
328
|
-
"schema_name" => Pact.like("special_route"),
|
329
|
-
"publishing_app" => Pact.like("publisher"),
|
330
|
-
"rendering_app" => Pact.like("frontend"),
|
331
|
-
"locale" => Pact.like("en"),
|
332
|
-
"routes" => Pact.like([{}]),
|
333
|
-
"public_updated_at" => Pact.like("2015-07-30T13:58:11.000Z"),
|
334
|
-
"details" => Pact.like({}),
|
335
|
-
"publication_state" => "superseded"
|
336
|
-
},
|
337
|
-
headers: {
|
338
|
-
"Content-Type" => "application/json; charset=utf-8",
|
339
|
-
},
|
340
|
-
)
|
341
|
-
end
|
342
|
-
|
343
|
-
it "responds with 200 and the superseded content item" do
|
344
|
-
response = @api_client.get_content(@content_id, version: 1)
|
345
|
-
assert_equal 200, response.code
|
346
|
-
assert_equal response["publication_state"], "superseded"
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
describe "when a content item cannot be published because of a path conflict" do
|
351
|
-
before do
|
352
|
-
@content_item = content_item_for_content_id(@content_id)
|
353
|
-
|
354
|
-
publishing_api
|
355
|
-
.given("a draft content item exists with content_id #{@content_id} with a blocking live item at the same path")
|
356
|
-
.upon_receiving("a request to return the draft content item")
|
357
|
-
.with(
|
358
|
-
method: :get,
|
359
|
-
path: "/v2/content/#{@content_id}",
|
360
|
-
headers: GdsApi::JsonClient.default_request_headers.merge(
|
361
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
362
|
-
),
|
363
|
-
)
|
364
|
-
.will_respond_with(
|
365
|
-
status: 200,
|
366
|
-
body: {
|
367
|
-
"warnings" => Pact.like("content_item_blocking_publish" => "message"),
|
368
|
-
"content_id" => @content_id,
|
369
|
-
"document_type" => Pact.like("special_route"),
|
370
|
-
"schema_name" => Pact.like("special_route"),
|
371
|
-
"publishing_app" => Pact.like("publisher"),
|
372
|
-
"rendering_app" => Pact.like("frontend"),
|
373
|
-
"locale" => Pact.like("en"),
|
374
|
-
"routes" => Pact.like([{}]),
|
375
|
-
"public_updated_at" => Pact.like("2015-07-30T13:58:11.000Z"),
|
376
|
-
"details" => Pact.like({}),
|
377
|
-
"publication_state" => "draft"
|
378
|
-
},
|
379
|
-
headers: {
|
380
|
-
"Content-Type" => "application/json; charset=utf-8",
|
381
|
-
},
|
382
|
-
)
|
383
|
-
end
|
384
|
-
|
385
|
-
it "responds with 200 and the draft content item containing a warning" do
|
386
|
-
response = @api_client.get_content(@content_id, version: 2)
|
387
|
-
assert_equal 200, response.code
|
388
|
-
assert_equal hash_including("content_item_blocking_publish"), response["warnings"]
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
describe "when requesting the published version" do
|
393
|
-
before do
|
394
|
-
@content_item = content_item_for_content_id(@content_id)
|
395
|
-
|
396
|
-
publishing_api
|
397
|
-
.given("a content item exists in with a superseded version with content_id: #{@content_id}")
|
398
|
-
.upon_receiving("a request to return the published content item")
|
399
|
-
.with(
|
400
|
-
method: :get,
|
401
|
-
path: "/v2/content/#{@content_id}",
|
402
|
-
query: "version=2",
|
403
|
-
headers: GdsApi::JsonClient.default_request_headers.merge(
|
404
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
405
|
-
),
|
406
|
-
)
|
407
|
-
.will_respond_with(
|
408
|
-
status: 200,
|
409
|
-
body: {
|
410
|
-
"content_id" => @content_id,
|
411
|
-
"document_type" => Pact.like("special_route"),
|
412
|
-
"schema_name" => Pact.like("special_route"),
|
413
|
-
"publishing_app" => Pact.like("publisher"),
|
414
|
-
"rendering_app" => Pact.like("frontend"),
|
415
|
-
"locale" => Pact.like("en"),
|
416
|
-
"routes" => Pact.like([{}]),
|
417
|
-
"public_updated_at" => Pact.like("2015-07-30T13:58:11.000Z"),
|
418
|
-
"details" => Pact.like({}),
|
419
|
-
"publication_state" => "published"
|
420
|
-
},
|
421
|
-
headers: {
|
422
|
-
"Content-Type" => "application/json; charset=utf-8",
|
423
|
-
},
|
424
|
-
)
|
425
|
-
end
|
426
|
-
|
427
|
-
it "responds with 200 and the published content item" do
|
428
|
-
response = @api_client.get_content(@content_id, version: 2)
|
429
|
-
assert_equal 200, response.code
|
430
|
-
assert_equal response["publication_state"], "published"
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
|
-
describe "when requesting no specific version" do
|
435
|
-
before do
|
436
|
-
@content_item = content_item_for_content_id(@content_id)
|
437
|
-
|
438
|
-
publishing_api
|
439
|
-
.given("a content item exists in with a superseded version with content_id: #{@content_id}")
|
440
|
-
.upon_receiving("a request to return the content item")
|
441
|
-
.with(
|
442
|
-
method: :get,
|
443
|
-
path: "/v2/content/#{@content_id}",
|
444
|
-
headers: GdsApi::JsonClient.default_request_headers.merge(
|
445
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
446
|
-
),
|
447
|
-
)
|
448
|
-
.will_respond_with(
|
449
|
-
status: 200,
|
450
|
-
body: {
|
451
|
-
"content_id" => @content_id,
|
452
|
-
"document_type" => Pact.like("special_route"),
|
453
|
-
"schema_name" => Pact.like("special_route"),
|
454
|
-
"publishing_app" => Pact.like("publisher"),
|
455
|
-
"rendering_app" => Pact.like("frontend"),
|
456
|
-
"locale" => Pact.like("en"),
|
457
|
-
"routes" => Pact.like([{}]),
|
458
|
-
"public_updated_at" => Pact.like("2015-07-30T13:58:11.000Z"),
|
459
|
-
"details" => Pact.like({}),
|
460
|
-
"publication_state" => "published"
|
461
|
-
},
|
462
|
-
headers: {
|
463
|
-
"Content-Type" => "application/json; charset=utf-8",
|
464
|
-
},
|
465
|
-
)
|
466
|
-
end
|
467
|
-
|
468
|
-
it "responds with 200 and the published content item" do
|
469
|
-
response = @api_client.get_content(@content_id)
|
470
|
-
assert_equal 200, response.code
|
471
|
-
assert_equal response["publication_state"], "published"
|
472
|
-
end
|
473
|
-
end
|
474
|
-
end
|
475
|
-
|
476
|
-
describe "a non-existent item" do
|
477
|
-
before do
|
478
|
-
publishing_api
|
479
|
-
.given("no content exists")
|
480
|
-
.upon_receiving("a request for a non-existent content item")
|
481
|
-
.with(
|
482
|
-
method: :get,
|
483
|
-
path: "/v2/content/#{@content_id}",
|
484
|
-
headers: GdsApi::JsonClient.default_request_headers.merge(
|
485
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
486
|
-
),
|
487
|
-
)
|
488
|
-
.will_respond_with(
|
489
|
-
status: 404,
|
490
|
-
body: {
|
491
|
-
"error" => {
|
492
|
-
"code" => 404,
|
493
|
-
"message" => Pact.term(generate: "not found", matcher: /\S+/)
|
494
|
-
},
|
495
|
-
},
|
496
|
-
headers: {
|
497
|
-
"Content-Type" => "application/json; charset=utf-8",
|
498
|
-
},
|
499
|
-
)
|
500
|
-
end
|
501
|
-
|
502
|
-
it "responds with 404" do
|
503
|
-
assert_raises(GdsApi::HTTPNotFound) do
|
504
|
-
@api_client.get_content(@content_id)
|
505
|
-
end
|
506
|
-
end
|
507
|
-
end
|
508
|
-
end
|
509
|
-
|
510
|
-
describe "#publish" do
|
511
|
-
describe "if the publish command succeeds" do
|
512
|
-
before do
|
513
|
-
publishing_api
|
514
|
-
.given("a draft content item exists with content_id: #{@content_id}")
|
515
|
-
.upon_receiving("a publish request")
|
516
|
-
.with(
|
517
|
-
method: :post,
|
518
|
-
path: "/v2/content/#{@content_id}/publish",
|
519
|
-
body: {
|
520
|
-
update_type: "major",
|
521
|
-
},
|
522
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
523
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
524
|
-
),
|
525
|
-
)
|
526
|
-
.will_respond_with(
|
527
|
-
status: 200
|
528
|
-
)
|
529
|
-
end
|
530
|
-
|
531
|
-
it "responds with 200 if the publish command succeeds" do
|
532
|
-
response = @api_client.publish(@content_id, "major")
|
533
|
-
assert_equal 200, response.code
|
534
|
-
end
|
535
|
-
end
|
536
|
-
|
537
|
-
describe "if the content item does not exist" do
|
538
|
-
before do
|
539
|
-
publishing_api
|
540
|
-
.given("no content exists")
|
541
|
-
.upon_receiving("a publish request")
|
542
|
-
.with(
|
543
|
-
method: :post,
|
544
|
-
path: "/v2/content/#{@content_id}/publish",
|
545
|
-
body: {
|
546
|
-
update_type: "major",
|
547
|
-
},
|
548
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
549
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
550
|
-
),
|
551
|
-
)
|
552
|
-
.will_respond_with(
|
553
|
-
status: 404
|
554
|
-
)
|
555
|
-
end
|
556
|
-
|
557
|
-
it "responds with 404" do
|
558
|
-
error = assert_raises GdsApi::HTTPClientError do
|
559
|
-
@api_client.publish(@content_id, "major")
|
560
|
-
end
|
561
|
-
|
562
|
-
assert_equal 404, error.code
|
563
|
-
end
|
564
|
-
end
|
565
|
-
|
566
|
-
describe "if the update information is invalid" do
|
567
|
-
before do
|
568
|
-
publishing_api
|
569
|
-
.given("a draft content item exists with content_id: #{@content_id}")
|
570
|
-
.upon_receiving("an invalid publish request")
|
571
|
-
.with(
|
572
|
-
method: :post,
|
573
|
-
path: "/v2/content/#{@content_id}/publish",
|
574
|
-
body: {
|
575
|
-
"update_type" => ""
|
576
|
-
},
|
577
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
578
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
579
|
-
),
|
580
|
-
)
|
581
|
-
.will_respond_with(
|
582
|
-
status: 422,
|
583
|
-
body: {
|
584
|
-
"error" => {
|
585
|
-
"code" => 422,
|
586
|
-
"message" => Pact.term(generate: "Unprocessable entity", matcher: /\S+/),
|
587
|
-
"fields" => {
|
588
|
-
"update_type" => Pact.each_like("is required", min: 1),
|
589
|
-
},
|
590
|
-
},
|
591
|
-
}
|
592
|
-
)
|
593
|
-
end
|
594
|
-
|
595
|
-
it "responds with 422" do
|
596
|
-
error = assert_raises GdsApi::HTTPClientError do
|
597
|
-
@api_client.publish(@content_id, "")
|
598
|
-
end
|
599
|
-
|
600
|
-
assert_equal 422, error.code
|
601
|
-
assert_equal "Unprocessable entity", error.error_details["error"]["message"]
|
602
|
-
end
|
603
|
-
end
|
604
|
-
|
605
|
-
describe "if the content item is already published" do
|
606
|
-
before do
|
607
|
-
publishing_api
|
608
|
-
.given("a published content item exists with content_id: #{@content_id}")
|
609
|
-
.upon_receiving("a publish request")
|
610
|
-
.with(
|
611
|
-
method: :post,
|
612
|
-
path: "/v2/content/#{@content_id}/publish",
|
613
|
-
body: {
|
614
|
-
update_type: "major",
|
615
|
-
},
|
616
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
617
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
618
|
-
),
|
619
|
-
)
|
620
|
-
.will_respond_with(
|
621
|
-
status: 400,
|
622
|
-
body: {
|
623
|
-
"error" => {
|
624
|
-
"code" => 400, "message" => Pact.term(generate: "Cannot publish an already published content item", matcher: /\S+/),
|
625
|
-
},
|
626
|
-
}
|
627
|
-
)
|
628
|
-
end
|
629
|
-
|
630
|
-
it "responds with 400" do
|
631
|
-
error = assert_raises GdsApi::HTTPClientError do
|
632
|
-
@api_client.publish(@content_id, "major")
|
633
|
-
end
|
634
|
-
|
635
|
-
assert_equal 400, error.code
|
636
|
-
assert_equal "Cannot publish an already published content item", error.error_details["error"]["message"]
|
637
|
-
end
|
638
|
-
end
|
639
|
-
|
640
|
-
describe "if the update information contains a locale" do
|
641
|
-
before do
|
642
|
-
publishing_api
|
643
|
-
.given("a draft content item exists with content_id: #{@content_id} and locale: fr")
|
644
|
-
.upon_receiving("a publish request")
|
645
|
-
.with(
|
646
|
-
method: :post,
|
647
|
-
path: "/v2/content/#{@content_id}/publish",
|
648
|
-
body: {
|
649
|
-
update_type: "major",
|
650
|
-
locale: "fr",
|
651
|
-
},
|
652
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
653
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
654
|
-
),
|
655
|
-
)
|
656
|
-
.will_respond_with(
|
657
|
-
status: 200,
|
658
|
-
)
|
659
|
-
end
|
660
|
-
|
661
|
-
it "responds with 200 if the publish command succeeds" do
|
662
|
-
response = @api_client.publish(@content_id, "major", locale: "fr")
|
663
|
-
assert_equal 200, response.code
|
664
|
-
end
|
665
|
-
end
|
666
|
-
|
667
|
-
describe "optimistic locking" do
|
668
|
-
describe "if the content item has not changed since it was requested" do
|
669
|
-
before do
|
670
|
-
publishing_api
|
671
|
-
.given("the content item #{@content_id} is at version 3")
|
672
|
-
.upon_receiving("a publish request for version 3")
|
673
|
-
.with(
|
674
|
-
method: :post,
|
675
|
-
path: "/v2/content/#{@content_id}/publish",
|
676
|
-
body: {
|
677
|
-
update_type: "minor",
|
678
|
-
previous_version: 3,
|
679
|
-
},
|
680
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
681
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
682
|
-
),
|
683
|
-
)
|
684
|
-
.will_respond_with(
|
685
|
-
status: 200,
|
686
|
-
)
|
687
|
-
end
|
688
|
-
|
689
|
-
it "responds with 200 OK" do
|
690
|
-
response = @api_client.publish(@content_id, "minor", previous_version: 3)
|
691
|
-
assert_equal 200, response.code
|
692
|
-
end
|
693
|
-
end
|
694
|
-
|
695
|
-
describe "if the content item has changed in the meantime" do
|
696
|
-
before do
|
697
|
-
publishing_api
|
698
|
-
.given("the content item #{@content_id} is at version 3")
|
699
|
-
.upon_receiving("a publish request for version 2")
|
700
|
-
.with(
|
701
|
-
method: :post,
|
702
|
-
path: "/v2/content/#{@content_id}/publish",
|
703
|
-
body: {
|
704
|
-
update_type: "minor",
|
705
|
-
previous_version: 2,
|
706
|
-
},
|
707
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
708
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
709
|
-
),
|
710
|
-
)
|
711
|
-
.will_respond_with(
|
712
|
-
status: 409,
|
713
|
-
body: {
|
714
|
-
"error" => {
|
715
|
-
"code" => 409,
|
716
|
-
"message" => Pact.term(generate: "Conflict", matcher: /\S+/),
|
717
|
-
"fields" => {
|
718
|
-
"previous_version" => Pact.each_like("does not match", min: 1),
|
719
|
-
},
|
720
|
-
},
|
721
|
-
},
|
722
|
-
headers: {
|
723
|
-
"Content-Type" => "application/json; charset=utf-8"
|
724
|
-
}
|
725
|
-
)
|
726
|
-
end
|
727
|
-
|
728
|
-
it "responds with 409 Conflict" do
|
729
|
-
error = assert_raises GdsApi::HTTPClientError do
|
730
|
-
@api_client.publish(@content_id, "minor", previous_version: 2)
|
731
|
-
end
|
732
|
-
assert_equal 409, error.code
|
733
|
-
assert_equal "Conflict", error.error_details["error"]["message"]
|
734
|
-
end
|
735
|
-
end
|
736
|
-
end
|
737
|
-
end
|
738
|
-
|
739
|
-
describe "#unpublish" do
|
740
|
-
describe "if the unpublish command succeeds" do
|
741
|
-
before do
|
742
|
-
publishing_api
|
743
|
-
.given("a published content item exists with content_id: #{@content_id}")
|
744
|
-
.upon_receiving("an unpublish request")
|
745
|
-
.with(
|
746
|
-
method: :post,
|
747
|
-
path: "/v2/content/#{@content_id}/unpublish",
|
748
|
-
body: {
|
749
|
-
type: "gone",
|
750
|
-
},
|
751
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
752
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
753
|
-
),
|
754
|
-
)
|
755
|
-
.will_respond_with(
|
756
|
-
status: 200
|
757
|
-
)
|
758
|
-
end
|
759
|
-
|
760
|
-
it "responds with 200" do
|
761
|
-
response = @api_client.unpublish(@content_id, type: "gone")
|
762
|
-
assert_equal 200, response.code
|
763
|
-
end
|
764
|
-
end
|
765
|
-
|
766
|
-
describe "if the content item does not exist" do
|
767
|
-
before do
|
768
|
-
publishing_api
|
769
|
-
.given("no content exists")
|
770
|
-
.upon_receiving("an unpublish request")
|
771
|
-
.with(
|
772
|
-
method: :post,
|
773
|
-
path: "/v2/content/#{@content_id}/unpublish",
|
774
|
-
body: {
|
775
|
-
type: "gone",
|
776
|
-
},
|
777
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
778
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
779
|
-
),
|
780
|
-
)
|
781
|
-
.will_respond_with(
|
782
|
-
status: 404
|
783
|
-
)
|
784
|
-
end
|
785
|
-
|
786
|
-
it "responds with 404" do
|
787
|
-
error = assert_raises GdsApi::HTTPClientError do
|
788
|
-
@api_client.unpublish(@content_id, type: "gone")
|
789
|
-
end
|
790
|
-
|
791
|
-
assert_equal 404, error.code
|
792
|
-
end
|
793
|
-
end
|
794
|
-
|
795
|
-
describe "if the type is incorrect" do
|
796
|
-
before do
|
797
|
-
publishing_api
|
798
|
-
.given("a published content item exists with content_id: #{@content_id}")
|
799
|
-
.upon_receiving("an invalid unpublish request")
|
800
|
-
.with(
|
801
|
-
method: :post,
|
802
|
-
path: "/v2/content/#{@content_id}/unpublish",
|
803
|
-
body: {
|
804
|
-
type: "not-a-valid-type",
|
805
|
-
},
|
806
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
807
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
808
|
-
),
|
809
|
-
)
|
810
|
-
.will_respond_with(
|
811
|
-
status: 422,
|
812
|
-
body: {
|
813
|
-
"error" => {
|
814
|
-
"code" => 422,
|
815
|
-
"message" => Pact.term(generate: "not-a-valid-type is not a valid unpublishing type", matcher: /\S+/),
|
816
|
-
"fields" => {},
|
817
|
-
},
|
818
|
-
}
|
819
|
-
)
|
820
|
-
end
|
821
|
-
|
822
|
-
it "responds with 422" do
|
823
|
-
error = assert_raises GdsApi::HTTPClientError do
|
824
|
-
@api_client.unpublish(@content_id, type: "not-a-valid-type")
|
825
|
-
end
|
826
|
-
|
827
|
-
assert_equal 422, error.code
|
828
|
-
assert_equal "not-a-valid-type is not a valid unpublishing type", error.error_details["error"]["message"]
|
829
|
-
end
|
830
|
-
end
|
831
|
-
|
832
|
-
describe "if the content item is already unpublished" do
|
833
|
-
before do
|
834
|
-
publishing_api
|
835
|
-
.given("an unpublished content item exists with content_id: #{@content_id}")
|
836
|
-
.upon_receiving("an unpublish request")
|
837
|
-
.with(
|
838
|
-
method: :post,
|
839
|
-
path: "/v2/content/#{@content_id}/unpublish",
|
840
|
-
body: {
|
841
|
-
type: "gone",
|
842
|
-
},
|
843
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
844
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
845
|
-
),
|
846
|
-
)
|
847
|
-
.will_respond_with(
|
848
|
-
status: 200
|
849
|
-
)
|
850
|
-
end
|
851
|
-
|
852
|
-
it "responds with 200 and updates the unpublishing" do
|
853
|
-
response = @api_client.unpublish(@content_id, type: "gone")
|
854
|
-
assert_equal 200, response.code
|
855
|
-
end
|
856
|
-
end
|
857
|
-
|
858
|
-
describe "optimistic locking" do
|
859
|
-
describe "if the content item has not changed since it was requested" do
|
860
|
-
before do
|
861
|
-
publishing_api
|
862
|
-
.given("the published content item #{@content_id} is at version 3")
|
863
|
-
.upon_receiving("an unpublish request for version 3")
|
864
|
-
.with(
|
865
|
-
method: :post,
|
866
|
-
path: "/v2/content/#{@content_id}/unpublish",
|
867
|
-
body: {
|
868
|
-
type: "gone",
|
869
|
-
previous_version: 3,
|
870
|
-
},
|
871
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
872
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
873
|
-
),
|
874
|
-
)
|
875
|
-
.will_respond_with(
|
876
|
-
status: 200,
|
877
|
-
)
|
878
|
-
end
|
879
|
-
|
880
|
-
it "responds with 200 OK" do
|
881
|
-
response = @api_client.unpublish(@content_id, type: "gone", previous_version: 3)
|
882
|
-
assert_equal 200, response.code
|
883
|
-
end
|
884
|
-
end
|
885
|
-
|
886
|
-
describe "if the content item has changed in the meantime" do
|
887
|
-
before do
|
888
|
-
publishing_api
|
889
|
-
.given("the published content item #{@content_id} is at version 3")
|
890
|
-
.upon_receiving("an unpublish request for version 2")
|
891
|
-
.with(
|
892
|
-
method: :post,
|
893
|
-
path: "/v2/content/#{@content_id}/unpublish",
|
894
|
-
body: {
|
895
|
-
type: "gone",
|
896
|
-
previous_version: 2,
|
897
|
-
},
|
898
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
899
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
900
|
-
),
|
901
|
-
)
|
902
|
-
.will_respond_with(
|
903
|
-
status: 409,
|
904
|
-
body: {
|
905
|
-
"error" => {
|
906
|
-
"code" => 409,
|
907
|
-
"message" => Pact.term(generate: "Conflict", matcher: /\S+/),
|
908
|
-
"fields" => {
|
909
|
-
"previous_version" => Pact.each_like("does not match", min: 1),
|
910
|
-
},
|
911
|
-
},
|
912
|
-
},
|
913
|
-
headers: {
|
914
|
-
"Content-Type" => "application/json; charset=utf-8"
|
915
|
-
}
|
916
|
-
)
|
917
|
-
end
|
918
|
-
|
919
|
-
it "responds with 409 Conflict" do
|
920
|
-
error = assert_raises GdsApi::HTTPClientError do
|
921
|
-
@api_client.unpublish(@content_id, type: "gone", previous_version: 2)
|
922
|
-
end
|
923
|
-
assert_equal 409, error.code
|
924
|
-
assert_equal "Conflict", error.error_details["error"]["message"]
|
925
|
-
end
|
926
|
-
end
|
927
|
-
end
|
928
|
-
end
|
929
|
-
|
930
|
-
describe "#patch_links" do
|
931
|
-
describe "when setting links of the same type" do
|
932
|
-
before do
|
933
|
-
publishing_api
|
934
|
-
.given("organisation links exist for content_id #{@content_id}")
|
935
|
-
.upon_receiving("a patch organisation links request")
|
936
|
-
.with(
|
937
|
-
method: :patch,
|
938
|
-
path: "/v2/links/#{@content_id}",
|
939
|
-
body: {
|
940
|
-
links: {
|
941
|
-
organisations: ["591436ab-c2ae-416f-a3c5-1901d633fbfb"],
|
942
|
-
}
|
943
|
-
},
|
944
|
-
headers: {
|
945
|
-
"Content-Type" => "application/json",
|
946
|
-
},
|
947
|
-
)
|
948
|
-
.will_respond_with(
|
949
|
-
status: 200,
|
950
|
-
body: {
|
951
|
-
links: {
|
952
|
-
organisations: ["591436ab-c2ae-416f-a3c5-1901d633fbfb"],
|
953
|
-
}
|
954
|
-
}
|
955
|
-
)
|
956
|
-
end
|
957
|
-
|
958
|
-
it "replaces the links and responds with the new links" do
|
959
|
-
response = @api_client.patch_links(@content_id, links: {
|
960
|
-
organisations: ["591436ab-c2ae-416f-a3c5-1901d633fbfb"],
|
961
|
-
})
|
962
|
-
assert_equal 200, response.code
|
963
|
-
assert_equal(
|
964
|
-
["591436ab-c2ae-416f-a3c5-1901d633fbfb"],
|
965
|
-
response['links']['organisations']
|
966
|
-
)
|
967
|
-
end
|
968
|
-
end
|
969
|
-
|
970
|
-
describe "when setting links of a different type" do
|
971
|
-
before do
|
972
|
-
publishing_api
|
973
|
-
.given("organisation links exist for content_id #{@content_id}")
|
974
|
-
.upon_receiving("a patch topic links request")
|
975
|
-
.with(
|
976
|
-
method: :patch,
|
977
|
-
path: "/v2/links/#{@content_id}",
|
978
|
-
body: {
|
979
|
-
links: {
|
980
|
-
topics: ["225df4a8-2945-4e9b-8799-df7424a90b69"],
|
981
|
-
}
|
982
|
-
},
|
983
|
-
headers: {
|
984
|
-
"Content-Type" => "application/json",
|
985
|
-
},
|
986
|
-
)
|
987
|
-
.will_respond_with(
|
988
|
-
status: 200,
|
989
|
-
body: {
|
990
|
-
links: {
|
991
|
-
topics: ["225df4a8-2945-4e9b-8799-df7424a90b69"],
|
992
|
-
organisations: ["20583132-1619-4c68-af24-77583172c070"]
|
993
|
-
}
|
994
|
-
}
|
995
|
-
)
|
996
|
-
end
|
997
|
-
|
998
|
-
it "adds the new type of links and responds with the whole link set" do
|
999
|
-
response = @api_client.patch_links(@content_id, links: {
|
1000
|
-
topics: ["225df4a8-2945-4e9b-8799-df7424a90b69"],
|
1001
|
-
})
|
1002
|
-
|
1003
|
-
assert_equal 200, response.code
|
1004
|
-
assert_equal(
|
1005
|
-
{
|
1006
|
-
'topics' => ["225df4a8-2945-4e9b-8799-df7424a90b69"],
|
1007
|
-
'organisations' => ["20583132-1619-4c68-af24-77583172c070"],
|
1008
|
-
},
|
1009
|
-
response['links']
|
1010
|
-
)
|
1011
|
-
end
|
1012
|
-
end
|
1013
|
-
|
1014
|
-
describe "when deleting links of a specific type" do
|
1015
|
-
before do
|
1016
|
-
publishing_api
|
1017
|
-
.given("organisation links exist for content_id #{@content_id}")
|
1018
|
-
.upon_receiving("a patch blank organisation links request")
|
1019
|
-
.with(
|
1020
|
-
method: :patch,
|
1021
|
-
path: "/v2/links/#{@content_id}",
|
1022
|
-
body: {
|
1023
|
-
links: {
|
1024
|
-
organisations: [],
|
1025
|
-
}
|
1026
|
-
},
|
1027
|
-
headers: {
|
1028
|
-
"Content-Type" => "application/json",
|
1029
|
-
},
|
1030
|
-
)
|
1031
|
-
.will_respond_with(
|
1032
|
-
status: 200,
|
1033
|
-
body: {
|
1034
|
-
links: {}
|
1035
|
-
}
|
1036
|
-
)
|
1037
|
-
end
|
1038
|
-
|
1039
|
-
it "responds with the links" do
|
1040
|
-
response = @api_client.patch_links(@content_id, links: {
|
1041
|
-
organisations: [],
|
1042
|
-
})
|
1043
|
-
|
1044
|
-
assert_equal 200, response.code
|
1045
|
-
assert_equal({}, response['links'])
|
1046
|
-
end
|
1047
|
-
end
|
1048
|
-
|
1049
|
-
describe "when there's no links entry" do
|
1050
|
-
before do
|
1051
|
-
publishing_api
|
1052
|
-
.given("no links exist for content_id #{@content_id}")
|
1053
|
-
.upon_receiving("a patch organisation links request")
|
1054
|
-
.with(
|
1055
|
-
method: :patch,
|
1056
|
-
path: "/v2/links/#{@content_id}",
|
1057
|
-
body: {
|
1058
|
-
links: {
|
1059
|
-
organisations: ["591436ab-c2ae-416f-a3c5-1901d633fbfb"],
|
1060
|
-
}
|
1061
|
-
},
|
1062
|
-
headers: {
|
1063
|
-
"Content-Type" => "application/json",
|
1064
|
-
},
|
1065
|
-
)
|
1066
|
-
.will_respond_with(
|
1067
|
-
status: 200,
|
1068
|
-
body: {
|
1069
|
-
links: {
|
1070
|
-
organisations: ["591436ab-c2ae-416f-a3c5-1901d633fbfb"],
|
1071
|
-
}
|
1072
|
-
},
|
1073
|
-
)
|
1074
|
-
end
|
1075
|
-
|
1076
|
-
it "responds with the links" do
|
1077
|
-
response = @api_client.patch_links(@content_id, links: {
|
1078
|
-
organisations: ["591436ab-c2ae-416f-a3c5-1901d633fbfb"],
|
1079
|
-
})
|
1080
|
-
|
1081
|
-
assert_equal 200, response.code
|
1082
|
-
assert_equal(
|
1083
|
-
{
|
1084
|
-
'organisations' => ["591436ab-c2ae-416f-a3c5-1901d633fbfb"],
|
1085
|
-
},
|
1086
|
-
response['links']
|
1087
|
-
)
|
1088
|
-
end
|
1089
|
-
end
|
1090
|
-
|
1091
|
-
describe "optimistic locking" do
|
1092
|
-
describe "if the linkset has not changed since it was requested" do
|
1093
|
-
before do
|
1094
|
-
publishing_api
|
1095
|
-
.given("the linkset for #{@content_id} is at version 3")
|
1096
|
-
.upon_receiving("a request to update the linkset at version 3")
|
1097
|
-
.with(
|
1098
|
-
method: :patch,
|
1099
|
-
path: "/v2/links/#{@content_id}",
|
1100
|
-
body: {
|
1101
|
-
links: {
|
1102
|
-
organisations: ["591436ab-c2ae-416f-a3c5-1901d633fbfb"],
|
1103
|
-
},
|
1104
|
-
previous_version: 3,
|
1105
|
-
},
|
1106
|
-
headers: {
|
1107
|
-
"Content-Type" => "application/json",
|
1108
|
-
},
|
1109
|
-
)
|
1110
|
-
.will_respond_with(
|
1111
|
-
status: 200,
|
1112
|
-
)
|
1113
|
-
end
|
1114
|
-
|
1115
|
-
it "responds with 200 OK" do
|
1116
|
-
response = @api_client.patch_links(@content_id,
|
1117
|
-
links: {
|
1118
|
-
organisations: ["591436ab-c2ae-416f-a3c5-1901d633fbfb"],
|
1119
|
-
},
|
1120
|
-
previous_version: 3,
|
1121
|
-
)
|
1122
|
-
|
1123
|
-
assert_equal 200, response.code
|
1124
|
-
end
|
1125
|
-
end
|
1126
|
-
|
1127
|
-
describe "if the content item has changed in the meantime" do
|
1128
|
-
before do
|
1129
|
-
publishing_api
|
1130
|
-
.given("the linkset for #{@content_id} is at version 3")
|
1131
|
-
.upon_receiving("a request to update the linkset at version 2")
|
1132
|
-
.with(
|
1133
|
-
method: :patch,
|
1134
|
-
path: "/v2/links/#{@content_id}",
|
1135
|
-
body: {
|
1136
|
-
links: {
|
1137
|
-
organisations: ["591436ab-c2ae-416f-a3c5-1901d633fbfb"],
|
1138
|
-
},
|
1139
|
-
previous_version: 2,
|
1140
|
-
},
|
1141
|
-
headers: {
|
1142
|
-
"Content-Type" => "application/json",
|
1143
|
-
},
|
1144
|
-
)
|
1145
|
-
.will_respond_with(
|
1146
|
-
status: 409,
|
1147
|
-
body: {
|
1148
|
-
"error" => {
|
1149
|
-
"code" => 409,
|
1150
|
-
"message" => Pact.term(generate: "Conflict", matcher: /\S+/),
|
1151
|
-
"fields" => {
|
1152
|
-
"previous_version" => Pact.each_like("does not match", min: 1),
|
1153
|
-
},
|
1154
|
-
},
|
1155
|
-
},
|
1156
|
-
headers: {
|
1157
|
-
"Content-Type" => "application/json; charset=utf-8"
|
1158
|
-
}
|
1159
|
-
)
|
1160
|
-
end
|
1161
|
-
|
1162
|
-
it "responds with 409 Conflict" do
|
1163
|
-
error = assert_raises GdsApi::HTTPClientError do
|
1164
|
-
@api_client.patch_links(@content_id,
|
1165
|
-
links: {
|
1166
|
-
organisations: ["591436ab-c2ae-416f-a3c5-1901d633fbfb"],
|
1167
|
-
},
|
1168
|
-
previous_version: 2,
|
1169
|
-
)
|
1170
|
-
end
|
1171
|
-
|
1172
|
-
assert_equal 409, error.code
|
1173
|
-
assert_equal "Conflict", error.error_details["error"]["message"]
|
1174
|
-
end
|
1175
|
-
end
|
1176
|
-
end
|
1177
|
-
end
|
1178
|
-
|
1179
|
-
describe "#get_linkables" do
|
1180
|
-
let(:linkables) {
|
1181
|
-
[
|
1182
|
-
{
|
1183
|
-
"title" => "Content Item A",
|
1184
|
-
"internal_name" => "an internal name",
|
1185
|
-
"content_id" => "aaaaaaaa-aaaa-1aaa-aaaa-aaaaaaaaaaaa",
|
1186
|
-
"publication_state" => "draft",
|
1187
|
-
"base_path" => "/a-base-path",
|
1188
|
-
},
|
1189
|
-
{
|
1190
|
-
"title" => "Content Item B",
|
1191
|
-
"internal_name" => "Content Item B",
|
1192
|
-
"content_id" => "bbbbbbbb-bbbb-2bbb-bbbb-bbbbbbbbbbbb",
|
1193
|
-
"publication_state" => "published",
|
1194
|
-
"base_path" => "/another-base-path",
|
1195
|
-
},
|
1196
|
-
]
|
1197
|
-
}
|
1198
|
-
|
1199
|
-
it "returns the content items of a given document_type" do
|
1200
|
-
publishing_api
|
1201
|
-
.given("there is content with document_type 'topic'")
|
1202
|
-
.upon_receiving("a get linkables request")
|
1203
|
-
.with(
|
1204
|
-
method: :get,
|
1205
|
-
path: "/v2/linkables",
|
1206
|
-
query: "document_type=topic",
|
1207
|
-
headers: GdsApi::JsonClient.default_request_headers.merge(
|
1208
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
1209
|
-
),
|
1210
|
-
)
|
1211
|
-
.will_respond_with(
|
1212
|
-
status: 200,
|
1213
|
-
body: linkables,
|
1214
|
-
)
|
1215
|
-
|
1216
|
-
response = @api_client.get_linkables(document_type: "topic")
|
1217
|
-
assert_equal 200, response.code
|
1218
|
-
assert_equal linkables, response.to_a
|
1219
|
-
end
|
1220
|
-
end
|
1221
|
-
|
1222
|
-
describe "#get_content_items" do
|
1223
|
-
it "returns the content items of a certain document_type" do
|
1224
|
-
publishing_api
|
1225
|
-
.given("there is content with document_type 'topic'")
|
1226
|
-
.upon_receiving("a get entries request")
|
1227
|
-
.with(
|
1228
|
-
method: :get,
|
1229
|
-
path: "/v2/content",
|
1230
|
-
query: "document_type=topic&fields%5B%5D=title&fields%5B%5D=base_path",
|
1231
|
-
headers: GdsApi::JsonClient.default_request_headers.merge(
|
1232
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
1233
|
-
),
|
1234
|
-
)
|
1235
|
-
.will_respond_with(
|
1236
|
-
status: 200,
|
1237
|
-
body: {
|
1238
|
-
total: 2,
|
1239
|
-
pages: 1,
|
1240
|
-
current_page: 1,
|
1241
|
-
links: [{
|
1242
|
-
href: "http://example.org/v2/content?document_type=topic&fields[]=title&fields[]=base_path&page=1",
|
1243
|
-
rel: "self"
|
1244
|
-
}],
|
1245
|
-
results: [
|
1246
|
-
{ title: 'Content Item A', base_path: '/a-base-path' },
|
1247
|
-
{ title: 'Content Item B', base_path: '/another-base-path' },
|
1248
|
-
]
|
1249
|
-
}
|
1250
|
-
)
|
1251
|
-
|
1252
|
-
response = @api_client.get_content_items(
|
1253
|
-
document_type: 'topic',
|
1254
|
-
fields: [:title, :base_path],
|
1255
|
-
)
|
1256
|
-
|
1257
|
-
assert_equal 200, response.code
|
1258
|
-
|
1259
|
-
assert_equal [
|
1260
|
-
["total", 2],
|
1261
|
-
["pages", 1],
|
1262
|
-
["current_page", 1],
|
1263
|
-
["links", [{ "href" => "http://example.org/v2/content?document_type=topic&fields[]=title&fields[]=base_path&page=1", "rel" => "self" }]],
|
1264
|
-
["results", [{ "title" => "Content Item A", "base_path" => "/a-base-path" }, { "title" => "Content Item B", "base_path" => "/another-base-path" }]]
|
1265
|
-
], response.to_a
|
1266
|
-
end
|
1267
|
-
|
1268
|
-
it "returns the content items in english locale by default" do
|
1269
|
-
publishing_api
|
1270
|
-
.given("a content item exists in multiple locales with content_id: #{@content_id}")
|
1271
|
-
.upon_receiving("a get entries request")
|
1272
|
-
.with(
|
1273
|
-
method: :get,
|
1274
|
-
path: "/v2/content",
|
1275
|
-
query: "document_type=topic&fields%5B%5D=content_id&fields%5B%5D=locale",
|
1276
|
-
headers: GdsApi::JsonClient.default_request_headers.merge(
|
1277
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
1278
|
-
),
|
1279
|
-
)
|
1280
|
-
.will_respond_with(
|
1281
|
-
status: 200,
|
1282
|
-
body: {
|
1283
|
-
total: 1,
|
1284
|
-
pages: 1,
|
1285
|
-
current_page: 1,
|
1286
|
-
links: [{
|
1287
|
-
href: "http://example.org/v2/content?document_type=topic&fields[]=content_id&fields[]=locale&page=1",
|
1288
|
-
rel: "self"
|
1289
|
-
}],
|
1290
|
-
results: [
|
1291
|
-
{ content_id: @content_id, locale: "en" }
|
1292
|
-
]
|
1293
|
-
}
|
1294
|
-
)
|
1295
|
-
|
1296
|
-
response = @api_client.get_content_items(
|
1297
|
-
document_type: 'topic',
|
1298
|
-
fields: [:content_id, :locale],
|
1299
|
-
)
|
1300
|
-
|
1301
|
-
assert_equal 200, response.code
|
1302
|
-
|
1303
|
-
assert_equal [
|
1304
|
-
["total", 1],
|
1305
|
-
["pages", 1],
|
1306
|
-
["current_page", 1],
|
1307
|
-
["links", [{ "href" => "http://example.org/v2/content?document_type=topic&fields[]=content_id&fields[]=locale&page=1", "rel" => "self" }]],
|
1308
|
-
["results", [{ "content_id" => "bed722e6-db68-43e5-9079-063f623335a7", "locale" => "en" }]]
|
1309
|
-
], response.to_a
|
1310
|
-
end
|
1311
|
-
|
1312
|
-
it "returns the content items in a specific locale" do
|
1313
|
-
publishing_api
|
1314
|
-
.given("a content item exists in multiple locales with content_id: #{@content_id}")
|
1315
|
-
.upon_receiving("a get entries request with a specific locale")
|
1316
|
-
.with(
|
1317
|
-
method: :get,
|
1318
|
-
path: "/v2/content",
|
1319
|
-
query: "document_type=topic&fields%5B%5D=content_id&fields%5B%5D=locale&locale=fr",
|
1320
|
-
headers: GdsApi::JsonClient.default_request_headers.merge(
|
1321
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
1322
|
-
),
|
1323
|
-
)
|
1324
|
-
.will_respond_with(
|
1325
|
-
status: 200,
|
1326
|
-
body: {
|
1327
|
-
total: 1,
|
1328
|
-
pages: 1,
|
1329
|
-
current_page: 1,
|
1330
|
-
links: [{
|
1331
|
-
href: "http://example.org/v2/content?document_type=topic&fields[]=content_id&fields[]=locale&locale=fr&page=1",
|
1332
|
-
rel: "self"
|
1333
|
-
}],
|
1334
|
-
results: [
|
1335
|
-
{ content_id: @content_id, locale: "fr" }
|
1336
|
-
]
|
1337
|
-
}
|
1338
|
-
)
|
1339
|
-
|
1340
|
-
response = @api_client.get_content_items(
|
1341
|
-
document_type: 'topic',
|
1342
|
-
fields: [:content_id, :locale],
|
1343
|
-
locale: 'fr',
|
1344
|
-
)
|
1345
|
-
|
1346
|
-
assert_equal 200, response.code
|
1347
|
-
assert_equal [
|
1348
|
-
["total", 1],
|
1349
|
-
["pages", 1],
|
1350
|
-
["current_page", 1],
|
1351
|
-
["links", [{ "href" => "http://example.org/v2/content?document_type=topic&fields[]=content_id&fields[]=locale&locale=fr&page=1", "rel" => "self" }]],
|
1352
|
-
["results", [{ "content_id" => "bed722e6-db68-43e5-9079-063f623335a7", "locale" => "fr" }]]
|
1353
|
-
], response.to_a
|
1354
|
-
end
|
1355
|
-
|
1356
|
-
it "returns the content items in all the available locales" do
|
1357
|
-
publishing_api
|
1358
|
-
.given("a content item exists in multiple locales with content_id: #{@content_id}")
|
1359
|
-
.upon_receiving("a get entries request with an 'all' locale")
|
1360
|
-
.with(
|
1361
|
-
method: :get,
|
1362
|
-
path: "/v2/content",
|
1363
|
-
query: "document_type=topic&fields%5B%5D=content_id&fields%5B%5D=locale&locale=all",
|
1364
|
-
headers: GdsApi::JsonClient.default_request_headers.merge(
|
1365
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
1366
|
-
),
|
1367
|
-
)
|
1368
|
-
.will_respond_with(
|
1369
|
-
status: 200,
|
1370
|
-
body: {
|
1371
|
-
total: 3,
|
1372
|
-
pages: 1,
|
1373
|
-
current_page: 1,
|
1374
|
-
links: [{
|
1375
|
-
href: "http://example.org/v2/content?document_type=topic&fields[]=content_id&fields[]=locale&locale=all&page=1",
|
1376
|
-
rel: "self"
|
1377
|
-
}],
|
1378
|
-
results: [
|
1379
|
-
{ content_id: @content_id, locale: "en" },
|
1380
|
-
{ content_id: @content_id, locale: "fr" },
|
1381
|
-
{ content_id: @content_id, locale: "ar" },
|
1382
|
-
]
|
1383
|
-
}
|
1384
|
-
)
|
1385
|
-
|
1386
|
-
response = @api_client.get_content_items(
|
1387
|
-
document_type: 'topic',
|
1388
|
-
fields: [:content_id, :locale],
|
1389
|
-
locale: 'all',
|
1390
|
-
)
|
1391
|
-
|
1392
|
-
assert_equal 200, response.code
|
1393
|
-
assert_equal [
|
1394
|
-
["total", 3],
|
1395
|
-
["pages", 1], ["current_page", 1],
|
1396
|
-
["links",
|
1397
|
-
[{ "href" => "http://example.org/v2/content?document_type=topic&fields[]=content_id&fields[]=locale&locale=all&page=1", "rel" => "self" }]],
|
1398
|
-
["results",
|
1399
|
-
[{ "content_id" => "bed722e6-db68-43e5-9079-063f623335a7", "locale" => "en" },
|
1400
|
-
{ "content_id" => "bed722e6-db68-43e5-9079-063f623335a7", "locale" => "fr" },
|
1401
|
-
{ "content_id" => "bed722e6-db68-43e5-9079-063f623335a7", "locale" => "ar" }]]
|
1402
|
-
], response.to_a
|
1403
|
-
end
|
1404
|
-
|
1405
|
-
it "returns details hashes" do
|
1406
|
-
publishing_api
|
1407
|
-
.given("a content item exists with content_id: #{@content_id} and it has details")
|
1408
|
-
.upon_receiving("a get entries request with details field")
|
1409
|
-
.with(
|
1410
|
-
method: :get,
|
1411
|
-
path: "/v2/content",
|
1412
|
-
query: "document_type=topic&fields%5B%5D=content_id&fields%5B%5D=details",
|
1413
|
-
headers: GdsApi::JsonClient.default_request_headers.merge(
|
1414
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
1415
|
-
),
|
1416
|
-
)
|
1417
|
-
.will_respond_with(
|
1418
|
-
status: 200,
|
1419
|
-
body: {
|
1420
|
-
total: 1,
|
1421
|
-
pages: 1,
|
1422
|
-
current_page: 1,
|
1423
|
-
links: [{
|
1424
|
-
href: "http://example.org/v2/content?document_type=topic&fields[]=content_id&fields[]=details&page=1",
|
1425
|
-
rel: "self"
|
1426
|
-
}],
|
1427
|
-
results: [
|
1428
|
-
{ content_id: @content_id, details: { foo: :bar } }
|
1429
|
-
]
|
1430
|
-
}
|
1431
|
-
)
|
1432
|
-
|
1433
|
-
response = @api_client.get_content_items(
|
1434
|
-
document_type: 'topic',
|
1435
|
-
fields: [:content_id, :details],
|
1436
|
-
)
|
1437
|
-
|
1438
|
-
assert_equal 200, response.code
|
1439
|
-
|
1440
|
-
assert_equal [
|
1441
|
-
["total", 1],
|
1442
|
-
["pages", 1],
|
1443
|
-
["current_page", 1],
|
1444
|
-
["links", [{ "href" => "http://example.org/v2/content?document_type=topic&fields[]=content_id&fields[]=details&page=1", "rel" => "self" }]],
|
1445
|
-
["results", [{ "content_id" => "bed722e6-db68-43e5-9079-063f623335a7", "details" => { "foo" => "bar" } }]]
|
1446
|
-
], response.to_a
|
1447
|
-
end
|
1448
|
-
end
|
1449
|
-
|
1450
|
-
describe "#discard_draft(content_id, options = {})" do
|
1451
|
-
describe "when the content item exists" do
|
1452
|
-
before do
|
1453
|
-
publishing_api
|
1454
|
-
.given("a content item exists with content_id: #{@content_id}")
|
1455
|
-
.upon_receiving("a request to discard draft content")
|
1456
|
-
.with(
|
1457
|
-
method: :post,
|
1458
|
-
path: "/v2/content/#{@content_id}/discard-draft",
|
1459
|
-
body: {},
|
1460
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
1461
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
1462
|
-
),
|
1463
|
-
)
|
1464
|
-
.will_respond_with(
|
1465
|
-
status: 200,
|
1466
|
-
)
|
1467
|
-
end
|
1468
|
-
|
1469
|
-
it "responds with 200" do
|
1470
|
-
response = @api_client.discard_draft(@content_id)
|
1471
|
-
assert_equal 200, response.code
|
1472
|
-
end
|
1473
|
-
end
|
1474
|
-
|
1475
|
-
describe "when the content item exists and is French" do
|
1476
|
-
before do
|
1477
|
-
publishing_api
|
1478
|
-
.given("a French content item exists with content_id: #{@content_id}")
|
1479
|
-
.upon_receiving("a request to discard French draft content")
|
1480
|
-
.with(
|
1481
|
-
method: :post,
|
1482
|
-
path: "/v2/content/#{@content_id}/discard-draft",
|
1483
|
-
body: {
|
1484
|
-
locale: "fr",
|
1485
|
-
},
|
1486
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
1487
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
1488
|
-
),
|
1489
|
-
)
|
1490
|
-
.will_respond_with(
|
1491
|
-
status: 200,
|
1492
|
-
)
|
1493
|
-
end
|
1494
|
-
|
1495
|
-
it "responds with 200" do
|
1496
|
-
response = @api_client.discard_draft(@content_id, locale: "fr")
|
1497
|
-
assert_equal 200, response.code
|
1498
|
-
end
|
1499
|
-
end
|
1500
|
-
|
1501
|
-
describe "when there is no content with that content_id" do
|
1502
|
-
before do
|
1503
|
-
publishing_api
|
1504
|
-
.given("no content exists")
|
1505
|
-
.upon_receiving("a request to discard draft content")
|
1506
|
-
.with(
|
1507
|
-
method: :post,
|
1508
|
-
path: "/v2/content/#{@content_id}/discard-draft",
|
1509
|
-
body: {},
|
1510
|
-
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
1511
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
1512
|
-
),
|
1513
|
-
)
|
1514
|
-
.will_respond_with(
|
1515
|
-
status: 404,
|
1516
|
-
)
|
1517
|
-
end
|
1518
|
-
|
1519
|
-
it "responds with a 404" do
|
1520
|
-
error = assert_raises GdsApi::HTTPClientError do
|
1521
|
-
@api_client.discard_draft(@content_id)
|
1522
|
-
end
|
1523
|
-
|
1524
|
-
assert_equal 404, error.code
|
1525
|
-
end
|
1526
|
-
end
|
1527
|
-
end
|
1528
|
-
describe "#get_linked_items" do
|
1529
|
-
describe "if the content item does not exist" do
|
1530
|
-
before do
|
1531
|
-
publishing_api
|
1532
|
-
.given("no content exists")
|
1533
|
-
.upon_receiving("a request to return the items linked to it")
|
1534
|
-
.with(
|
1535
|
-
method: :get,
|
1536
|
-
path: "/v2/linked/#{@content_id}",
|
1537
|
-
query: "fields%5B%5D=content_id&fields%5B%5D=base_path&link_type=topic",
|
1538
|
-
headers: GdsApi::JsonClient.default_request_headers.merge(
|
1539
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
1540
|
-
),
|
1541
|
-
)
|
1542
|
-
.will_respond_with(
|
1543
|
-
status: 404,
|
1544
|
-
body: {
|
1545
|
-
"error" => {
|
1546
|
-
"code" => 404,
|
1547
|
-
"message" => Pact.term(generate: "not found", matcher: /\S+/)
|
1548
|
-
},
|
1549
|
-
},
|
1550
|
-
headers: {
|
1551
|
-
"Content-Type" => "application/json; charset=utf-8",
|
1552
|
-
},
|
1553
|
-
)
|
1554
|
-
end
|
1555
|
-
|
1556
|
-
it "404s" do
|
1557
|
-
assert_raises(GdsApi::HTTPNotFound) do
|
1558
|
-
@api_client.get_linked_items(
|
1559
|
-
@content_id,
|
1560
|
-
link_type: "topic",
|
1561
|
-
fields: %w(content_id base_path),
|
1562
|
-
)
|
1563
|
-
end
|
1564
|
-
end
|
1565
|
-
end
|
1566
|
-
|
1567
|
-
describe "there are two documents that link to the wanted document" do
|
1568
|
-
before do
|
1569
|
-
content_id2 = "08dfd5c3-d935-4e81-88fd-cfe65b78893d"
|
1570
|
-
content_id3 = "e2961462-bc37-48e9-bb98-c981ef1a2d59"
|
1571
|
-
|
1572
|
-
@linked_content_item = content_item_for_content_id("6cb2cf8c-670f-4de3-97d5-6ad9114581c7")
|
1573
|
-
@linking_content_item1 = content_item_for_content_id(content_id3,
|
1574
|
-
"base_path" => "/item-b",
|
1575
|
-
"links" => {
|
1576
|
-
"topic" => [@linked_content_item['content_id1']]
|
1577
|
-
})
|
1578
|
-
@linking_content_item2 = content_item_for_content_id(content_id2,
|
1579
|
-
"base_path" => "/item-a",
|
1580
|
-
"links" => {
|
1581
|
-
"topic" => [@linked_content_item['content_id1']],
|
1582
|
-
})
|
1583
|
-
|
1584
|
-
publishing_api
|
1585
|
-
.given("there are two documents with a 'topic' link to another document")
|
1586
|
-
.upon_receiving("a get linked request")
|
1587
|
-
.with(
|
1588
|
-
method: :get,
|
1589
|
-
path: "/v2/linked/" + @linked_content_item['content_id'],
|
1590
|
-
query: "fields%5B%5D=content_id&fields%5B%5D=base_path&link_type=topic",
|
1591
|
-
headers: GdsApi::JsonClient.default_request_headers.merge(
|
1592
|
-
"Authorization" => "Bearer #{@bearer_token}"
|
1593
|
-
),
|
1594
|
-
)
|
1595
|
-
.will_respond_with(
|
1596
|
-
status: 200,
|
1597
|
-
body: [
|
1598
|
-
{
|
1599
|
-
content_id: @linking_content_item1["content_id"],
|
1600
|
-
base_path: @linking_content_item1["base_path"]
|
1601
|
-
},
|
1602
|
-
{
|
1603
|
-
content_id: @linking_content_item2["content_id"],
|
1604
|
-
base_path: @linking_content_item2["base_path"]
|
1605
|
-
}
|
1606
|
-
]
|
1607
|
-
)
|
1608
|
-
end
|
1609
|
-
|
1610
|
-
it "returns the requested fields of linking items" do
|
1611
|
-
response = @api_client.get_linked_items(
|
1612
|
-
@linked_content_item["content_id"],
|
1613
|
-
link_type: "topic",
|
1614
|
-
fields: %w(content_id base_path)
|
1615
|
-
)
|
1616
|
-
assert_equal 200, response.code
|
1617
|
-
|
1618
|
-
expected_documents = [
|
1619
|
-
{ "content_id" => @linking_content_item2["content_id"], "base_path" => "/item-a" },
|
1620
|
-
{ "content_id" => @linking_content_item1["content_id"], "base_path" => "/item-b" },
|
1621
|
-
]
|
1622
|
-
|
1623
|
-
expected_documents.each do |document|
|
1624
|
-
response.to_a.must_include document
|
1625
|
-
end
|
1626
|
-
end
|
1627
|
-
end
|
1628
|
-
end
|
1629
|
-
|
1630
|
-
describe "content ID validation" do
|
1631
|
-
[:get_content, :get_links, :get_linked_items, :discard_draft].each do |method|
|
1632
|
-
it "happens on #{method}" do
|
1633
|
-
proc { @api_client.send(method, nil) }.must_raise ArgumentError
|
1634
|
-
end
|
1635
|
-
end
|
1636
|
-
|
1637
|
-
it "happens on publish" do
|
1638
|
-
proc { @api_client.publish(nil, "major") }.must_raise ArgumentError
|
1639
|
-
end
|
1640
|
-
|
1641
|
-
it "happens on put_content" do
|
1642
|
-
proc { @api_client.put_content(nil, {}) }.must_raise ArgumentError
|
1643
|
-
end
|
1644
|
-
|
1645
|
-
it "happens on patch_links" do
|
1646
|
-
proc { @api_client.patch_links(nil, links: {}) }.must_raise ArgumentError
|
1647
|
-
end
|
1648
|
-
end
|
1649
|
-
end
|