|
118 | 118 | end |
119 | 119 | end |
120 | 120 |
|
| 121 | + context "if current_content is not a hash" do |
| 122 | + let(:dynamic_current_content) { "not a hash" } |
| 123 | + |
| 124 | + it "returns an error" do |
| 125 | + post "/api/requests", params: base_payload, as: :json |
| 126 | + |
| 127 | + expect(response).to have_http_status(:bad_request) |
| 128 | + json = JSON.parse(response.body) |
| 129 | + expect(json["errors"]).to include("current_content must be a hash") |
| 130 | + end |
| 131 | + end |
| 132 | + |
| 133 | + context "if previous_content is not a hash" do |
| 134 | + it "returns an error" do |
| 135 | + post "/api/requests", params: valid_payload.merge(previous_content: "not a hash"), as: :json |
| 136 | + |
| 137 | + expect(response).to have_http_status(:bad_request) |
| 138 | + json = JSON.parse(response.body) |
| 139 | + expect(json["errors"]).to include("previous_content must be a hash") |
| 140 | + end |
| 141 | + end |
| 142 | + |
121 | 143 | context "without recipients" do |
122 | 144 | it "returns a 400 error" do |
123 | 145 | payload = valid_payload |
|
158 | 180 | it "returns a 400 error" do |
159 | 181 | post "/api/requests/#{invalid_source_app}/#{invalid_source_id}/resend-emails", as: :json |
160 | 182 |
|
161 | | - expect(response).to have_http_status(:bad_request) |
| 183 | + expect(response).to have_http_status(:not_found) |
162 | 184 | json = JSON.parse(response.body) |
163 | 185 | expect(json["errors"]).to include( |
164 | 186 | "Request with ID #{invalid_source_id} not found for app #{invalid_source_app}", |
|
170 | 192 | it "returns a 400 error" do |
171 | 193 | post "/api/requests/#{existing_request.source_app}/#{invalid_source_id}/resend-emails", as: :json |
172 | 194 |
|
173 | | - expect(response).to have_http_status(:bad_request) |
| 195 | + expect(response).to have_http_status(:not_found) |
174 | 196 | json = JSON.parse(response.body) |
175 | 197 | expect(json["errors"]).to include( |
176 | 198 | "Request with ID #{invalid_source_id} not found for app #{existing_request.source_app}", |
|
182 | 204 | it "returns a 400 error" do |
183 | 205 | post "/api/requests/#{invalid_source_app}/#{existing_request.source_id}/resend-emails", as: :json |
184 | 206 |
|
185 | | - expect(response).to have_http_status(:bad_request) |
| 207 | + expect(response).to have_http_status(:not_found) |
186 | 208 | json = JSON.parse(response.body) |
187 | 209 | expect(json["errors"]).to include( |
188 | 210 | "Request with ID #{existing_request.source_id} not found for app #{invalid_source_app}", |
|
196 | 218 | it "returns a 400 error" do |
197 | 219 | post "/api/requests/#{existing_request_whitehall.source_app}/#{existing_request.source_id}/resend-emails", as: :json |
198 | 220 |
|
199 | | - expect(response).to have_http_status(:bad_request) |
| 221 | + expect(response).to have_http_status(:not_found) |
200 | 222 | json = JSON.parse(response.body) |
201 | 223 | expect(json["errors"]).to include( |
202 | 224 | "Request with ID #{existing_request.source_id} not found for app #{existing_request_whitehall.source_app}", |
|
253 | 275 | it "returns a 400 error" do |
254 | 276 | patch "/api/requests/#{invalid_source_app}/#{invalid_source_id}", params: update_payload, as: :json |
255 | 277 |
|
256 | | - expect(response).to have_http_status(:bad_request) |
| 278 | + expect(response).to have_http_status(:not_found) |
257 | 279 | json = JSON.parse(response.body) |
258 | 280 | expect(json["errors"]).to include( |
259 | 281 | "Request with ID #{invalid_source_id} not found for app #{invalid_source_app}", |
|
265 | 287 | it "returns a 400 error" do |
266 | 288 | patch "/api/requests/#{update_payload[:source_app]}/#{invalid_source_id}", params: update_payload, as: :json |
267 | 289 |
|
268 | | - expect(response).to have_http_status(:bad_request) |
| 290 | + expect(response).to have_http_status(:not_found) |
269 | 291 | json = JSON.parse(response.body) |
270 | 292 | expect(json["errors"]).to include( |
271 | 293 | "Request with ID #{invalid_source_id} not found for app #{update_payload[:source_app]}", |
|
277 | 299 | it "returns a 400 error" do |
278 | 300 | patch "/api/requests/#{invalid_source_app}/#{update_payload[:source_id]}", params: update_payload, as: :json |
279 | 301 |
|
280 | | - expect(response).to have_http_status(:bad_request) |
| 302 | + expect(response).to have_http_status(:not_found) |
281 | 303 | json = JSON.parse(response.body) |
282 | 304 | expect(json["errors"]).to include( |
283 | 305 | "Request with ID #{update_payload[:source_id]} not found for app #{invalid_source_app}", |
|
290 | 312 |
|
291 | 313 | it "returns a 400 error" do |
292 | 314 | patch "/api/requests/#{second_request[:source_app]}/#{update_payload[:source_id]}", params: update_payload, as: :json |
293 | | - expect(response).to have_http_status(:bad_request) |
| 315 | + expect(response).to have_http_status(:not_found) |
294 | 316 | json = JSON.parse(response.body) |
295 | 317 | expect(json["errors"]).to include( |
296 | 318 | "Request with ID #{update_payload[:source_id]} not found for app #{second_request[:source_app]}", |
|
313 | 335 | ) |
314 | 336 | end |
315 | 337 | end |
| 338 | + |
| 339 | + context "if current_content is not a hash" do |
| 340 | + let(:invalid_content_payload) { { source_app: existing_request.source_app, source_id: existing_request.source_id, current_content: "not a hash" } } |
| 341 | + |
| 342 | + it "returns errors for current_content format" do |
| 343 | + patch "/api/requests/#{existing_request.source_app}/#{existing_request.source_id}", params: invalid_content_payload, as: :json |
| 344 | + |
| 345 | + expect(response).to have_http_status(:bad_request) |
| 346 | + |
| 347 | + json = JSON.parse(response.body) |
| 348 | + expect(json["errors"]).to include( |
| 349 | + "current_content must be a hash", |
| 350 | + ) |
| 351 | + end |
| 352 | + end |
316 | 353 | end |
317 | 354 | end |
0 commit comments