Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
khiga8 committed Dec 15, 2024
1 parent 6e1694b commit bef3812
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ en:
header: "Upload CSV File"
csv_header_requirements: "Your CSV file must have column headers of 'Email' and 'Timestamp' for the import to work."
upload_results:
success_heading: "File successsfully scanned"
success_heading: "File successfully scanned"
error_heading: "File scanned: %{count} error(s) present"
submissions_added: "%{count} new form submissions were added."
review_errors: "Review the following error(s) to ensure all form submissions are added:"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,54 @@
module Organizations
module Staff
class ExternalFormUploadControllerTest < ActionDispatch::IntegrationTest
setup do
file = fixture_file_upload("google_form_sample.csv", "text/csv")
@params = {files: file}
admin = create(:admin)
@adopter = create(:adopter, email: "[email protected]")
@adopter2 = create(:adopter, email: "[email protected]")
sign_in admin
context "success" do
setup do
file = fixture_file_upload("google_form_sample.csv", "text/csv")
@params = {files: file}
admin = create(:admin)
@adopter = create(:adopter, email: "[email protected]")
@adopter2 = create(:adopter, email: "[email protected]")
sign_in admin
end

should "Creates new form submission" do
assert_difference "@adopter.person.form_submissions.count" do
post staff_external_form_upload_index_path, params: @params
end
end

should "It does not create form answers for adopter2" do
assert_no_difference "@adopter2.person.form_submissions.count" do
post staff_external_form_upload_index_path, params: @params
end
end

should "shows success feedback" do
post staff_external_form_upload_index_path, params: @params, as: :turbo_stream

assert_response :success
assert_turbo_stream(action: "replace", count: 1) do
assert_select "h5", text: "File successfully scanned"
end
end
end

test "Creates new form submission" do
assert_difference "@adopter.person.form_submissions.count" do
post staff_external_form_upload_index_path, params: @params
context "error" do
setup do
file = fixture_file_upload("google_form_error_sample.csv", "text/csv")
@params = {files: file}
admin = create(:admin)
adopter = create(:adopter, email: "[email protected]")
sign_in admin
end
end

test "It does not create form answers for adopter2" do
assert_no_difference "@adopter2.person.form_submissions.count" do
post staff_external_form_upload_index_path, params: @params
should "shows error feedback" do
post staff_external_form_upload_index_path, params: @params, as: :turbo_stream

assert_response :success
assert_turbo_stream(action: "replace", count: 1) do
assert_select "h5", text: "File scanned: 1 error(s) present"
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/files/google_form_error_sample.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Timestamp,Nombre,Email,Dirección,Número de teléfono,Comentarios
2024/13/05 7:14:21 p. m. GMT-4,dsf,[email protected],dsfsdf,sdfsdf,ds

0 comments on commit bef3812

Please sign in to comment.