Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1033 external form upload #1038

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

wandergithub
Copy link
Contributor

🔗 Issue

#1033

✍️ Description

  • Add a note for Google form support to description.
  • Add a route and create a method to use form upload service to process the csv file
  • adds test

📷 Screenshots/Demos

@wandergithub
Copy link
Contributor Author

@kasugaijin There is an assertion that is commented. This is because it works perfectly when tested individually. But when using ./bin/rails test:all it fails. I don't know why the FormSubmission person_id is different from the user_id when tested with the mentioned command but it matches as it should when tested individually. I could not find where is it being affected.

@organization = ActsAsTenant.current_tenant
@file = fixture_file_upload("google_form_sample.csv", "text/csv")
@params = {files: [@file]}
@user = create(:admin, email: "[email protected]")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be creating an adopter here, instead of admin

There are also some changes happening in this PR #997

  • a Person can have multiple form submissions
  • a form submission will be created on a person when a new adopter signs up

This means the asserstions on lines 20 and 21 will become unnecessary. We'll want to just test two cases

  • when a form submission does not have any form answers (and no CSV timestamp), assert that new form answers are created
  • when a form submission does have a csv timestamp matching the timestamp in the CSV, no new Form Answers are created

I think the best thing to do, here, is wait for that PR to get merged, then finish these tests off. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I understand lines 20 and 21 can be removed.

On the other assertions I'm verifying that FormSubmissions and FormAnswers are being created after the upload csv. Where we have 4 answers and questions/cells and 1 form was uploaded so one FormSubmission was created.

As I understood we may need to add a test for when a csv file matches an existing csv_timestamp entry... Nothing should happen. But all of these are subject to change after PR #997

Then I will remove the unnecessary assertions, address controller comments, and wait for your instructions on the tests.

authorize! :external_form_upload,
context: {organization: Current.organization}
files = params.require(:files)
files.each do |file|
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should only really allow 1 upload here...it doesn't make sense for more than one file.

Given we are using app/views/organizations/staff/shared/_attachment_form.html.erb partial, we could make the value for the multiple attribute an argument that gets passed to the partial. So in this case, it would be false and in the other place the partial is used, on the pet, it would be true. Thoughts?

Then we can get rid of this loop here.

Also, curious of the benefit of checking file.is_a?(ActionDispatch::Http::UploadedFile)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file.is_a?(ActionDispatch::Http::UploadedFile) It is because the received parameter contains other things like "". Maybe It will be unnecessary when using just one file.

I don't understand completely the use case due to a lack of background knowledge of the project. If you think a single file is the way to go, I will implement the suggested changes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this import service is making the assumption there is only one third party form, and therefore one CSV to upload. It doesn’t currently handle the case where adopter data lives across multiple forms. So it would be good to only allow one file for now.

Modify external form controller to support just one file upload
correct controller test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants