-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add post-setup test and seed flight
- Loading branch information
Showing
9 changed files
with
60 additions
and
9 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
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,39 @@ | ||
import { format } from 'date-fns'; | ||
import { Kysely } from 'kysely'; | ||
|
||
import type { DB } from '../../src/lib/db/schema'; | ||
import type { CreateFlight } from '../../src/lib/db/types'; | ||
|
||
export const seedFlight = async (db: Kysely<DB>, userId: string) => { | ||
await createFlight(db, { | ||
seats: [ | ||
{ userId, seat: 'window', seatNumber: '11F', seatClass: 'economy' }, | ||
], | ||
from: 'EKCH', | ||
to: 'ESSA', | ||
date: format(new Date(), 'yyyy-MM-dd'), | ||
duration: 70 * 60, | ||
}); | ||
}; | ||
|
||
const createFlight = async (db: Kysely<DB>, data: CreateFlight) => { | ||
await db.transaction().execute(async (trx) => { | ||
const { seats, ...flightData } = data; | ||
const resp = await trx | ||
.insertInto('flight') | ||
.values(flightData) | ||
.returning('id') | ||
.executeTakeFirstOrThrow(); | ||
|
||
const seatData = seats.map((seat) => ({ | ||
flightId: resp.id, | ||
userId: seat.userId, | ||
guestName: seat.guestName, | ||
seat: seat.seat, | ||
seatNumber: seat.seatNumber, | ||
seatClass: seat.seatClass, | ||
})); | ||
|
||
await trx.insertInto('seat').values(seatData).executeTakeFirstOrThrow(); | ||
}); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const isPathname = (pathname: string) => { | ||
return (url: URL) => url.pathname === pathname; | ||
}; |
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