Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions application/backend/prisma/seed/seed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PrismaClient } from '@prisma/client'
import { InviteStatus, PrismaClient } from '@prisma/client'
import { hashPassword } from '../../src/authentication'
import { SurveyStep } from '../../../common/types/survey'
import { createDefaultAnswers, recalculateAnswers } from '../../src/utils/answers'
Expand All @@ -20,9 +20,38 @@ const main = async () => {
})

const ShortSurveyStepData = require('./shortSurveyData.json')
// Short Study - nested ACCEPTED invites for the four participants seeded below (Michael, Sally, Alice, Judith)
const shortStudy = await prisma.study.create({
data: {
name: 'Short Study',
invites: {
create: [
{
email: 'michaelwilson@example.com',
status: InviteStatus.ACCEPTED,
expiresAt: new Date('2026-01-01'),
sentAt: new Date('2025-12-15'),
},
{
email: 'sallywilson@example.com',
status: InviteStatus.ACCEPTED,
expiresAt: new Date('2026-01-01'),
sentAt: new Date('2025-12-15'),
},
{
email: 'alicejohnson@example.com',
status: InviteStatus.ACCEPTED,
expiresAt: new Date('2026-01-01'),
sentAt: new Date('2025-12-15'),
},
{
email: String(process.env.EXAMPLE_PARTICIPANT_EMAIL),
status: InviteStatus.ACCEPTED,
expiresAt: new Date('2026-01-01'),
sentAt: new Date('2025-12-15'),
},
],
},
},
})
console.log('Short Study created:', shortStudy)
Expand All @@ -49,6 +78,7 @@ const main = async () => {

const baseAnswers = createDefaultAnswers(ShortSurveyStepData)

// Michael - nested writes for user + profile + nextOfKin + studies + surveys
const michael = await prisma.user.upsert({
where: { email: 'michaelwilson@example.com' },
update: {},
Expand Down Expand Up @@ -99,7 +129,7 @@ const main = async () => {
},
},
})

// Sally - same nested pattern as Michael, second guardian on Short Study
await prisma.user.upsert({
where: { email: 'sallywilson@example.com' },
update: {},
Expand Down Expand Up @@ -150,7 +180,7 @@ const main = async () => {
},
},
})

// Johnny - dependent profile (no user account, so no invite) linked to Short Study
await prisma.participantProfile.upsert({
where: {
individualId: 'IND-ABC-003',
Expand Down Expand Up @@ -193,6 +223,7 @@ const main = async () => {
},
})

// Alice - Participant user on Short Study
const alice = await prisma.user.upsert({
where: { email: 'alicejohnson@example.com' },
update: {},
Expand Down Expand Up @@ -245,13 +276,22 @@ const main = async () => {
},
},
})

// Ensure a Study record exists
// Seed Study - nested ACCEPTED invite for Judith below (she is also on Short Study, that invite is nested above)
const defaultStudy = await prisma.study.create({
data: {
name: 'Seed Study',
redcapURL: process.env.REDCAP_API_URL,
redcapToken: process.env.REDCAP_API_TOKEN,
invites: {
create: [
{
email: String(process.env.EXAMPLE_PARTICIPANT_EMAIL),
status: InviteStatus.ACCEPTED,
expiresAt: new Date('2026-01-01'),
sentAt: new Date('2025-12-15'),
},
],
},
},
})

Expand Down Expand Up @@ -345,6 +385,7 @@ const main = async () => {

const exampleAnswers = createDefaultAnswers(SeedSurveyStepData)
exampleAnswers[1].answers[0] = false //For DUO testing
// Judith - example participant registered on both Short Study and Seed Study
const exampleUser = await prisma.user.upsert({
where: { email: String(process.env.EXAMPLE_PARTICIPANT_EMAIL) },
update: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ describe('InvitesController', () => {
const invite = await prisma.invite.findFirstOrThrow({
where: {
email: TestUsers.PARTICIPANT_UNANSWERED.email,
studyId: TestStudies.TEST_STUDY_2.id,
},
})

Expand Down Expand Up @@ -805,6 +806,7 @@ describe('InvitesController', () => {
const invite = await prisma.invite.findFirstOrThrow({
where: {
email: TestUsers.PARTICIPANT_UNANSWERED.email,
studyId: TestStudies.TEST_STUDY_2.id,
},
})

Expand Down
Loading
Loading