Modify the SMS API to upsert a Reminder document when a Courtbot VT user subscribes to receiving a court notification. #18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Unit tests for this pull request are not included in this pull request, but are available here.
This request proposes the SMS API be modified such that when a user elects to receive a notification on an upcoming court session, a single document is updated (or inserted) through an updateOne() Mongoose call having options.upsert set to true.
Currently, when a user subscribes to being reminded on an upcoming court session, a new Reminder document is added each time.
The requested change may impose unwanted side-effects if duplicate Reminder documents are not removed.
Exempli gratia (Where _id is the group _id from the aggregate operation and not the reminder document _id):
Reminder documents with matching phone number and court case docket identifiers and numbers (but with multiple, different active states) will have more than one active field value in the following group operation:
One side-effect of the current implementation is that users may be notified multiple times on an upcoming court session if a users makes multiple confirmations to receive a notification on an upcoming court date, as a Reminder document is currently created each time a user subscribes. Duplicate Reminder documents from the MongoDB store may be removed with:
User stories:
Given a user is subscribing to receive a notification on a court case for the first time,
when a user declines to be notified on an upcoming court session and the SMS API is called,
then no Reminder document is created.
Given a user is subscribing to receive a notification on a court case for the first time,
when a user confirms to be notified on an upcoming court session and the SMS API is called,
then a single Reminder document is created with the associated case's unique identifier and user phone number and the Reminder document's active field is set to true.
Given a user is subscribing to receive a notification on a court case that they have been notified on prior and one associated Reminder document exists with its active field value set to false,
when a user confirms to be notified on an upcoming court session and the SMS API is called,
then the associated Reminder document having a matching case unique identifier and user phone number is updated with the document's active field set to true.
Given a user has subscribed to receiving a notification on an upcoming court session and one associated Reminder document exists with its active field value set to true,
when a user confirms to be notified on the same upcoming court session and the SMS API is called,
no additional Reminder document is created and the associated Reminder document's unique case identifier and user phone number and active field value set to true field states are not modified.
Acceptance criterion:
A Reminder document is created when a user confirms to receiving a notification on an upcoming court date for a valid court case for the first time.
An associated Reminder document's active field is updated to true when a user confirms to receiving a notification on a court date for a valid court case the user has previously received a notification.
No additional Reminder documents are created when a user confirms to receiving a notification on an upcoming court date for a valid court case multiple times.