ReviewOS

also looking at this

reviewos/reviewos.org

fix(tests): a fresh database has no user 1 and no hook secret

#4
Merged glennmichael123 wants to merge fix/repo-delete-test-seeds into main
2 files +24 -3
tests/e2e/repo-delete.test.tsmodified+16-3
Changes to tests/e2e/repo-delete.test.ts
@@ -18,6 +18,10 @@ let available = false
1818let db: any = null
1919let sweepPolymorphic: (id: number) => Promise<{ ok: boolean, removed: Array<{ table: string, rows: number }>, error?: string }>
2020const made: number[] = []
21// The user everything here is owned by. Created per run rather than assumed:
22// `reactions.user_id` and `notification_subscriptions.user_id` are real foreign
23// keys, and a freshly migrated database has no user 1 to point them at.
24let userId = 0
2125
2226beforeAll(async () => {
2327 try {
@@ -27,6 +31,12 @@ beforeAll(async () => {
2731 db = (globalThis as any).db
2832 await db.selectFrom('repositories').select(['id']).limit(1).execute()
2933
34 const handle = `del${Math.floor(Math.random() * 1e9)}`
35 const user = await db.insertInto('users')
36 .values({ name: 'Delete Tester', email: `${handle}@example.com`, handle, password: 'x' })
37 .returning(['id']).executeTakeFirst()
38 userId = Number(user.id)
39
3040 ;({ sweepPolymorphic } = await import('../../app/Actions/Repo/polymorphic'))
3141 available = true
3242 }
@@ -41,6 +51,9 @@ afterAll(async () => {
4151
4252 for (const id of made)
4353 await db.deleteFrom('repositories').where('id', '=', id).execute()
54
55 if (userId)
56 await db.deleteFrom('users').where('id', '=', userId).execute()
4457})
4558
4659/** A repository with one of everything that hangs off it, polymorphic or not. */
@@ -50,7 +63,7 @@ async function seedRepository(): Promise<{ id: number, issueId: number, commentI
5063 const repository = await db.insertInto('repositories')
5164 .values({
5265 owner_type: 'user',
53 owner_id: 1,
66 owner_id: userId,
5467 name,
5568 description: '',
5669 visibility: 'public',
@@ -73,11 +86,11 @@ async function seedRepository(): Promise<{ id: number, issueId: number, commentI
7386 const commentId = Number(comment.id)
7487
7588 await db.insertInto('reactions')
76 .values({ subject_type: 'issue_comment', subject_id: commentId, content: '+1', user_id: 1 }).execute()
89 .values({ subject_type: 'issue_comment', subject_id: commentId, content: '+1', user_id: userId }).execute()
7790 await db.insertInto('timeline_entries')
7891 .values({ subject_type: 'issue', subject_id: issueId, kind: 'closed' }).execute()
7992 await db.insertInto('notification_subscriptions')
80 .values({ subject_type: 'repository', subject_id: id, user_id: 1, reason: 'watching' }).execute()
93 .values({ subject_type: 'repository', subject_id: id, user_id: userId, reason: 'watching' }).execute()
8194 await db.insertInto('repository_labels')
8295 .values({ repository_id: id, name: 'bug', color: '#f00', description: '', is_default: true }).execute()
8396