Skip to content

Commit

Permalink
refactor tests wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jho44 committed Feb 24, 2024
1 parent 1cf6087 commit 8315c5a
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 214 deletions.
220 changes: 8 additions & 212 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { AvailabilityStatus, PrismaClient, Pronoun } from '@prisma/client';
import { DateTime } from 'luxon';
import { createExpiredLink, createUser1WithNothing, createUser2WithActiveSession, createUser3WithHousehold, deleteAllFriendRequests } from './utils';

export const prisma = new PrismaClient();

const prisma = new PrismaClient();
async function main() {
const phones: string[] = [
'+12015550121',
Expand All @@ -15,154 +17,15 @@ async function main() {
const expires = new Date();
expires.setHours(expires.getHours() + 1);

function permsYes(phone: string) {
return {
phonePermissions: {
connectOrCreate: {
where: {
phone
},
create: {
phone,
blocked: false,
allowInvites: true,
allowReminders: true,
acceptedTermsAt: now
}
}
}
};
}

function emptyHousehold(ind: number) {
return {
household: {
connectOrCreate: {
where: {
id: ind
},
create: {
// phone: phones[ind - 1],
id: ind,
name: `Household ${ind}`
}
}
}
};
}

function householdWithKid(ind: number, kidInd: number) {
return {
household: {
connectOrCreate: {
where: {
id: ind
},
create: {
id: ind,
name: `Household ${ind}`,
children: {
connectOrCreate: [
{
where: {
id: kidInd
},
create: {
firstName: `User ${ind} Kid ${kidInd}`,
pronouns: Pronoun['HE_HIM_HIS']
}
}
]
}
}
}
}
};
}

function basicUser(id: number) {
return {
firstName: `User ${id}`,
locale: 'English',
pronouns: Pronoun['SHE_HER_HERS'],
timeZone: 'America/Los_Angeles',
reminderDatetime: new Date(),
reminderIntervalDays: 7,
acceptedTermsAt: new Date()
};
}

await prisma.friendRequest
.deleteMany()
.catch(() => console.log('No friend request table to delete'));
await deleteAllFriendRequests()

const expiredLink = {
token: '3e99472f1003794c',
phone: '+12015550121',
expires: new Date('8/5/2020')
};
await prisma.magicLink.upsert({
where: {
id: 1
},
update: expiredLink,
create: expiredLink
});
await createExpiredLink()

// User 1
await prisma.user.upsert({
where: {
phone: phones[0]
},
update: basicUser(1),
create: {
...basicUser(1),
...permsYes(phones[0])
}
});

// User 2
await prisma.user.upsert({
where: {
phone: phones[1]
},
update: basicUser(2),
create: {
...basicUser(2),
...permsYes(phones[1])
}
});

const user2session = 'user2session';
const session = {
token: user2session,
phone: phones[1],
expires
};
await prisma.session.upsert({
where: {
token: user2session
},
update: session,
create: session
});
await createUser1WithNothing(phones[0], now)

// User 3
const user3 = {
...basicUser(3),
...emptyHousehold(3)
};
await createUser2WithActiveSession(phones[1], now)

await prisma.user.upsert({
where: {
phone: phones[2]
},
update: user3,
create: {
...user3,
...permsYes(phones[2])
}
});
await createUser3WithHousehold(phones[2], now)

// User 4
const user4 = {
Expand Down Expand Up @@ -300,73 +163,6 @@ async function main() {
update: session6,
create: session6
});

const firstDate = DateTime.fromObject(
{
year: 2001,
month: 8,
day: 11
},
{
zone: 'utc'
}
);


const firstDateBase = {
status: AvailabilityStatus.AVAILABLE,
notes: 'first date',
emoticons: '',
startTime: firstDate.set({ hour: 14 }).toJSDate(),
endTime: firstDate.set({ hour: 15 }).toJSDate()
};
await prisma.availabilityDate.upsert({
where: {
householdId_date: {
householdId: 3,
date: firstDate.toJSDate(),
}
},
update: firstDateBase,
create: {
householdId: 3,
date: firstDate.toJSDate(),
...firstDateBase
}
});

const lastDate = DateTime.fromObject(
{
year: 2001,
month: 3,
day: 8
},
{
zone: 'utc'
}
);

const lastDateBase = {
status: AvailabilityStatus.AVAILABLE,
notes: 'last date',
emoticons: '',
startTime: lastDate.set({ hour: 14 }).toJSDate(),
endTime: lastDate.set({ hour: 15 }).toJSDate()
};
await prisma.availabilityDate.upsert({
where: {
householdId_date: {
householdId: 3,
date: lastDate.toJSDate(),
}
},
update: lastDateBase,
create: {
householdId: 3,
date: lastDate.toJSDate(),
...lastDateBase
}
});
}

export async function run() {
Expand Down
Loading

0 comments on commit 8315c5a

Please sign in to comment.