Skip to content

Commit

Permalink
♻️ pull thresholds for now - include new auth file
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Aug 21, 2024
1 parent 236e92d commit fd2f36b
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { $fetch } from '@nuxt/test-utils/e2e'
import type { User } from '~/types/models'
import { createUser } from '~~/server/utils/user'

const users = [
{
session: {} as User,
cookie: '',
email: '[email protected]',
name: 'Test User',
avatar: 'https://avatars.githubusercontent.com/u/31337?v=4',
payload: {
roles: {
admin: false,
},
},
},
{
session: {} as User,
cookie: undefined,
email: '[email protected]',
name: 'Admin User',
avatar: 'https://avatars.githubusercontent.com/u/31337?v=4',
payload: {
roles: {
admin: true,
},
},
},
]

async function setupUsers() {
await Promise.all(users.map(async (userData) => {
userData.session = await createUser(userData, 'github', {})
}))
}

async function actingAs(email: string) {
const user = users.find(user => user.email === email)
if (!user) throw new Error('User not found')
const { data } = await $fetch('/api/test/session', { method: 'POST', body: { id: user?.session?.id.toString(), hash: user?.session?.hash } })
user.cookie = data.cookie[1].split(';')[0] as string
const get = (url: string) => $fetch(url, { headers: { cookie: user.cookie as string } })
return { get }
}

export {
users,
setupUsers,
actingAs,
}

0 comments on commit fd2f36b

Please sign in to comment.