Skip to content

LG-7345: Generate a unique ID when creating enrollments#6883

Merged
sheldon-b merged 9 commits intomainfrom
sbachstein/lg-7345-fix-unique-id-regression
Sep 6, 2022
Merged

LG-7345: Generate a unique ID when creating enrollments#6883
sheldon-b merged 9 commits intomainfrom
sbachstein/lg-7345-fix-unique-id-regression

Conversation

@sheldon-b
Copy link
Contributor

@sheldon-b sheldon-b commented Aug 31, 2022

🔮 Context

The USPS API requires us to specify a unique ID when we create an enrollment. Initially we did not store that value in the database and instead just grabbed 18 digits of the user's UUID -- this was a temporary workaround until we fleshed out the unique ID generation better

Since that initial workaround we've added a unique_id database column on the InPersonEnrollment model. The polling job sets that value and uses it once it's set, but it isn't used when we actually create the enrollment in the USPS API

Current sequence of actions

  1. When the user visits the location page we generate an enrollment with status == establishing. No unique ID is generated and the field is left empty
  2. When the user confirms their password we create an enrollment in the USPS API. For the unique ID we use InPersonEnrollment#usps_unique_id, which uses 18 digits of the user's UUID
  3. We change the status of the enrollment to pending
  4. Later the polling job runs queries for each pending enrollment. If the enrollment does not have a unique ID value saved then we set it to InPersonEnrollment#usps_unique_id (which would've been used to create the enrollment in the USPS API)
  5. The polling job polls the USPS API for updates to the enrollment using the value of enrollment.unique_id, which was just set in the previous step

What this PR implements

changes in bold
context in italics

  1. When the user visits the location page we generate an enrollment with status == establishing. When the enrollment is created we generate and save a unique ID using InPersonEnrollment.generate_unique_id
  2. When the user confirms their password we create an enrollment in the USPS API. For the unique ID we use:
    1. enrollment.unique_id if it exists
    2. Otherwise InPersonEnrollment#usps_unique_id, which uses 18 digits of the user's UUID
  3. We change the status of the enrollment to pending
  4. Later the polling job queries for each pending enrollment. If the enrollment does not have a unique ID value saved then we set it to InPersonEnrollment#usps_unique_id (which would've been used to create the enrollment in the USPS API)
  5. The polling job polls the USPS API for updates to the enrollment using the value of enrollment.unique_id. For enrollments created before this PR these values would have been set in the previous step. For enrollments created after this PR this value would have been set when the enrollment was first created at step 1

Future work

Eventually we'll set the unique_id field to be a required field. Then we can simplify step 2 above to always use enrollment.unique_id and we can remove step 4 above. This is captured in LG-7024

🚧 Changes

  • Adds a hook on the InPersonEnrollment model to generate a unique ID automatically if one isn't provided
  • Adds a few tests so that regressions will be detected

@sheldon-b sheldon-b changed the base branch from main to sbachstein/lg-6964-expand-usps-polling-analytics August 31, 2022 16:03
Base automatically changed from sbachstein/lg-6964-expand-usps-polling-analytics to main August 31, 2022 18:37
@sheldon-b sheldon-b force-pushed the sbachstein/lg-7345-fix-unique-id-regression branch from a9d13e9 to 072091d Compare September 1, 2022 15:01
@sheldon-b sheldon-b marked this pull request as ready for review September 1, 2022 15:11
@sheldon-b sheldon-b requested review from a team, svalexander and tomas-nava and removed request for a team and svalexander September 1, 2022 15:11
@sheldon-b sheldon-b marked this pull request as draft September 1, 2022 16:52
@sheldon-b sheldon-b marked this pull request as ready for review September 1, 2022 17:14
Copy link
Contributor

@eileen-nava eileen-nava left a comment

Choose a reason for hiding this comment

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

Since I'm still learning the codebase, I don't feel comfortable approving the PR for merge. However, I found it very educational to read through this PR! The code is very readable.


it 'sets enrollment status to pending and sets enrollment established at date' do
context 'when the enrollment does not have a unique ID' do
it 'uses the deprecated InPersonEnrollment#usps_unique_id value to create the enrollment' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Ohhhhh, okay, this spec answers my previous question in a comment on enrollment_helper.rb. 👍🏻

Copy link
Contributor

@tomas-nava tomas-nava left a comment

Choose a reason for hiding this comment

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

approve!

@sheldon-b sheldon-b merged commit 840b593 into main Sep 6, 2022
@sheldon-b sheldon-b deleted the sbachstein/lg-7345-fix-unique-id-regression branch September 6, 2022 15:36
@zachmargolis zachmargolis mentioned this pull request Sep 7, 2022
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.

5 participants