diff --git a/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/in_progress_forms_controller.rb b/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/in_progress_forms_controller.rb index 6e144041c31..59e524342c2 100644 --- a/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/in_progress_forms_controller.rb +++ b/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/in_progress_forms_controller.rb @@ -5,7 +5,7 @@ module V0 class InProgressFormsController < ApplicationController def update form = in_progress_form || new_form_for_user(form_id, @current_user) - form.update!(form_data: params[:formData], metadata: params[:metadata]) + form.update!(form_params) render json: InProgressFormSerializer.new(form) end @@ -44,6 +44,10 @@ def in_progress_form InProgressForm.form_for_user(form_id, @current_user) end + def form_params + params.permit(form_data: {}, metadata: {}) + end + def form_id params[:id] end diff --git a/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/in_progress_forms_spec.rb b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/in_progress_forms_spec.rb index 82cd2434b93..45530b27a91 100644 --- a/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/in_progress_forms_spec.rb +++ b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/in_progress_forms_spec.rb @@ -7,7 +7,6 @@ let(:initial_request_date) { Time.utc(2022, 3, 4, 5, 6, 7) } let(:form_id) { '21a' } let(:headers) { { 'Content-Type' => 'application/json' } } - let(:in_progress_form_id) { InProgressForm.last.id } before do Flipper.enable(:accredited_representative_portal_pilot) @@ -17,15 +16,17 @@ describe 'requests' do context 'can make requests to InProgressForms controller' do it 'can make requests to InProgressForms controller' do + form = build( + :in_progress_form, + user_uuid: representative_user.uuid, + form_data: { field: 'value' }, + form_id: + ) + # Test for GET and DELETE of existing InProgressForm Timecop.freeze(initial_request_date) do - form_data = { field: 'value' } - initial_in_progress_form = create( - :in_progress_form, - user_uuid: representative_user.uuid, - form_data:, - form_id: - ) + form.save! + get("/accredited_representative_portal/v0/in_progress_forms/#{form_id}") expect(parsed_response).to eq( { @@ -45,7 +46,7 @@ 'createdAt' => 1_646_370_367, 'expiresAt' => 1_651_554_367, 'lastUpdated' => 1_646_370_367, - 'inProgressFormId' => initial_in_progress_form.id + 'inProgressFormId' => InProgressForm.last.id } } ) @@ -56,12 +57,12 @@ # Test for PUT when InProgressForm does not exist Timecop.freeze(initial_request_date + 1.day) do - form_data = { another_field: 'foo' } put( "/accredited_representative_portal/v0/in_progress_forms/#{form_id}", - params: { 'formData' => form_data }.to_json, + params: { 'form_data' => { another_field: 'foo' } }.to_json, headers: ) + expect(parsed_response).to eq( { 'data' => { @@ -75,7 +76,7 @@ 'createdAt' => 1_646_456_767, 'expiresAt' => 1_651_640_767, 'lastUpdated' => 1_646_456_767, - 'inProgressFormId' => in_progress_form_id + 'inProgressFormId' => InProgressForm.last.id } } } @@ -92,7 +93,7 @@ 'createdAt' => 1_646_456_767, 'expiresAt' => 1_651_640_767, 'lastUpdated' => 1_646_456_767, - 'inProgressFormId' => in_progress_form_id + 'inProgressFormId' => InProgressForm.last.id } } ) @@ -100,12 +101,12 @@ # Test for PUT and DELETE when InProgressForm does exist Timecop.freeze(initial_request_date + 2.days) do - form_data = { another_field: 'foo', sample_field: 'sample' } put( "/accredited_representative_portal/v0/in_progress_forms/#{form_id}", - params: { 'formData' => form_data }.to_json, + params: { 'form_data' => { another_field: 'foo', sample_field: 'sample' } }.to_json, headers: ) + expect(parsed_response).to eq( { 'data' => { @@ -119,7 +120,7 @@ 'createdAt' => 1_646_456_767, 'expiresAt' => 1_651_727_167, 'lastUpdated' => 1_646_543_167, - 'inProgressFormId' => in_progress_form_id + 'inProgressFormId' => InProgressForm.last.id } } } @@ -137,7 +138,7 @@ 'createdAt' => 1_646_456_767, 'expiresAt' => 1_651_727_167, 'lastUpdated' => 1_646_543_167, - 'inProgressFormId' => in_progress_form_id + 'inProgressFormId' => InProgressForm.last.id } } )