- Introduced layout components for multiple admin dashboard sections including events, audit logs, bank accounts, blog articles, bookings, chat oversight, cities, contact messages, dashboard, discount codes, event categories, guest lists, identity verifications, manage events, manual notifications, notification rules, payments, provinces, push deliveries, reviews, settlements, sms messages, support tickets, user reports, and users. - Updated metadata for the auth layout to include the admin page title. - Modified branch protection documentation to clarify deployment notifications.
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
import type { BrowserContext, Page } from '@playwright/test'
|
|
|
|
import { REFRESH_TOKEN_COOKIE_DEV } from '@/lib/refreshSessionCookie'
|
|
|
|
export const createAccessToken = (role: 'admin' | 'user' = 'user') => {
|
|
const payload = Buffer.from(
|
|
JSON.stringify({
|
|
sub: `${role}-id`,
|
|
role,
|
|
sessionId: `${role}-session`,
|
|
exp: Math.floor(Date.now() / 1000) + 3600,
|
|
})
|
|
).toString('base64url')
|
|
|
|
return `header.${payload}.signature`
|
|
}
|
|
|
|
export const E2E_MOCK_REFRESH_TOKEN = 'e2e-mock-refresh-token'
|
|
|
|
export const nestRefreshCookie = (value = E2E_MOCK_REFRESH_TOKEN) => ({
|
|
name: REFRESH_TOKEN_COOKIE_DEV,
|
|
value,
|
|
domain: '127.0.0.1',
|
|
path: '/',
|
|
httpOnly: true as const,
|
|
sameSite: 'Lax' as const,
|
|
})
|
|
|
|
export async function authenticateAs(context: BrowserContext, page: Page, role: 'admin' | 'user' = 'user') {
|
|
const accessToken = createAccessToken(role)
|
|
const expiresAt = Date.now() + 30 * 24 * 60 * 60 * 1000
|
|
|
|
await context.addCookies([
|
|
{ name: 'accessToken', value: accessToken, domain: '127.0.0.1', path: '/' },
|
|
nestRefreshCookie(),
|
|
{ name: 'userRole', value: role, domain: '127.0.0.1', path: '/' },
|
|
{ name: 'userStatus', value: 'active', domain: '127.0.0.1', path: '/' },
|
|
])
|
|
await page.addInitScript(
|
|
({ token, refreshExpiry, userRole }) => {
|
|
localStorage.setItem(
|
|
'user',
|
|
JSON.stringify({
|
|
accessToken: token,
|
|
userId: `${userRole}-id`,
|
|
role: userRole,
|
|
sessionId: `${userRole}-session`,
|
|
AccessTokenExpireTime: Date.now() + 3600_000,
|
|
refreshTokenExpireTime: refreshExpiry,
|
|
status: 'active',
|
|
})
|
|
)
|
|
},
|
|
{ token: accessToken, refreshExpiry: expiresAt, userRole: role }
|
|
)
|
|
}
|