Some checks failed
Deploy to Staging / Build Images (pull_request) Successful in 6m41s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 52s
Deploy to Staging / Verify Staging (pull_request) Failing after 4m7s
Deploy to Staging / Notify Staging Ready (pull_request) Has been skipped
Deploy to Staging / Notify Staging Failure (pull_request) Successful in 9s
Backend test fixtures: - Replace auth0|xxx format with UUID in all test userId values - Update admin tests for new id/userProfileId schema - Add missing deletionRequestedAt/deletionScheduledFor to auth test mocks - Fix admin integration test supertest usage (app.server) Frontend: - AdminUser type: auth0Sub -> id + userProfileId - admin.api.ts: all user management methods use userId (UUID) params - useUsers/useAdmins hooks: auth0Sub -> userId/id in mutations - AdminUsersPage + AdminUsersMobileScreen: user.auth0Sub -> user.id - Remove encodeURIComponent (UUIDs don't need encoding) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
70 lines
1.9 KiB
TypeScript
70 lines
1.9 KiB
TypeScript
/**
|
|
* @ai-summary Tests for AdminUsersPage component
|
|
*/
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
import { BrowserRouter } from 'react-router-dom';
|
|
import { AdminUsersPage } from '../../../pages/admin/AdminUsersPage';
|
|
import { useAdminAccess } from '../../../core/auth/useAdminAccess';
|
|
import { ReactElement } from 'react';
|
|
|
|
jest.mock('../../../core/auth/useAdminAccess');
|
|
|
|
const mockUseAdminAccess = useAdminAccess as jest.MockedFunction<typeof useAdminAccess>;
|
|
|
|
const renderWithRouter = (component: ReactElement) => {
|
|
return render(<BrowserRouter>{component}</BrowserRouter>);
|
|
};
|
|
|
|
describe('AdminUsersPage', () => {
|
|
it('should show loading state', () => {
|
|
mockUseAdminAccess.mockReturnValue({
|
|
isAdmin: false,
|
|
adminRecord: null,
|
|
loading: true,
|
|
error: null,
|
|
});
|
|
|
|
renderWithRouter(<AdminUsersPage />);
|
|
|
|
expect(screen.getByRole('progressbar')).toBeInTheDocument();
|
|
});
|
|
|
|
it('should redirect non-admin users', () => {
|
|
mockUseAdminAccess.mockReturnValue({
|
|
isAdmin: false,
|
|
adminRecord: null,
|
|
loading: false,
|
|
error: null,
|
|
});
|
|
|
|
renderWithRouter(<AdminUsersPage />);
|
|
|
|
// Component redirects, so we won't see the page content
|
|
expect(screen.queryByText('User Management')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('should render page for admin users', () => {
|
|
mockUseAdminAccess.mockReturnValue({
|
|
isAdmin: true,
|
|
adminRecord: {
|
|
id: 'admin-uuid-123',
|
|
userProfileId: 'user-uuid-123',
|
|
email: 'admin@example.com',
|
|
role: 'admin',
|
|
createdAt: '2024-01-01',
|
|
createdBy: 'system',
|
|
revokedAt: null,
|
|
updatedAt: '2024-01-01',
|
|
},
|
|
loading: false,
|
|
error: null,
|
|
});
|
|
|
|
renderWithRouter(<AdminUsersPage />);
|
|
|
|
expect(screen.getByText('User Management')).toBeInTheDocument();
|
|
expect(screen.getByText('Admin Users')).toBeInTheDocument();
|
|
});
|
|
});
|