|
9 | 9 | expect(form).to be_valid |
10 | 10 | end |
11 | 11 |
|
12 | | - it "has a ready for live trait" do |
13 | | - form = build :form, :ready_for_live, :with_group |
14 | | - expect(form.ready_for_live).to be true |
15 | | - expect(form.incomplete_tasks).to be_empty |
16 | | - expect(form.task_statuses).to include( |
17 | | - declaration_status: :completed, |
18 | | - make_live_status: :not_started, |
19 | | - name_status: :completed, |
20 | | - pages_status: :completed, |
21 | | - privacy_policy_status: :completed, |
22 | | - support_contact_details_status: :completed, |
23 | | - what_happens_next_status: :completed, |
24 | | - ) |
25 | | - end |
26 | | - |
27 | 12 | it "has a live trait" do |
28 | 13 | form = build :form, :live |
29 | 14 | expect(form.state).to eq "live" |
|
50 | 35 | expect(form.pages.map(&:position)).to eq [1, 2, 3, 4, 5] |
51 | 36 | end |
52 | 37 |
|
53 | | - it "has a missing pages trait" do |
54 | | - form = build :form, :missing_pages |
55 | | - expect(form.incomplete_tasks).to eq %i[missing_pages] |
| 38 | + describe "task status traits" do |
| 39 | + before do |
| 40 | + form.set_task_status_service(TaskStatusService.new(form:)) |
| 41 | + end |
| 42 | + |
| 43 | + describe "ready for live trait" do |
| 44 | + let(:form) { build :form, :ready_for_live, :with_group } |
| 45 | + |
| 46 | + it "creates a form that is ready to be made live" do |
| 47 | + expect(form.ready_for_live).to be true |
| 48 | + expect(form.incomplete_tasks).to be_empty |
| 49 | + expect(form.task_statuses).to include( |
| 50 | + declaration_status: :completed, |
| 51 | + make_live_status: :not_started, |
| 52 | + name_status: :completed, |
| 53 | + pages_status: :completed, |
| 54 | + privacy_policy_status: :completed, |
| 55 | + support_contact_details_status: :completed, |
| 56 | + what_happens_next_status: :completed, |
| 57 | + ) |
| 58 | + end |
| 59 | + end |
| 60 | + |
| 61 | + describe "missing pages trait" do |
| 62 | + let(:form) { build :form, :missing_pages } |
| 63 | + |
| 64 | + it "creates a form with missing pages" do |
| 65 | + expect(form.incomplete_tasks).to eq %i[missing_pages] |
| 66 | + end |
| 67 | + end |
56 | 68 | end |
57 | 69 | end |
58 | 70 |
|
|
503 | 515 | end |
504 | 516 |
|
505 | 517 | describe "FormStateMachine" do |
| 518 | + before do |
| 519 | + form.set_task_status_service(TaskStatusService.new(form: form)) |
| 520 | + end |
| 521 | + |
506 | 522 | describe "#make_live!" do |
507 | 523 | let(:form) { create :form, :ready_for_live } |
508 | 524 |
|
|
861 | 877 | end |
862 | 878 |
|
863 | 879 | describe "#ready_for_live" do |
| 880 | + before do |
| 881 | + form.set_task_status_service(TaskStatusService.new(form:)) |
| 882 | + end |
| 883 | + |
864 | 884 | context "when a form is complete and ready to be made live" do |
865 | | - let(:completed_form) { create(:form, :live) } |
| 885 | + let(:form) { create(:form, :live) } |
866 | 886 |
|
867 | 887 | it "returns true" do |
868 | | - expect(completed_form.ready_for_live).to be true |
| 888 | + expect(form.ready_for_live).to be true |
869 | 889 | end |
870 | 890 | end |
871 | 891 |
|
872 | 892 | context "when a form is incomplete and should still be in draft state" do |
873 | | - let(:new_form) { build :form, :new_form } |
| 893 | + let(:form) { build :form, :new_form } |
874 | 894 |
|
875 | 895 | [ |
876 | 896 | { |
|
891 | 911 | }, |
892 | 912 | ].each do |scenario| |
893 | 913 | it "returns false if #{scenario[:attribute]} is missing" do |
894 | | - new_form.send("#{scenario[:attribute]}=", scenario[:attribute_value]) |
895 | | - expect(new_form.ready_for_live).to be false |
| 914 | + form.send("#{scenario[:attribute]}=", scenario[:attribute_value]) |
| 915 | + expect(form.ready_for_live).to be false |
896 | 916 | end |
897 | 917 | end |
898 | 918 | end |
899 | 919 | end |
900 | 920 |
|
901 | 921 | describe "#all_incomplete_tasks" do |
| 922 | + before do |
| 923 | + form.set_task_status_service(TaskStatusService.new(form: form)) |
| 924 | + end |
| 925 | + |
902 | 926 | context "when a form is complete and ready to be made live" do |
903 | | - let(:completed_form) { build :form, :live } |
| 927 | + let(:form) { build :form, :live } |
904 | 928 |
|
905 | 929 | it "returns no missing sections" do |
906 | | - expect(completed_form.all_incomplete_tasks).to be_empty |
| 930 | + expect(form.all_incomplete_tasks).to be_empty |
907 | 931 | end |
908 | 932 | end |
909 | 933 |
|
910 | 934 | context "when a form is incomplete and should still be in draft state" do |
911 | | - let(:new_form) { build :form, :new_form } |
| 935 | + let(:form) { build :form, :new_form } |
912 | 936 |
|
913 | 937 | it "returns a set of keys related to missing fields" do |
914 | | - expect(new_form.all_incomplete_tasks).to match_array(%i[missing_pages missing_submission_email missing_privacy_policy_url missing_contact_details missing_what_happens_next share_preview_not_completed]) |
| 938 | + expect(form.all_incomplete_tasks).to match_array(%i[missing_pages missing_submission_email missing_privacy_policy_url missing_contact_details missing_what_happens_next share_preview_not_completed]) |
915 | 939 | end |
916 | 940 | end |
917 | 941 | end |
|
975 | 999 | task_status_service = instance_double(TaskStatusService) |
976 | 1000 | allow(TaskStatusService).to receive(:new).and_return(task_status_service) |
977 | 1001 | allow(task_status_service).to receive(:mandatory_tasks_completed?).and_return(mandatory_tasks_completed) |
| 1002 | + |
| 1003 | + form.set_task_status_service(task_status_service) |
978 | 1004 | end |
979 | 1005 |
|
980 | 1006 | context "when not all mandatory tasks have been completed" do |
|
998 | 1024 | let(:group) { create :group } |
999 | 1025 | let(:completed_form) { build :form, :live, :with_group, group: } |
1000 | 1026 |
|
| 1027 | + before do |
| 1028 | + completed_form.set_task_status_service(TaskStatusService.new(form: completed_form)) |
| 1029 | + end |
| 1030 | + |
1001 | 1031 | it "returns a hash with each of the task statuses" do |
1002 | 1032 | expected_hash = { |
1003 | 1033 | name_status: :completed, |
|
0 commit comments