|
190 | 190 | }.to change(Submission, :count).by(1) |
191 | 191 | .and change(Delivery, :count).by(1) |
192 | 192 |
|
193 | | - expect(Submission.last).to have_attributes(reference:, form_id: form.id, answers: answers.deep_stringify_keys, |
194 | | - mode: "form", form_document: document_json, |
| 193 | + expect(Submission.last).to have_attributes(reference:, |
| 194 | + form_id: form.id, |
| 195 | + answers: answers.deep_stringify_keys, |
| 196 | + mode: "form", |
| 197 | + form_document: document_json, |
| 198 | + welsh_form_document: nil, |
195 | 199 | submission_locale: "en") |
196 | 200 | end |
197 | 201 |
|
|
283 | 287 | end |
284 | 288 | end |
285 | 289 |
|
| 290 | + context "when Welsh has been used to complete the form" do |
| 291 | + let(:locales_used) { %i[en cy] } |
| 292 | + |
| 293 | + before do |
| 294 | + ActiveResource::HttpMock.respond_to do |mock| |
| 295 | + mock.get "/api/v2/forms/1/live?language=cy", {}, welsh_form_document.to_json, 200 |
| 296 | + end |
| 297 | + end |
| 298 | + |
| 299 | + it "fetches the Welsh form" do |
| 300 | + service.submit |
| 301 | + expect(ActiveResource::HttpMock.requests).to include ActiveResource::Request.new(:get, "/api/v2/forms/1/live?language=cy") |
| 302 | + end |
| 303 | + |
| 304 | + it "saves the submission data including the Welsh version of the form" do |
| 305 | + expect { |
| 306 | + service.submit |
| 307 | + }.to change(Submission, :count).by(1) |
| 308 | + |
| 309 | + expect(Submission.last.form_document["language"]).to eq("en") |
| 310 | + expect(Submission.last.form_document["name"]).to eq("Form 1") |
| 311 | + expect(Submission.last.welsh_form_document["language"]).to eq("cy") |
| 312 | + expect(Submission.last.welsh_form_document["name"]).to eq("Welsh Form 1") |
| 313 | + end |
| 314 | + end |
| 315 | + |
286 | 316 | context "when form is not in english" do |
287 | 317 | let(:submission_type) { "email" } |
288 | 318 | let(:submission_format) { [] } |
|
305 | 335 | service.submit |
306 | 336 | }.to change(Submission, :count).by(1) |
307 | 337 |
|
308 | | - # expect(Submission.last).to have_attributes(form_id: form.id, answers: answers.deep_stringify_keys, form_document: document_json) |
309 | 338 | expect(Submission.last.form_document["language"]).to eq("en") |
310 | 339 | expect(Submission.last.form_document["name"]).to eq("Form 1") |
311 | 340 | end |
| 341 | + |
| 342 | + context "when Welsh has been used to complete the form" do |
| 343 | + let(:locales_used) { %i[en cy] } |
| 344 | + |
| 345 | + it "saves the original Welsh version of the form on the submission" do |
| 346 | + expect { |
| 347 | + service.submit |
| 348 | + }.to change(Submission, :count).by(1) |
| 349 | + |
| 350 | + expect(Submission.last.welsh_form_document["language"]).to eq("cy") |
| 351 | + expect(Submission.last.welsh_form_document["name"]).to eq("Welsh Form 1") |
| 352 | + end |
| 353 | + end |
312 | 354 | end |
313 | 355 | end |
314 | 356 |
|
|
0 commit comments