Add quality gates and baseline tests for web/mobile

This commit is contained in:
zouantchaw
2026-02-12 23:21:25 -05:00
parent bda22f12ef
commit 6502a2f983
17 changed files with 543 additions and 20 deletions

View 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')
})
})

View 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]
}

View File

@@ -1,5 +1,6 @@
import { getFirestore, doc, getDoc } from "firebase/firestore";
import { app } from "../features/auth/firebase";
import { getDashboardPath as getDashboardPathFromRole } from "../features/auth/roleUtils";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - generated dataconnect types may not be resolvable in this context
import { getUserById } from "@/dataconnect-generated";
@@ -68,11 +69,5 @@ export const fetchUserData = async (uid: string): Promise<UserData | null> => {
* @returns The appropriate dashboard path
*/
export const getDashboardPath = (userRole: string): string => {
const roleMap: Record<string, string> = {
admin: "/dashboard/admin",
client: "/dashboard/client",
vendor: "/dashboard/vendor",
};
return roleMap[userRole.toLowerCase()] || "/dashboard/client";
return getDashboardPathFromRole(userRole);
};