Add quality gates and baseline tests for web/mobile
This commit is contained in:
25
apps/web/src/features/auth/roleUtils.test.ts
Normal file
25
apps/web/src/features/auth/roleUtils.test.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { getDashboardPath, normalizeRole } from './roleUtils'
|
||||
|
||||
describe('roleUtils', () => {
|
||||
it('normalizes lowercase and uppercase roles', () => {
|
||||
expect(normalizeRole('admin')).toBe('admin')
|
||||
expect(normalizeRole('CLIENT')).toBe('client')
|
||||
expect(normalizeRole('Vendor')).toBe('vendor')
|
||||
})
|
||||
|
||||
it('returns null for unsupported roles', () => {
|
||||
expect(normalizeRole('super_admin')).toBeNull()
|
||||
expect(normalizeRole('')).toBeNull()
|
||||
})
|
||||
|
||||
it('maps known roles to the proper dashboard path', () => {
|
||||
expect(getDashboardPath('admin')).toBe('/dashboard/admin')
|
||||
expect(getDashboardPath('CLIENT')).toBe('/dashboard/client')
|
||||
expect(getDashboardPath('vendor')).toBe('/dashboard/vendor')
|
||||
})
|
||||
|
||||
it('falls back to client dashboard for unknown roles', () => {
|
||||
expect(getDashboardPath('unknown')).toBe('/dashboard/client')
|
||||
})
|
||||
})
|
||||
30
apps/web/src/features/auth/roleUtils.ts
Normal file
30
apps/web/src/features/auth/roleUtils.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
export type Role = 'admin' | 'client' | 'vendor'
|
||||
export type RawRole = Role | Uppercase<Role> | string
|
||||
|
||||
const DEFAULT_DASHBOARD_PATH = '/dashboard/client'
|
||||
|
||||
const ROLE_TO_DASHBOARD: Record<Role, string> = {
|
||||
admin: '/dashboard/admin',
|
||||
client: '/dashboard/client',
|
||||
vendor: '/dashboard/vendor',
|
||||
}
|
||||
|
||||
export const normalizeRole = (role: RawRole): Role | null => {
|
||||
const normalizedRole = role.toLowerCase()
|
||||
|
||||
if (normalizedRole === 'admin' || normalizedRole === 'client' || normalizedRole === 'vendor') {
|
||||
return normalizedRole
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export const getDashboardPath = (role: RawRole): string => {
|
||||
const normalizedRole = normalizeRole(role)
|
||||
|
||||
if (!normalizedRole) {
|
||||
return DEFAULT_DASHBOARD_PATH
|
||||
}
|
||||
|
||||
return ROLE_TO_DASHBOARD[normalizedRole]
|
||||
}
|
||||
Reference in New Issue
Block a user