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

Merged
merged 13 commits into from
Oct 17, 2024

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: "adopter1@alta.com")
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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@wandergithub FYI this PR has now been merged #997
So now person has many form submissions

Copy link
Collaborator

Choose a reason for hiding this comment

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

@wandergithub let me know if you have any blockers on this :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kasugaijin Yeah, I would like to know which requirements or specifications changed on this PR. It's not clear to me.

Modify external form controller to support just one file upload
correct controller test
@@ -0,0 +1,21 @@
require "test_helper"

class Organizations::Staff::ExternalFormUploadControllerTest < ActionDispatch::IntegrationTest
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we nest the modules instead please?

@wandergithub
Copy link
Contributor Author

image
does not fail locally ??

@wandergithub
Copy link
Contributor Author

Ok, I will address it here in this PR.

@wandergithub
Copy link
Contributor Author

I'm blocked, I cant make the factory for @person1 = create(:adopter, email: "adopter1@alta.com") to persist the person.
The person with the email "adoper1@..." is not being created. I've used :with_person to make changes to the factory but when debugging in the csv_service part of the code the person does not exist for some reason 🤯.

@kasugaijin
Copy link
Collaborator

I'm blocked, I cant make the factory for @person1 = create(:adopter, email: "adopter1@alta.com") to persist the person. The person with the email "adoper1@..." is not being created. I've used :with_person to make changes to the factory but when debugging in the csv_service part of the code the person does not exist for some reason 🤯.

Can you please push your latest changes up to this branch? I'd like to see the full picture before looking at why

@kasugaijin
Copy link
Collaborator

kasugaijin commented Oct 14, 2024

@wandergithub
I think I found the issues - see the video
I'd suggest refactoring the CSV import logic first, too.

I think you can ignore my comment about changing the email in the setup and the csv...that should not be an issue with the updates I suggest.

https://www.loom.com/share/d462da8a6a534cd0b75b831fcc593786?sid=4cf176c6-89f8-408d-8aa1-289c46fb3c7f

@wandergithub
Copy link
Contributor Author

@kasugaijin Thank you! I really needed that. I will implement the new service logic first to get it out of the way, and then check out everything else.

@kasugaijin
Copy link
Collaborator

@kasugaijin Thank you! I really needed that. I will implement the new service logic first to get it out of the way, and then check out everything else.

I am glad it helped!

@kasugaijin
Copy link
Collaborator

I am just leaving a note for myself here - we should make sure we fully test the refactor of the CSV import service i.e.

  • it skips the row if the user exists and the timestamp matches that on the FormSubmisson
  • it updates the existing form submission if it is 'empty' i.e. does not have any answers (no timestamp saved)
  • it creates a new form submission and adds the form answers if there is no 'empty' form submission and the timestamp is different

@wandergithub You could add the above tests to this PR...but it has already changed a lot for you, so it might be better to not change the scope of this PR any further, and then tackle any of the missing above tests separately to keep things manageable (if you prefer).

- Updates users Factorie to create the person
- fix external_form_upload_controller_tests
@wandergithub
Copy link
Contributor Author

I am just leaving a note for myself here - we should make sure we fully test the refactor of the CSV import service i.e.

  • it skips the row if the user exists and the timestamp matches that on the FormSubmisson
  • it updates the existing form submission if it is 'empty' i.e. does not have any answers (no timestamp saved)
  • it creates a new form submission and adds the form answers if there is no 'empty' form submission and the timestamp is different

@wandergithub You could add the above tests to this PR...but it has already changed a lot for you, so it might be better to not change the scope of this PR any further, and then tackle any of the missing above tests separately to keep things manageable (if you prefer).

I added the last two since the first test already exists as the first one in csv_import_service_tests.rb. I think I addressed all concerns . I will be attentive to any comments.

Copy link
Collaborator

@kasugaijin kasugaijin left a comment

Choose a reason for hiding this comment

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

Looking really good @wandergithub! Just one comment to DRY up the service object refactor.

Copy link
Collaborator

@kasugaijin kasugaijin left a comment

Choose a reason for hiding this comment

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

Approved but please change the variable names in the tests per my suggestion

@@ -4,14 +4,14 @@
module Organizations
class CsvImportServiceTest < ActiveSupport::TestCase
setup do
person = create(:person)
person = create(:adopter)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here re variable naming

Copy link
Collaborator

@kasugaijin kasugaijin left a comment

Choose a reason for hiding this comment

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

Nice!

@wandergithub
Copy link
Contributor Author

I think that would do it 👍🏽

@kasugaijin kasugaijin merged commit c4a3c32 into rubyforgood:main Oct 17, 2024
5 checks passed
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