-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve seed data and validity (#4099)
- Loading branch information
1 parent
c19f18c
commit adab010
Showing
19 changed files
with
223 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export const LISTINGS_TO_SEED = 10; | ||
export const APPLICATIONS_PER_LISTINGS = 5; | ||
export const APPLICATIONS_PER_LISTINGS = 10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Prisma } from '@prisma/client'; | ||
import { randomInt } from 'crypto'; | ||
import { randomAdjective, randomNoun } from './word-generator'; | ||
import { AlternateContactRelationship } from '../../src/enums/applications/alternate-contact-relationship-enum'; | ||
import { addressFactory } from './address-factory'; | ||
|
||
export const alternateContactFactory = | ||
(): Prisma.AlternateContactCreateWithoutApplicationsInput => { | ||
const relationshipKeys = Object.values(AlternateContactRelationship); | ||
const firstName = randomNoun(); | ||
const lastName = randomNoun(); | ||
const relationshipType = | ||
relationshipKeys[randomInt(relationshipKeys.length)]; | ||
|
||
if (relationshipType === AlternateContactRelationship.noContact) { | ||
return { | ||
firstName: undefined, | ||
lastName: undefined, | ||
type: relationshipType, | ||
otherType: undefined, | ||
phoneNumber: undefined, | ||
emailAddress: undefined, | ||
agency: undefined, | ||
address: { create: addressFactory() }, | ||
}; | ||
} | ||
return { | ||
firstName: firstName, | ||
lastName: lastName, | ||
type: relationshipType, | ||
otherType: | ||
relationshipType === AlternateContactRelationship.other | ||
? randomAdjective() | ||
: undefined, | ||
phoneNumber: '(123) 123-1231', | ||
emailAddress: `${firstName}.${lastName}@example.com`, | ||
address: { create: addressFactory() }, | ||
agency: | ||
relationshipType === AlternateContactRelationship.caseManager | ||
? randomAdjective() | ||
: undefined, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,48 @@ | ||
import { Prisma, YesNoEnum } from '@prisma/client'; | ||
import { randomInt } from 'crypto'; | ||
import { HouseholdMemberRelationship } from '../../src/enums/applications/household-member-relationship-enum'; | ||
import { addressFactory } from './address-factory'; | ||
import { randomAdjective, randomNoun } from './word-generator'; | ||
import { randomNoun } from './word-generator'; | ||
import { | ||
randomBirthDay, | ||
randomBirthMonth, | ||
randomBirthYear, | ||
} from './number-generator'; | ||
import { randomBoolean } from './boolean-generator'; | ||
|
||
export const householdMemberFactorySingle = | ||
(): Prisma.HouseholdMemberCreateWithoutApplicationsInput => { | ||
const firstName = randomNoun(); | ||
const lastName = randomNoun(); | ||
const randomYesNo = randomBoolean() === true ? YesNoEnum.yes : YesNoEnum.no; | ||
return { | ||
firstName: firstName, | ||
middleName: randomNoun(), | ||
lastName: lastName, | ||
// Question: why are these strings? | ||
birthMonth: randomBirthMonth(), | ||
birthDay: randomBirthDay(), | ||
birthYear: randomBirthYear(), | ||
sameAddress: randomYesNo, | ||
// Question: should this be an enum? | ||
relationship: randomAdjective(), | ||
workInRegion: randomYesNo, | ||
householdMemberAddress: randomBoolean | ||
? undefined | ||
: { create: addressFactory() }, | ||
householdMemberWorkAddress: { | ||
create: addressFactory(), | ||
}, | ||
}; | ||
export const householdMemberFactorySingle = ( | ||
index: number, | ||
): Prisma.HouseholdMemberCreateWithoutApplicationsInput => { | ||
const firstName = randomNoun(); | ||
const lastName = randomNoun(); | ||
|
||
const relationshipKeys = Object.values(HouseholdMemberRelationship); | ||
|
||
return { | ||
firstName: firstName, | ||
middleName: randomNoun(), | ||
lastName: lastName, | ||
// Question: why are these strings? | ||
birthMonth: randomBirthMonth(), | ||
birthDay: randomBirthDay(), | ||
birthYear: randomBirthYear(), | ||
sameAddress: YesNoEnum.yes, | ||
relationship: relationshipKeys[randomInt(relationshipKeys.length)], | ||
workInRegion: YesNoEnum.yes, | ||
householdMemberAddress: { create: addressFactory() }, | ||
householdMemberWorkAddress: { | ||
create: addressFactory(), | ||
}, | ||
orderId: index, | ||
}; | ||
}; | ||
|
||
export const householdMemberFactoryMany = async ( | ||
numberToMake: number, | ||
): Promise<Prisma.HouseholdMemberCreateWithoutApplicationsInput[]> => { | ||
const createArray: Promise<Prisma.HouseholdMemberCreateWithoutApplicationsInput>[] = | ||
[...new Array(numberToMake)].map(async () => | ||
householdMemberFactorySingle(), | ||
[...new Array(numberToMake)].map(async (index) => | ||
householdMemberFactorySingle(index), | ||
); | ||
return await Promise.all(createArray); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
api/src/enums/applications/alternate-contact-relationship-enum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export enum AlternateContactRelationship { | ||
familyMember = 'familyMember', | ||
friend = 'friend', | ||
caseManager = 'caseManager', | ||
other = 'other', | ||
noContact = 'noContact', | ||
} |
17 changes: 17 additions & 0 deletions
17
api/src/enums/applications/household-member-relationship-enum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export enum HouseholdMemberRelationship { | ||
spouse = 'spouse', | ||
registeredDomesticPartner = 'registeredDomesticPartner', | ||
parent = 'parent', | ||
child = 'child', | ||
sibling = 'sibling', | ||
cousin = 'cousin', | ||
aunt = 'aunt', | ||
uncle = 'uncle', | ||
nephew = 'nephew', | ||
niece = 'niece', | ||
grandparent = 'grandparent', | ||
greatGrandparent = 'greatGrandparent', | ||
inLaw = 'inLaw', | ||
friend = 'friend', | ||
other = 'other', | ||
} |
Oops, something went wrong.