Create ACCEPTED invites for seeded participant users - #912
Conversation
ignatiusm
left a comment
There was a problem hiding this comment.
Hi @iamtanuj18 ,
Thanks for your work on this. Nice one fixing the affected tests. Two requested changes:
-
To make the ongoing maintenance of the seed data easier, can you look in to nested writes to see if you can create invites at the same time as the users are being created? I think this is easier to maintain as all records related to a user are linked in one transaction. For an example, look at lines 52 to 101 in
application/backend/prisma/seed/seed.ts. You may need to do some experimenting to make sure this works. Let me know if you have any issues. -
Can you also apply a similar fix to any participants created in
application/backend/prisma/seed/seed.ts? This is a different set of seed data used for local dev. It is what initially alerted me to this issue as I was playing around with invites with local dev set up, when I realised that the participant users did not have associated invites.
|
@ignatiusm requested changes are done and the PR is ready for review. |
ignatiusm
left a comment
There was a problem hiding this comment.
Hi @iamtanuj18,
Really nice work tidying up the test seed data with nested writes!! Thanks for adding some more explanatory comments. I reckon that is much tidier - would be curious to hear your view.
For the invites, I realise I might have steered you in the wrong direction when I said:
To make the ongoing maintenance of the seed data easier, can you look in to nested writes to see if you can create invites at the same time as the users are being created?
Looking at application/backend/prisma/schema.prisma Invites are associated with Studies, not Users. So the nested writes need to happen with study creation, not User creation. I just implemented a test example locally to check. I think it is an improvement: creating the invites at study creation time, then sets up expectations for the number of participants that will be created.
Can you please have a go at implementing the invites using nested writes too? feel free to ask if you have any questions or concerns.
|
@ignatiusm changes: invites now nested under study.create in both seed files. |
Fixes #890.
Adds ACCEPTED Invite rows for PARTICIPANT_UNANSWERED, PARTICIPANT_COMPLETED, and GUARDIAN_2 in seed.ts, so seeded participants match the shape of production data (every participant has an accepted invite in their study). Fixes the alreadyAcceptedCount check in ParticipantsController returning 0 for seeded participants.
Two existing tests in ParticipantsController.test.ts were relying on
findFirstOrThrow({ email })to return the participant's single pre-existing PENDING invite. Now that seeded participants also have an ACCEPTED invite in TEST_STUDY, the query is ambiguous — the fix addsstudyId: TEST_STUDY_2.idto those queries so they find the correct pending invite.