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

Resolves #4689 - Update seeds: mark users invitation_status as "accepted" #4705

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lsfernandes92
Copy link

@lsfernandes92 lsfernandes92 commented Oct 4, 2024

Resolves #4689

Description

When we run the bin/setup script, it triggers various processes, including the Rails command bin/rails db:reset. This command is responsible for dropping the database and setting it up again (which actually creates the database, loads the schema, and initializes it with seed data). The seed data is located in db/seeds.rb, and this file should contain all the necessary record creation to populate the database with demo values.

We discovered that when a partner service attempts to invite a user created during the bin/setup script, the error "nil can't be converted to a Time value" is raised. This happens because those users don't have the invitation attributes set.

This PR adds extra lines to the db/seeds.rb file to mark all created users' invitation_status as accepted. Specifically, it sets the invitation_sent_at and invitation_accepted_at attributes for each user. I decided to modify only these values after reviewing the User#invitation_status method and this related test.

Regarding the question left on the issue

| It does send the email -- it's just failing on displaying?

I'm not entirely sure, but based on the logs, there was a background job failure after I sent the user invite that I noticed. Should I be concerned about this?

Screenshot 3

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  1. I followed the steps to reproduce mentioned in the issue:

    • Inside the project folder, run the command bin/setup
    • Then run the command bin/start
    • Open your localhost
    • Sign in with the email "[email protected]" and the password "password!"
    • Navigate to "Partner Agencies > All Partners"
    • From the partner listing, choose "Pawnee Parent Service"
    • Click on "Manage users"
    • On the "Invite New User" form, fill in the name with "User 1" and the email with "[email protected]"
    • Click on "Invite User"
  2. I ran the test scenario that I added with bundle exec rspec spec/models/user_spec.rb:134

  3. I also ran the bin/lint command

  4. I ran the entire test suite with bundle exec rspec

Screenshots

(Before) On the "Manage users" partner page, after clicking on "Invite User"

Screenshot 2

(After) On the "Manage users" partner page, after clicking on "Invite User"

Screenshot 4

@lsfernandes92 lsfernandes92 marked this pull request as ready for review October 4, 2024 18:29
@lsfernandes92 lsfernandes92 changed the title Update seeds: mark users invitation_status as "accepted" [Resolves #4689] Update seeds: mark users invitation_status as "accepted" Oct 4, 2024
@@ -833,3 +833,7 @@ def seed_quantity(item_name, organization, storage_location, quantity)
]
)
TransferCreateService.call(transfer)

Copy link
Author

Choose a reason for hiding this comment

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

❓Question: For this file I see some common comments sections, should I add some comments to explain why the users' invitation_status is being changed?

@@ -111,6 +111,12 @@ def invitation_status
"invited" if invitation_sent_at.present?
end

def mark_invitation_status_as_accepted!
self.invitation_sent_at = Time.current
Copy link
Author

Choose a reason for hiding this comment

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

❓Question: Should I be concerned about the other related invitation attributes? Like, for example, the attributes invitation_created_at, or invitation_limit, or invitation_token, etc…

@@ -111,6 +111,12 @@ def invitation_status
"invited" if invitation_sent_at.present?
end

def mark_invitation_status_as_accepted!
Copy link
Author

Choose a reason for hiding this comment

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

❓Question: Another possible solution would be to implement this inside the seeds file instead of the User model class. I find it clearer this way, but the User class is at risk of becoming a "monster class," and this addition might encourage others to add even more complexity to it. Do you think it's okay as it is?

@lsfernandes92 lsfernandes92 changed the title [Resolves #4689] Update seeds: mark users invitation_status as "accepted" Resolves #4689 - Update seeds: mark users invitation_status as "accepted" Oct 4, 2024
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.

Some users in the seed do not have an 'invited at' . That has caused testing issues. Can we fix it?
1 participant