Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Commit b551aa0

Browse files
authored
Merge pull request #768 from alphagov/update-set-submission-type-tasks
Synchronise form documents for update submission type tasks
2 parents 98e2286 + 3f2b178 commit b551aa0

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

lib/tasks/forms.rake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ namespace :forms do
5252

5353
made_live_form.update!(json_form_blob: form_blob.to_json)
5454
end
55+
56+
Api::V2::FormDocumentSyncService.new.synchronize_form(form)
57+
5558
Rails.logger.info("set submission_type to s3 and s3_bucket_name to #{args[:s3_bucket_name]} for form: #{args[:form_id]}")
5659
end
5760

@@ -118,5 +121,7 @@ def set_submission_type(submission_type, form_id)
118121
made_live_form.update!(json_form_blob: form_blob.to_json)
119122
end
120123

124+
Api::V2::FormDocumentSyncService.new.synchronize_form(form)
125+
121126
Rails.logger.info("set submission_type to #{submission_type} for form: #{form_id}")
122127
end

spec/lib/tasks/forms.rake_spec.rb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@
5858
expect(JSON.parse(form.made_live_forms.last.json_form_blob)["submission_type"]).to eq("email_with_csv")
5959
end
6060

61+
it "synchronises the FormDocument" do
62+
task.invoke(form.id)
63+
form_documents = Api::V2::Form.find(form.id).form_documents
64+
expect(form_documents.size).to eq(1)
65+
expect(form_documents.first["content"]["submission_type"]).to eq("email_with_csv")
66+
end
67+
6168
it "does not update a different form" do
6269
expect { task.invoke(form.id) }
6370
.not_to(change { other_form.reload.submission_type })
@@ -74,6 +81,13 @@
7481
expect { task.invoke(form.id) }
7582
.to change { form.reload.submission_type }.to("email_with_csv")
7683
end
84+
85+
it "synchronises the FormDocument" do
86+
task.invoke(form.id)
87+
form_documents = Api::V2::Form.find(form.id).form_documents
88+
expect(form_documents.size).to eq(1)
89+
expect(form_documents.first["content"]["submission_type"]).to eq("email_with_csv")
90+
end
7791
end
7892

7993
context "when the form is archived" do
@@ -91,6 +105,14 @@
91105
task.invoke(form.id)
92106
expect(JSON.parse(form.made_live_forms.last.json_form_blob)["submission_type"]).to eq("email")
93107
end
108+
109+
it "synchronises the archived and draft FormDocuments" do
110+
task.invoke(form.id)
111+
form_documents = Api::V2::Form.find(form.id).form_documents
112+
expect(form_documents.size).to eq(2)
113+
expect(form_documents.first["content"]["submission_type"]).to eq("email_with_csv")
114+
expect(form_documents.second["content"]["submission_type"]).to eq("email_with_csv")
115+
end
94116
end
95117
end
96118

@@ -141,6 +163,14 @@
141163
expect(JSON.parse(form.made_live_forms.last.json_form_blob)["s3_bucket_name"]).to eq(s3_bucket_name)
142164
end
143165

166+
it "synchronises the FormDocument" do
167+
task.invoke(form.id, s3_bucket_name, s3_bucket_aws_account_id, s3_bucket_region)
168+
form_documents = Api::V2::Form.find(form.id).form_documents
169+
expect(form_documents.size).to eq(1)
170+
expect(form_documents.first["content"]["submission_type"]).to eq("s3")
171+
expect(form_documents.first["content"]["s3_bucket_name"]).to eq(s3_bucket_name)
172+
end
173+
144174
it "does not update a different form" do
145175
expect { task.invoke(form.id, s3_bucket_name, s3_bucket_aws_account_id, s3_bucket_region) }
146176
.not_to(change { other_form.reload.submission_type })
@@ -167,6 +197,14 @@
167197
expect { task.invoke(form.id, s3_bucket_name, s3_bucket_aws_account_id, s3_bucket_region) }
168198
.to change { form.reload.s3_bucket_aws_account_id }.to(s3_bucket_aws_account_id)
169199
end
200+
201+
it "synchronises the FormDocument" do
202+
task.invoke(form.id, s3_bucket_name, s3_bucket_aws_account_id, s3_bucket_region)
203+
form_documents = Api::V2::Form.find(form.id).form_documents
204+
expect(form_documents.size).to eq(1)
205+
expect(form_documents.first["content"]["submission_type"]).to eq("s3")
206+
expect(form_documents.first["content"]["s3_bucket_name"]).to eq(s3_bucket_name)
207+
end
170208
end
171209

172210
context "when the form is archived" do
@@ -184,6 +222,16 @@
184222
task.invoke(form.id, s3_bucket_name, s3_bucket_aws_account_id, s3_bucket_region)
185223
expect(JSON.parse(form.made_live_forms.last.json_form_blob)["submission_type"]).to eq("email")
186224
end
225+
226+
it "synchronises the archived and draft FormDocuments" do
227+
task.invoke(form.id, s3_bucket_name, s3_bucket_aws_account_id, s3_bucket_region)
228+
form_documents = Api::V2::Form.find(form.id).form_documents
229+
expect(form_documents.size).to eq(2)
230+
expect(form_documents.first["content"]["submission_type"]).to eq("s3")
231+
expect(form_documents.first["content"]["s3_bucket_name"]).to eq(s3_bucket_name)
232+
expect(form_documents.second["content"]["submission_type"]).to eq("s3")
233+
expect(form_documents.second["content"]["s3_bucket_name"]).to eq(s3_bucket_name)
234+
end
187235
end
188236

189237
context "without arguments" do
@@ -264,6 +312,13 @@
264312
expect(JSON.parse(form.made_live_forms.last.json_form_blob)["submission_type"]).to eq("email")
265313
end
266314

315+
it "synchronises the FormDocument" do
316+
task.invoke(form.id)
317+
form_documents = Api::V2::Form.find(form.id).form_documents
318+
expect(form_documents.size).to eq(1)
319+
expect(form_documents.first["content"]["submission_type"]).to eq("email")
320+
end
321+
267322
it "does not update a different form" do
268323
expect { task.invoke(form.id) }
269324
.not_to(change { other_form.reload.submission_type })
@@ -297,6 +352,14 @@
297352
task.invoke(form.id)
298353
expect(JSON.parse(form.made_live_forms.last.json_form_blob)["submission_type"]).to eq("s3")
299354
end
355+
356+
it "synchronises the archived and draft FormDocuments" do
357+
task.invoke(form.id)
358+
form_documents = Api::V2::Form.find(form.id).form_documents
359+
expect(form_documents.size).to eq(2)
360+
expect(form_documents.first["content"]["submission_type"]).to eq("email")
361+
expect(form_documents.second["content"]["submission_type"]).to eq("email")
362+
end
300363
end
301364
end
302365

0 commit comments

Comments
 (0)