From dca6b764f1b350e556a5e537a83faefd73b00602 Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Thu, 5 Dec 2024 09:52:29 +0200 Subject: [PATCH] Use PageRepository in specs where appropriate We want to mock repositories instead of forms-api requests in our specs as much as possible; this will make it easier to change the source of the model data in future. This commit changes specs that were mocking HTTP requests to `/api/v1/forms/:form_id/pages/:page_id` so that they mock the corresponding PageRepository methods instead. --- app/controllers/pages/guidance_controller.rb | 2 +- .../pages/selection/bulk_options_controller.rb | 4 ++-- .../pages/type_of_answer_controller.rb | 2 +- ..._a_question_for_each_type_of_answer_spec.rb | 5 +++-- ...wer_settings_for_existing_questions_spec.rb | 9 +++++---- spec/features/form/share_a_preview_spec.rb | 5 +++-- .../pages/address_settings_controller_spec.rb | 9 ++++++--- .../pages/conditions_controller_spec.rb | 18 ++++++++++++------ .../pages/date_settings_controller_spec.rb | 9 ++++++--- .../requests/pages/guidance_controller_spec.rb | 5 +++-- .../pages/name_settings_controller_spec.rb | 9 ++++++--- spec/requests/pages/routes_controller_spec.rb | 3 ++- .../selection/bulk_options_controller_spec.rb | 7 ++++--- .../pages/selection/options_controller_spec.rb | 10 +++++++--- .../pages/selection/type_controller_spec.rb | 9 ++++++--- .../pages/text_settings_controller_spec.rb | 9 ++++++--- .../pages/type_of_answer_controller_spec.rb | 8 +++++--- 17 files changed, 78 insertions(+), 45 deletions(-) diff --git a/app/controllers/pages/guidance_controller.rb b/app/controllers/pages/guidance_controller.rb index 27b78bc9c..765802bc7 100644 --- a/app/controllers/pages/guidance_controller.rb +++ b/app/controllers/pages/guidance_controller.rb @@ -26,7 +26,7 @@ def create def edit guidance_input = Pages::GuidanceInput.new(page_heading: draft_question.page_heading, guidance_markdown: draft_question.guidance_markdown) - back_link = edit_question_path(current_form, page) + back_link = edit_question_path(current_form, page.id) render :guidance, locals: view_locals(page, guidance_input, back_link) end diff --git a/app/controllers/pages/selection/bulk_options_controller.rb b/app/controllers/pages/selection/bulk_options_controller.rb index e47c9c181..dc1e4acea 100644 --- a/app/controllers/pages/selection/bulk_options_controller.rb +++ b/app/controllers/pages/selection/bulk_options_controller.rb @@ -24,7 +24,7 @@ def edit @bulk_options_path = selection_bulk_options_update_path(current_form) @bulk_options_input = Pages::Selection::BulkOptionsInput.new(draft_question:) @bulk_options_input.assign_form_values - @back_link_url = edit_question_path(current_form, page) + @back_link_url = edit_question_path(current_form, page.id) render "pages/selection/bulk_options", locals: { current_form: } end @@ -32,7 +32,7 @@ def update @bulk_options_input = Pages::Selection::BulkOptionsInput.new(**bulk_options_input_params, draft_question:) @bulk_options_path = selection_bulk_options_update_path(current_form) - @back_link_url = edit_question_path(current_form, page) + @back_link_url = edit_question_path(current_form, page.id) if @bulk_options_input.submit redirect_to edit_question_path(current_form) diff --git a/app/controllers/pages/type_of_answer_controller.rb b/app/controllers/pages/type_of_answer_controller.rb index 67a221544..b8e9db06e 100644 --- a/app/controllers/pages/type_of_answer_controller.rb +++ b/app/controllers/pages/type_of_answer_controller.rb @@ -40,7 +40,7 @@ def update def selection_path(form, action) return question_text_new_path(form) if action == :create - selection_type_edit_path(form, page) + selection_type_edit_path(form, page.id) end def text_path(form, action) diff --git a/spec/features/form/add_or_edit_questions/add_a_question_for_each_type_of_answer_spec.rb b/spec/features/form/add_or_edit_questions/add_a_question_for_each_type_of_answer_spec.rb index 1a60dc6e4..f019c89e8 100644 --- a/spec/features/form/add_or_edit_questions/add_a_question_for_each_type_of_answer_spec.rb +++ b/spec/features/form/add_or_edit_questions/add_a_question_for_each_type_of_answer_spec.rb @@ -9,11 +9,12 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, fake_page.to_json, 200 - mock.post "/api/v1/forms/1/pages", post_headers, fake_page.to_json, 200 mock.put "/api/v1/forms/1", post_headers, form.to_json, 200 end + allow(PageRepository).to receive(:create!).with(hash_including(form_id: 1)).and_return(fake_page) + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(fake_page) + GroupForm.create!(group:, form_id: form.id) create(:membership, group:, user: standard_user, added_by: standard_user) diff --git a/spec/features/form/add_or_edit_questions/edit_answer_settings_for_existing_questions_spec.rb b/spec/features/form/add_or_edit_questions/edit_answer_settings_for_existing_questions_spec.rb index 449148938..fe1e4b31d 100644 --- a/spec/features/form/add_or_edit_questions/edit_answer_settings_for_existing_questions_spec.rb +++ b/spec/features/form/add_or_edit_questions/edit_answer_settings_for_existing_questions_spec.rb @@ -8,12 +8,13 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.post "/api/v1/forms/1/pages", post_headers - pages.each do |page| - mock.get "/api/v1/forms/1/pages/#{page.id}", headers, page.to_json, 200 - end end + pages.each do |page| + allow(PageRepository).to receive(:find).with(page_id: page.id.to_s, form_id: 1).and_return(page) + end + allow(PageRepository).to receive(:create!).with(hash_including(form_id: 1)) + GroupForm.create! group:, form_id: form.id create(:membership, group:, user: standard_user, added_by: standard_user) diff --git a/spec/features/form/share_a_preview_spec.rb b/spec/features/form/share_a_preview_spec.rb index d64f0ea37..673fd53f9 100644 --- a/spec/features/form/share_a_preview_spec.rb +++ b/spec/features/form/share_a_preview_spec.rb @@ -10,11 +10,12 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, fake_page.to_json, 200 - mock.post "/api/v1/forms/1/pages", post_headers, fake_page.to_json, 200 mock.put "/api/v1/forms/1", post_headers, form.to_json, 200 end + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(fake_page) + allow(PageRepository).to receive(:create!).with(hash_including(form_id: 1)) + GroupForm.create!(group:, form_id: form.id) create(:membership, group:, user: standard_user, added_by: standard_user, role: :group_admin) diff --git a/spec/requests/pages/address_settings_controller_spec.rb b/spec/requests/pages/address_settings_controller_spec.rb index 019b4e1d7..e9e1a6ce7 100644 --- a/spec/requests/pages/address_settings_controller_spec.rb +++ b/spec/requests/pages/address_settings_controller_spec.rb @@ -107,8 +107,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, page.to_json, 200 end + + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(page) + draft_question get address_settings_edit_path(form_id: page.form_id, page_id: page.id) end @@ -144,9 +146,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, page.to_json, 200 - mock.put "/api/v1/forms/1/pages/2", post_headers end + + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(page) + allow(PageRepository).to receive(:save!).with(hash_including(page_id: "2", form_id: 1)) end context "when form is valid and ready to update in the DB" do diff --git a/spec/requests/pages/conditions_controller_spec.rb b/spec/requests/pages/conditions_controller_spec.rb index df2d452fa..fc3e0ca18 100644 --- a/spec/requests/pages/conditions_controller_spec.rb +++ b/spec/requests/pages/conditions_controller_spec.rb @@ -100,9 +100,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/1", headers, selected_page.to_json, 200 end + allow(PageRepository).to receive(:find).with(page_id: "1", form_id: 1).and_return(selected_page) + get new_condition_path(form_id: 1, page_id: 1) end @@ -134,9 +135,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/1", headers, selected_page.to_json, 200 end + allow(PageRepository).to receive(:find).with(page_id: "1", form_id: 1).and_return(selected_page) + conditions_input = Pages::ConditionsInput.new(form:, page: selected_page, answer_value: "Yes", goto_page_id: 3) allow(conditions_input).to receive(:submit).and_return(submit_result) @@ -195,9 +197,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/#{selected_page.id}", headers, selected_page.to_json, 200 end + allow(PageRepository).to receive(:find).with(page_id: selected_page.id.to_s, form_id: 1).and_return(selected_page) + allow(ConditionRepository).to receive(:find).and_return(condition) allow(Pages::ConditionsInput).to receive(:new).and_return(conditions_input) @@ -245,9 +248,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/#{selected_page.id}", headers, selected_page.to_json, 200 end + allow(PageRepository).to receive(:find).with(page_id: selected_page.id.to_s, form_id: 1).and_return(selected_page) + conditions_input = Pages::ConditionsInput.new(form:, page: selected_page, record: condition, answer_value: "Yes", goto_page_id: 3) allow(ConditionRepository).to receive(:find).and_return(condition) @@ -309,9 +313,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/#{selected_page.id}", headers, selected_page.to_json, 200 end + allow(PageRepository).to receive(:find).with(page_id: selected_page.id.to_s, form_id: 1).and_return(selected_page) + allow(ConditionRepository).to receive(:find).and_return(condition) delete_condition_input = Pages::DeleteConditionInput.new(form:, page: selected_page, record: condition, answer_value: "Yes", goto_page_id: 3) @@ -355,9 +360,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/#{selected_page.id}", headers, selected_page.to_json, 200 end + allow(PageRepository).to receive(:find).with(page_id: selected_page.id.to_s, form_id: 1).and_return(selected_page) + allow(ConditionRepository).to receive(:find).and_return(condition) allow(ConditionRepository).to receive(:destroy) diff --git a/spec/requests/pages/date_settings_controller_spec.rb b/spec/requests/pages/date_settings_controller_spec.rb index 637e3c394..d05882c55 100644 --- a/spec/requests/pages/date_settings_controller_spec.rb +++ b/spec/requests/pages/date_settings_controller_spec.rb @@ -91,8 +91,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, page.to_json, 200 end + + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(page) + draft_question get date_settings_edit_path(form_id: page.form_id, page_id: page.id) end @@ -127,9 +129,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, page.to_json, 200 - mock.put "/api/v1/forms/1/pages/2", post_headers end + + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(page) + allow(PageRepository).to receive(:save!).with(hash_including(page_id: "2", form_id: 1)) end context "when form is valid and ready to update in the DB" do diff --git a/spec/requests/pages/guidance_controller_spec.rb b/spec/requests/pages/guidance_controller_spec.rb index 43d28fa14..0e020efde 100644 --- a/spec/requests/pages/guidance_controller_spec.rb +++ b/spec/requests/pages/guidance_controller_spec.rb @@ -149,9 +149,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/#{page.id}", headers, page.to_json, 200 end + allow(PageRepository).to receive(:find).with(page_id: page.id.to_s, form_id: 1).and_return(page) + get guidance_edit_path(form_id: form.id, page_id: page.id) end @@ -184,8 +185,8 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/#{page.id}", headers, page.to_json, 200 end + allow(PageRepository).to receive(:find).with(page_id: page.id.to_s, form_id: 1).and_return(page) allow(controller_spy).to receive(:draft_question).and_return(draft_question) post guidance_update_path(form_id: form.id, page_id: page.id), params: { pages_guidance_input: { page_heading:, guidance_markdown: }, route_to: } end diff --git a/spec/requests/pages/name_settings_controller_spec.rb b/spec/requests/pages/name_settings_controller_spec.rb index 6630f5037..52c6aab4f 100644 --- a/spec/requests/pages/name_settings_controller_spec.rb +++ b/spec/requests/pages/name_settings_controller_spec.rb @@ -92,8 +92,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, page.to_json, 200 end + + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(page) + draft_question get name_settings_edit_path(form_id: page.form_id, page_id: page.id) end @@ -128,9 +130,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, page.to_json, 200 - mock.put "/api/v1/forms/1/pages/2", post_headers end + + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(page) + allow(PageRepository).to receive(:save!).with(hash_including(page_id: "2", form_id: 1)) end context "when form is valid and ready to update in the DB" do diff --git a/spec/requests/pages/routes_controller_spec.rb b/spec/requests/pages/routes_controller_spec.rb index 15861d374..087ba8a61 100644 --- a/spec/requests/pages/routes_controller_spec.rb +++ b/spec/requests/pages/routes_controller_spec.rb @@ -32,9 +32,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/101", headers, selected_page.to_json, 200 end + allow(PageRepository).to receive(:find).with(page_id: "101", form_id: 1).and_return(selected_page) + get show_routes_path(form_id: form.id, page_id: selected_page.id) end diff --git a/spec/requests/pages/selection/bulk_options_controller_spec.rb b/spec/requests/pages/selection/bulk_options_controller_spec.rb index cc63fecc8..a30397b9a 100644 --- a/spec/requests/pages/selection/bulk_options_controller_spec.rb +++ b/spec/requests/pages/selection/bulk_options_controller_spec.rb @@ -122,8 +122,8 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, page.to_json, 200 end + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(page) draft_question get selection_bulk_options_edit_path(form_id: page.form_id, page_id: page.id) end @@ -163,9 +163,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, page.to_json, 200 - mock.put "/api/v1/forms/1/pages/2", post_headers end + + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(page) + allow(PageRepository).to receive(:save!).with(hash_including(page_id: "2", form_id: 1)) end context "when form is valid and ready to update in the DB" do diff --git a/spec/requests/pages/selection/options_controller_spec.rb b/spec/requests/pages/selection/options_controller_spec.rb index ec7d7a1a3..3df79827e 100644 --- a/spec/requests/pages/selection/options_controller_spec.rb +++ b/spec/requests/pages/selection/options_controller_spec.rb @@ -138,8 +138,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, page.to_json, 200 end + + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(page) + draft_question get selection_options_edit_path(form_id: page.form_id, page_id: page.id) end @@ -178,9 +180,11 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, page.to_json, 200 - mock.put "/api/v1/forms/1/pages/2", post_headers end + + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(page) + allow(PageRepository).to receive(:save!).with(hash_including(page_id: "2", form_id: 1)) + draft_question end diff --git a/spec/requests/pages/selection/type_controller_spec.rb b/spec/requests/pages/selection/type_controller_spec.rb index 5ec41db97..c88868d6a 100644 --- a/spec/requests/pages/selection/type_controller_spec.rb +++ b/spec/requests/pages/selection/type_controller_spec.rb @@ -112,8 +112,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, page.to_json, 200 end + + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(page) + draft_question get selection_type_edit_path(form_id: page.form_id, page_id: page.id) end @@ -155,9 +157,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, page.to_json, 200 - mock.put "/api/v1/forms/1/pages/2", post_headers end + + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(page) + allow(PageRepository).to receive(:save!).with(hash_including(page_id: "2", form_id: 1)) end context "when form is valid and ready to update in the DB" do diff --git a/spec/requests/pages/text_settings_controller_spec.rb b/spec/requests/pages/text_settings_controller_spec.rb index 0e869d355..674ab610f 100644 --- a/spec/requests/pages/text_settings_controller_spec.rb +++ b/spec/requests/pages/text_settings_controller_spec.rb @@ -91,8 +91,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, page.to_json, 200 end + + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(page) + draft_question get text_settings_edit_path(form_id: page.form_id, page_id: page.id) end @@ -123,9 +125,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, page.to_json, 200 - mock.put "/api/v1/forms/1/pages/2", post_headers end + + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(page) + allow(PageRepository).to receive(:save!).with(hash_including(page_id: "2", form_id: 1)) end context "when form is valid and ready to update in the DB" do diff --git a/spec/requests/pages/type_of_answer_controller_spec.rb b/spec/requests/pages/type_of_answer_controller_spec.rb index 00e2c5a8c..418fd6ae9 100644 --- a/spec/requests/pages/type_of_answer_controller_spec.rb +++ b/spec/requests/pages/type_of_answer_controller_spec.rb @@ -168,9 +168,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, page.to_json, 200 end + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(page) + get type_of_answer_edit_path(form_id: page.form_id, page_id: page.id) end @@ -214,9 +215,10 @@ ActiveResource::HttpMock.respond_to do |mock| mock.get "/api/v1/forms/1", headers, form.to_json, 200 mock.get "/api/v1/forms/1/pages", headers, pages.to_json, 200 - mock.get "/api/v1/forms/1/pages/2", headers, page.to_json, 200 - mock.put "/api/v1/forms/1/pages/2", post_headers end + + allow(PageRepository).to receive(:find).with(page_id: "2", form_id: 1).and_return(page) + allow(PageRepository).to receive(:save!).with(hash_including(page_id: "2", form_id: 1)) end context "when form is valid and ready to update in the DB" do