-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworkflow_spec.rb
More file actions
865 lines (689 loc) · 28.7 KB
/
workflow_spec.rb
File metadata and controls
865 lines (689 loc) · 28.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
RSpec.describe "Workflow", type: :request do
include Rails.application.routes.url_helpers
def self.it_shows_the_correct_context
it "shows the correct context" do
get workflow_path(id: edition.id, step:)
expect(page).to have_selector(".govuk-caption-xl", text: edition.title)
end
end
let(:details) do
{
foo: "Foo text",
bar: "Bar text",
}
end
let(:organisation) { build(:organisation) }
let(:document) { create(:document, :pension, content_id: @content_id, sluggable_string: "some-slug") }
let(:edition) { create(:edition, document:, details:, lead_organisation_id: organisation.id, instructions_to_publishers: "instructions", title: "Some Edition Title") }
let!(:schema) { stub_request_for_schema("pension") }
let(:subschema_relationship_type_predicate) do
double("relationship type predicate", one_to_one?: false)
end
before do
login_as_admin
@content_id = "49453854-d8fd-41da-ad4c-f99dbac601c3"
stub_publishing_api_has_embedded_content(content_id: @content_id, total: 0, results: [], order: HostContentItem::DEFAULT_ORDER)
allow(Organisation).to receive(:all).and_return([organisation])
allow(Version).to receive(:increment_for_edition)
allow(DomainEvent).to receive(:record)
end
describe "when creating a new content block" do
before do
allow_any_instance_of(Document).to receive(:is_new_block?).and_return(true)
end
describe "when on the edit step" do
let(:step) { :edit_draft }
describe "#show" do
it_shows_the_correct_context
end
end
describe "when reviewing the changes" do
let(:step) { :review }
describe "#show" do
it_shows_the_correct_context
it "shows the new edition for review" do
get workflow_path(id: edition.id, step:)
expect(response).to render_template("editions/workflow/review")
expect(assigns(:edition)).to eq(edition)
end
it "shows the correct context and confirmation text" do
get workflow_path(id: edition.id, step:)
expect(page).to have_content(document.title)
expect(page).to have_content I18n.t("edition.review.confirm")
end
context "when the edition has a subschema in a 1:1 relationship" do
let(:embedded_object_details) do
{
"start" => "2025-04-06T00:00:00+01:00",
"end" => "2026-04-05T23:52:00+01:00",
}
end
let(:edition) do
create(
:edition,
:time_period,
lead_organisation_id: organisation.id,
details: { "date_range" => embedded_object_details },
)
end
before do
allow(Schema).to receive(:find_by_block_type).and_call_original
end
it "displays the subschema in a single summary card" do
get workflow_path(id: edition.id, step: :review)
expect(page).to have_css(".gem-c-summary-card[data-testid='review_sole_embedded_date_range']")
end
end
end
describe "#update" do
it "posts the new edition to the Publishing API and marks edition as published" do
assert_edition_is_published do
put workflow_path(id: edition.id, step:, has_checked_content: true, save_action: "publish")
end
end
it "transitions the edition's state to 'draft_complete'" do
service = double("PublishEditionService", call: double("Edition", id: 123))
allow(PublishEditionService).to receive(:new).and_return(service)
put workflow_path(id: edition.id, step:, has_checked_content: true, save_action: "publish")
expect(edition.reload.state).to eq("draft_complete")
end
end
end
describe "when the edition details have not been checked and the workflow can't complete" do
let(:step) { :review }
describe "#update" do
it "returns to the review page" do
put workflow_path(id: edition.id, step:)
expect(response).to render_template("editions/workflow/review")
end
it "does NOT cause the state transition to 'draft_complete'" do
put workflow_path(id: edition.id, step:)
expect(edition.reload.state).to eq("draft")
end
end
end
describe "when subschemas are present" do
let(:subschemas) do
[
double("subschema_1",
id: "subschema_1",
name: "subschema_1",
block_type: "subschema_1",
relationship_type: subschema_relationship_type_predicate,
block_display_fields: [],
fields: [build(:field, name: "name", data_attributes: nil)],
group: nil),
double("subschema_2",
id: "subschema_2",
name: "subschema_2",
block_type: "subschema_1",
relationship_type: subschema_relationship_type_predicate,
fields: [],
group: nil),
]
end
let!(:schema) { stub_request_for_schema("pension", subschemas:) }
describe "#show" do
let(:step) { "embedded_subschema_1" }
it_shows_the_correct_context
it "shows the form for the first subschema" do
get workflow_path(id: edition.id, step: "embedded_subschema_1")
expect(response).to render_template("editions/workflow/embedded_objects")
end
it "shows the form for the second subschema" do
get workflow_path(id: edition.id, step: "embedded_subschema_2")
expect(response).to render_template("editions/workflow/embedded_objects")
end
describe "when there are existing subschema blocks created already" do
let(:details) { { subschema_1: { existing_subschema: { name: "existing subschema" } } } }
let(:edition) { create(:edition, document:, details:, lead_organisation_id: organisation.id, instructions_to_publishers: "instructions", title: "Some Edition Title") }
it "shows the existing block and how to add another embedded block" do
get workflow_path(id: edition.id, step: "embedded_subschema_1")
expect(page).to have_content("existing subschema")
expect(page).to have_content("Add another subschema 1")
end
end
context "when a 'one-to-one' subschema exists" do
let(:subschemas) do
[
double("one_to_one_subschema",
id: "one_to_one_subschema",
name: "one_to_one_subschema",
block_type: "one_to_one_subschema",
relationship_type: subschema_relationship_type_predicate,
fields: [],
group: nil),
]
end
before do
allow(subschema_relationship_type_predicate).to receive(:one_to_one?).and_return(true)
end
context "when the sole embedded object does not yet exist" do
let(:details) do
{ "title" => "Edition title" }
end
it "renders the 'new' view to create the sole embedded object" do
get workflow_path(id: edition.id, step: "embedded_one_to_one_subschema")
expect(response).to redirect_to(new_sole_embedded_object_edition_path(edition, :one_to_one_subschema))
end
end
context "when the sole embedded object already exists" do
let(:details) do
{ "title" => "Edition title",
"one_to_one_subschema" => { name: "existing item" } }
end
it "renders the 'edit' view to edit the existing sole embedded object" do
get workflow_path(id: edition.id, step: "embedded_one_to_one_subschema")
expect(response).to redirect_to(edit_sole_embedded_object_edition_path(edition, :one_to_one_subschema))
end
end
end
end
describe "#update" do
it "redirects to the second subschema" do
put workflow_path(id: edition.id, step: "embedded_subschema_1")
expect(response).to redirect_to(workflow_path(id: edition.id, step: :embedded_subschema_2))
end
it "redirects to the review page" do
put workflow_path(id: edition.id, step: "embedded_subschema_2")
expect(response).to redirect_to(workflow_path(id: edition.id, step: :review))
end
end
end
end
describe "when updating an existing content block" do
before do
allow_any_instance_of(Document).to receive(:is_new_block?).and_return(false)
end
describe "when editing an existing edition" do
let(:step) { :edit_draft }
describe "#show" do
it_shows_the_correct_context
it "shows the form" do
get workflow_path(id: edition.id, step:)
expect(response).to render_template("editions/workflow/edit_draft")
end
end
describe "#update" do
it "updates the block and redirects to the next flow if editing an existing block" do
allow_any_instance_of(Document).to receive(:is_new_block?).and_return(false)
put workflow_path(id: edition.id, step:),
params: {
"edition" => {
"title" => "New title",
"lead_organisation_id" => organisation.id,
"details" => {
"foo" => "bar",
},
},
}
expect(response).to redirect_to(workflow_path(id: edition.id, step: :review_links))
expect(edition.reload.title).to eq("New title")
expect(edition.reload.details["foo"]).to eq("bar")
expect(edition.reload.details["bar"]).to eq("Bar text")
end
it "updates the block with nil if a details field is blank" do
put workflow_path(id: edition.id, step:),
params: {
"edition" => {
"title" => "New title",
"lead_organisation_id" => organisation.id,
"details" => {
"foo" => "",
},
},
}
expect(edition.reload.details["foo"]).to be_nil
end
it "updates the block and redirects to the review page if editing a new block" do
allow_any_instance_of(Document).to receive(:is_new_block?).and_return(true)
put workflow_path(id: edition.id, step:),
params: {
"edition" => {
"title" => "New title",
"lead_organisation_id" => organisation.id,
"details" => {
"foo" => "bar",
},
},
}
expect(response).to redirect_to(workflow_path(id: edition.id, step: :review))
expect(edition.reload.title).to eq("New title")
expect(edition.reload.details["foo"]).to eq("bar")
expect(edition.reload.details["bar"]).to eq("Bar text")
end
it "shows an error if a required field is blank" do
put workflow_path(id: edition.id, step:),
params: {
"edition" => {
"title" => "",
"details" => {
"foo" => "bar",
},
},
}
expect(response).to render_template("editions/workflow/edit_draft")
expect(page).to have_text(I18n.t("activerecord.errors.models.edition.blank", attribute_with_indefinite_article: "a title"))
end
end
end
describe "when cancelling the current draft" do
it "offers a 'Delete draft' button using the DELETE method" do
get workflow_path(id: edition.id, step: :cancel)
expect(response).to render_template("editions/workflow/cancel")
form_submission_path = "/editions/#{edition.id}?redirect_path=%2F#{edition.document.id}"
expect(page).to have_css("form[action='#{form_submission_path}']") do |form|
expect(form).to have_css("input[name='_method'][value='delete']", visible: false)
expect(form).to have_button("Delete draft")
end
end
end
describe "when reviewing the links" do
let(:step) { :review_links }
describe "#show" do
describe "when there is embedded content" do
let(:host_content_items) do
10.times.map do |i|
{
"title" => "Content #{i}",
"document_type" => "document",
"base_path" => "/",
"content_id" => SecureRandom.uuid,
"last_edited_by_editor_id" => SecureRandom.uuid,
"last_edited_at" => 2.days.ago.to_s,
"host_content_id" => "abc12345",
"primary_publishing_organisation" => {
"content_id" => SecureRandom.uuid,
"title" => "Organisation #{i}",
"base_path" => "/organisation/#{i}",
},
"state" => "draft",
"publishing_app" => "publisher",
}
end
end
let(:host_content_item_users) { build_list(:signon_user, 10) }
before do
stub_publishing_api_has_embedded_content_for_any_content_id(
results: host_content_items,
total: host_content_items.length,
order: HostContentItem::DEFAULT_ORDER,
)
allow(SignonUser).to receive(:with_uuids).with(host_content_items.map { |i| i["last_edited_by_editor_id"] }).and_return(host_content_item_users)
end
it_shows_the_correct_context
end
describe "when there is no embedded content" do
before do
stub_publishing_api_has_embedded_content_for_any_content_id(
results: [],
total: 0,
order: HostContentItem::DEFAULT_ORDER,
)
end
it "redirects to the next step" do
get workflow_path(id: edition.id, step:)
expect(response).to redirect_to(workflow_path(id: edition.id, step: :internal_note))
end
describe "when the request comes from the next step" do
it "redirects to the previous step" do
get workflow_path(id: edition.id, step:),
headers: { "HTTP_REFERER" => "http://example.com#{workflow_path(id: edition.id, step: :internal_note)}" }
expect(response).to redirect_to(workflow_path(id: edition.id, step: :edit_draft))
end
end
end
end
describe "#update" do
it "redirects to the next step" do
put workflow_path(id: edition.id, step:)
expect(request).to redirect_to(workflow_path(id: edition.id, step: :internal_note))
end
end
end
describe "when updating the internal note" do
let(:step) { :internal_note }
describe "#show" do
it_shows_the_correct_context
it "shows the form" do
get workflow_path(id: edition.id, step:)
expect(response).to render_template("editions/workflow/internal_note")
end
it "should enable the unsaved-changes-prompt JS module" do
get workflow_path(id: edition.id, step:)
doc = Nokogiri::HTML(response.body)
expect(doc.css("form[data-module~='unsaved-changes-prompt']")).to be_present
end
end
describe "#update" do
it "adds the note and redirects" do
change_note = "This is my note"
put workflow_path(id: edition.id, step:),
params: {
"edition" => {
"internal_change_note" => change_note,
},
}
expect(response).to redirect_to(workflow_path(id: edition.id, step: :change_note))
expect(edition.reload.internal_change_note).to eq(change_note)
end
end
end
describe "when updating the change note" do
let(:step) { :change_note }
describe "#show" do
it_shows_the_correct_context
it "shows the form" do
get workflow_path(id: edition.id, step:)
expect(response).to render_template("editions/workflow/change_note")
end
it "should enable the unsaved-changes-prompt JS module" do
get workflow_path(id: edition.id, step:)
doc = Nokogiri::HTML(response.body)
expect(doc.css("form[data-module~='unsaved-changes-prompt']")).to be_present
end
end
describe "#update" do
it "adds the note and redirects" do
change_note = "This is my note"
put workflow_path(id: edition.id, step:),
params: {
"edition" => {
"major_change" => "1",
"change_note" => change_note,
},
}
expect(edition.reload.change_note).to eq(change_note)
expect(edition.reload.major_change).to be_truthy
expect(response).to redirect_to(workflow_path(id: edition.id, step: :schedule_publishing))
end
it "shows an error if the change is major and the change note is blank" do
put workflow_path(id: edition.id, step:),
params: {
"edition" => {
"major_change" => "1",
"change_note" => "",
},
}
expect(page).to have_text(I18n.t("activerecord.errors.models.edition.attributes.change_note.blank"))
end
it "shows an error if major_change is blank" do
put workflow_path(id: edition.id, step:),
params: {
"edition" => {
"major_change" => "",
"change_note" => "",
},
}
expect(page).to have_text(I18n.t("activerecord.errors.models.edition.attributes.major_change.inclusion"))
end
end
describe "when subschemas are present" do
let(:subschemas) do
[
double("subschema",
id: "subschema_1",
name: "subschema_1",
block_type: "subschema_1",
relationship_type: subschema_relationship_type_predicate,
group: nil),
double("subschema",
id: "subschema_2",
name: "subschema_2",
block_type: "subschema_2",
relationship_type: subschema_relationship_type_predicate,
group: nil),
]
end
let!(:schema) { stub_request_for_schema("pension", subschemas:) }
before do
allow_any_instance_of(Edition).to receive(:has_entries_for_subschema_id?).and_return(true)
end
describe "#show" do
let(:step) { "embedded_subschema_1" }
it "shows the form for the first subschema" do
get workflow_path(id: edition.id, step: "embedded_subschema_1")
expect(response).to render_template("editions/workflow/embedded_objects")
end
it "shows the form for the second subschema" do
get workflow_path(id: edition.id, step: "embedded_subschema_2")
expect(response).to render_template("editions/workflow/embedded_objects")
end
end
describe "#update" do
it "redirects to the second subschema" do
put workflow_path(id: edition.id, step: "embedded_subschema_1")
expect(response).to redirect_to(workflow_path(id: edition.id, step: :embedded_subschema_2))
end
it "redirects to review links" do
put workflow_path(id: edition.id, step: "embedded_subschema_2")
expect(response).to redirect_to(workflow_path(id: edition.id, step: :review_links))
end
end
end
describe "when subschemas are present" do
let(:group) { nil }
let(:subschemas) do
[
double("subschema",
id: "subschema_1",
name: "subschema_1",
block_type: "subschema_1",
relationship_type: subschema_relationship_type_predicate,
group:,
group_order: 0,
fields: []),
double("subschema",
id: "subschema_2",
name: "subschema_2",
block_type: "subschema_2",
relationship_type: subschema_relationship_type_predicate,
group:,
group_order: 1, fields: []),
]
end
let!(:schema) { stub_request_for_schema("pension", subschemas:) }
before do
allow_any_instance_of(Edition).to receive(:has_entries_for_subschema_id?).and_return(true)
end
describe "#show" do
let(:step) { "embedded_subschema_1" }
it "shows the form for the first subschema" do
get workflow_path(id: edition.id, step: "embedded_subschema_1")
expect(response).to render_template("editions/workflow/embedded_objects")
end
it "shows the form for the second subschema" do
get workflow_path(id: edition.id, step: "embedded_subschema_2")
expect(response).to render_template("editions/workflow/embedded_objects")
end
end
describe "#update" do
it "redirects to the second subschema" do
put workflow_path(id: edition.id, step: "embedded_subschema_1")
expect(response).to redirect_to(workflow_path(id: edition.id, step: :embedded_subschema_2))
end
it "redirects to review links" do
put workflow_path(id: edition.id, step: "embedded_subschema_2")
expect(response).to redirect_to(workflow_path(id: edition.id, step: :review_links))
end
end
describe "when the subschemas are in a group" do
let(:group) { "some_group" }
before do
allow(schema).to receive(:subschemas_for_group).with(group).and_return(subschemas)
end
describe "#show" do
describe "when content exists for at least some of the subschemas" do
let(:details) do
{
subschemas[0].block_type.to_s => {
"item" => {
"key" => "value",
},
},
}
end
it "shows the form for the group" do
get workflow_path(id: edition.id, step: "group_some_group")
expect(response).to render_template("editions/workflow/group_objects")
end
end
describe "when content does not exist for any of the subschemas" do
it "renders the select subschema group" do
get workflow_path(id: edition.id, step: "group_some_group")
expect(response).to render_template("shared/embedded_objects/select_subschema")
end
end
end
describe "#update" do
it "redirects to review links" do
put workflow_path(id: edition.id, step: "group_some_group")
expect(response).to redirect_to(workflow_path(id: edition.id, step: :review_links))
end
end
end
end
end
describe "when scheduling or publishing" do
let(:step) { :schedule_publishing }
describe "#show" do
it_shows_the_correct_context
it "shows the form" do
get workflow_path(id: edition.id, step:)
expect(response).to render_template("editions/workflow/schedule_publishing")
expect(assigns(:document)).to eq(document)
end
it "should enable the unsaved-changes-prompt JS module" do
get workflow_path(id: edition.id, step:)
doc = Nokogiri::HTML(response.body)
expect(doc.css("form[data-module~='unsaved-changes-prompt']")).to be_present
end
end
describe "#update" do
describe "when choosing to publish immediately" do
it "redirects to the review step" do
scheduled_at = {
"scheduled_publication(1i)": "",
"scheduled_publication(2i)": "",
"scheduled_publication(3i)": "",
"scheduled_publication(4i)": "",
"scheduled_publication(5i)": "",
}
put workflow_path(id: edition.id, step:),
params: {
schedule_publishing: "now",
scheduled_at:,
}
expect(response).to redirect_to(workflow_path(id: edition.id, step: :review))
end
end
describe "when scheduling publication" do
it "redirects to the internal note page" do
date = Time.zone.now + 1.day
scheduled_at = {
"scheduled_publication(1i)": date.year.to_s,
"scheduled_publication(2i)": date.month.to_s,
"scheduled_publication(3i)": date.day.to_s,
"scheduled_publication(4i)": date.hour.to_s,
"scheduled_publication(5i)": date.min.to_s,
}
put workflow_path(id: edition.id, step:), params: {
schedule_publishing: "schedule",
scheduled_at:,
}
expect(response).to redirect_to(workflow_path(id: edition.id, step: :review))
end
end
describe "when leaving the schedule_publishing param blank" do
it "shows an error message" do
put workflow_path(id: edition.id, step:)
expect(response).to render_template("editions/workflow/schedule_publishing")
expect(page).to have_text(I18n.t("activerecord.errors.models.edition.attributes.schedule_publishing.blank"))
end
end
end
end
describe "when on the review step" do
let(:step) { :review }
it_shows_the_correct_context
it "shows the correct context and confirmation text" do
get workflow_path(id: edition.id, step:)
expect(page).to have_text(document.title)
expect(page).to have_text I18n.t("edition.review.confirm")
end
context "when pre_release_features are enabled" do
before do
allow_any_instance_of(ApplicationHelper).to receive(:pre_release_features?).and_return(true)
end
it "does not show the confirmation text" do
get workflow_path(id: edition.id, step:)
expect(page).to_not have_text I18n.t("edition.review.confirm")
end
end
end
end
describe "when an unknown step is provided" do
describe "#show" do
it "returns a 404" do
get workflow_path(id: edition.id, step: "some_random_step")
expect(response.code).to eq("404")
end
end
describe "#update" do
it "returns a 404" do
put workflow_path(id: edition.id, step: "some_random_step")
expect(response.code).to eq("404")
end
end
end
describe "when an unknown subschema step is provided" do
describe "#show" do
it "returns a 404" do
get workflow_path(id: edition.id, step: "embedded_something")
expect(response.code).to eq("404")
end
end
end
describe "when an unknown group step is provided" do
describe "#show" do
it "returns a 404" do
get workflow_path(id: edition.id, step: "group_something")
expect(response.code).to eq("404")
end
end
end
end
def assert_edition_is_published(&block)
fake_put_content_response = GdsApi::Response.new(
double("http_response", code: 200, body: {}),
)
fake_publish_content_response = GdsApi::Response.new(
double("http_response", code: 200, body: {}),
)
payload = PublishingApi::ContentBlockPresenter.new(document_type: "content_block_type", content_id_alias: "some-slug", edition: edition).present
expect(Public::Services.publishing_api).to receive(:put_content).with(@content_id, payload).and_return(fake_put_content_response)
expect(Public::Services.publishing_api).to receive(:publish).with(@content_id).and_return(fake_publish_content_response)
block.call
document = Document.find_by!(content_id: @content_id)
new_edition = document.most_recent_edition
expect(new_edition.state).to eq("published")
end
def update_params(edition_id:, organisation_id:)
{
id: edition_id,
schedule_publishing: "schedule",
scheduled_at: {
"scheduled_publication(3i)": "2",
"scheduled_publication(2i)": "9",
"scheduled_publication(1i)": "2024",
"scheduled_publication(4i)": "10",
"scheduled_publication(5i)": "05",
},
"edition": {
creator: "1",
details: { foo: "newnew@example.com", bar: "edited" },
document_attributes: { block_type: "pension", title: "Another email" },
organisation_id:,
},
}
end