Skip to content

Commit 44e250e

Browse files
style: fix formatting in auth tests
1 parent ac54426 commit 44e250e

1 file changed

Lines changed: 67 additions & 22 deletions

File tree

src/lib/auth.test.ts

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ function buildSupabaseMock({ role, dbError = false }: { role?: string; dbError?:
2525
from: vi.fn().mockReturnValue({
2626
select: vi.fn().mockReturnValue({
2727
eq: vi.fn().mockReturnValue({
28-
maybeSingle: vi.fn().mockResolvedValue(
29-
dbError
30-
? { data: null, error: new Error('db error') }
31-
: { data: role ? { role } : null, error: null }
32-
),
28+
maybeSingle: vi
29+
.fn()
30+
.mockResolvedValue(
31+
dbError
32+
? { data: null, error: new Error('db error') }
33+
: { data: role ? { role } : null, error: null }
34+
),
3335
}),
3436
}),
3537
}),
@@ -43,11 +45,16 @@ describe('requireRole', () => {
4345

4446
it('resolves without redirect when user has the correct role', async () => {
4547
mockGetUser.mockResolvedValue({
46-
user: { id: 'user-1', email: 'test@test.com' } as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
48+
user: {
49+
id: 'user-1',
50+
email: 'test@test.com',
51+
} as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
4752
error: null,
4853
});
4954
const supabase = buildSupabaseMock({ role: 'GERENTE' });
50-
mockCreateClient.mockResolvedValue(supabase as any /* eslint-disable-line @typescript-eslint/no-explicit-any */);
55+
mockCreateClient.mockResolvedValue(
56+
supabase as any /* eslint-disable-line @typescript-eslint/no-explicit-any */
57+
);
5158

5259
await requireRole('GERENTE');
5360

@@ -56,11 +63,16 @@ describe('requireRole', () => {
5663

5764
it('redirects to /dashboard when user has wrong role', async () => {
5865
mockGetUser.mockResolvedValue({
59-
user: { id: 'user-1', email: 'test@test.com' } as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
66+
user: {
67+
id: 'user-1',
68+
email: 'test@test.com',
69+
} as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
6070
error: null,
6171
});
6272
const supabase = buildSupabaseMock({ role: 'RECEPCIONISTA' });
63-
mockCreateClient.mockResolvedValue(supabase as any /* eslint-disable-line @typescript-eslint/no-explicit-any */);
73+
mockCreateClient.mockResolvedValue(
74+
supabase as any /* eslint-disable-line @typescript-eslint/no-explicit-any */
75+
);
6476

6577
await requireRole('GERENTE');
6678
expect(mockRedirect).toHaveBeenCalledWith('/dashboard');
@@ -76,7 +88,10 @@ describe('requireRole', () => {
7688
it('redirects to /login when Supabase auth returns an error and logs it', async () => {
7789
const loggerSpy = vi.spyOn(Logger, 'error').mockImplementation(() => undefined);
7890
const authError = new Error('auth error');
79-
mockGetUser.mockResolvedValue({ user: null, error: authError as any /* eslint-disable-line @typescript-eslint/no-explicit-any */ });
91+
mockGetUser.mockResolvedValue({
92+
user: null,
93+
error: authError as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
94+
});
8095

8196
await requireRole('GERENTE');
8297
expect(mockRedirect).toHaveBeenCalledWith('/login');
@@ -85,23 +100,33 @@ describe('requireRole', () => {
85100

86101
it('redirects to /dashboard (fail-closed) when DB query errors', async () => {
87102
mockGetUser.mockResolvedValue({
88-
user: { id: 'user-1', email: 'test@test.com' } as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
103+
user: {
104+
id: 'user-1',
105+
email: 'test@test.com',
106+
} as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
89107
error: null,
90108
});
91109
const supabase = buildSupabaseMock({ dbError: true });
92-
mockCreateClient.mockResolvedValue(supabase as any /* eslint-disable-line @typescript-eslint/no-explicit-any */);
110+
mockCreateClient.mockResolvedValue(
111+
supabase as any /* eslint-disable-line @typescript-eslint/no-explicit-any */
112+
);
93113

94114
await requireRole('GERENTE');
95115
expect(mockRedirect).toHaveBeenCalledWith('/dashboard');
96116
});
97117

98118
it('redirects to /dashboard when role is null (no funcionario record)', async () => {
99119
mockGetUser.mockResolvedValue({
100-
user: { id: 'user-1', email: 'test@test.com' } as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
120+
user: {
121+
id: 'user-1',
122+
email: 'test@test.com',
123+
} as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
101124
error: null,
102125
});
103126
const supabase = buildSupabaseMock({ role: undefined });
104-
mockCreateClient.mockResolvedValue(supabase as any /* eslint-disable-line @typescript-eslint/no-explicit-any */);
127+
mockCreateClient.mockResolvedValue(
128+
supabase as any /* eslint-disable-line @typescript-eslint/no-explicit-any */
129+
);
105130

106131
await requireRole('GERENTE');
107132
expect(mockRedirect).toHaveBeenCalledWith('/dashboard');
@@ -115,11 +140,16 @@ describe('requireAnyRole', () => {
115140

116141
it('resolves without redirect when user role is in the allowed list', async () => {
117142
mockGetUser.mockResolvedValue({
118-
user: { id: 'user-1', email: 'test@test.com' } as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
143+
user: {
144+
id: 'user-1',
145+
email: 'test@test.com',
146+
} as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
119147
error: null,
120148
});
121149
const supabase = buildSupabaseMock({ role: 'INSTRUTOR' });
122-
mockCreateClient.mockResolvedValue(supabase as any /* eslint-disable-line @typescript-eslint/no-explicit-any */);
150+
mockCreateClient.mockResolvedValue(
151+
supabase as any /* eslint-disable-line @typescript-eslint/no-explicit-any */
152+
);
123153

124154
await requireAnyRole(['INSTRUTOR', 'GERENTE']);
125155

@@ -128,11 +158,16 @@ describe('requireAnyRole', () => {
128158

129159
it('redirects to /dashboard when user role is not in the allowed list', async () => {
130160
mockGetUser.mockResolvedValue({
131-
user: { id: 'user-1', email: 'test@test.com' } as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
161+
user: {
162+
id: 'user-1',
163+
email: 'test@test.com',
164+
} as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
132165
error: null,
133166
});
134167
const supabase = buildSupabaseMock({ role: 'RECEPCIONISTA' });
135-
mockCreateClient.mockResolvedValue(supabase as any /* eslint-disable-line @typescript-eslint/no-explicit-any */);
168+
mockCreateClient.mockResolvedValue(
169+
supabase as any /* eslint-disable-line @typescript-eslint/no-explicit-any */
170+
);
136171

137172
await requireAnyRole(['INSTRUTOR', 'GERENTE']);
138173
expect(mockRedirect).toHaveBeenCalledWith('/dashboard');
@@ -147,23 +182,33 @@ describe('requireAnyRole', () => {
147182

148183
it('redirects to /dashboard (fail-closed) when DB query errors', async () => {
149184
mockGetUser.mockResolvedValue({
150-
user: { id: 'user-1', email: 'test@test.com' } as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
185+
user: {
186+
id: 'user-1',
187+
email: 'test@test.com',
188+
} as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
151189
error: null,
152190
});
153191
const supabase = buildSupabaseMock({ dbError: true });
154-
mockCreateClient.mockResolvedValue(supabase as any /* eslint-disable-line @typescript-eslint/no-explicit-any */);
192+
mockCreateClient.mockResolvedValue(
193+
supabase as any /* eslint-disable-line @typescript-eslint/no-explicit-any */
194+
);
155195

156196
await requireAnyRole(['INSTRUTOR', 'GERENTE']);
157197
expect(mockRedirect).toHaveBeenCalledWith('/dashboard');
158198
});
159199

160200
it('redirects to /dashboard when role is null (ALUNO — no funcionario record)', async () => {
161201
mockGetUser.mockResolvedValue({
162-
user: { id: 'user-1', email: 'test@test.com' } as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
202+
user: {
203+
id: 'user-1',
204+
email: 'test@test.com',
205+
} as any /* eslint-disable-line @typescript-eslint/no-explicit-any */,
163206
error: null,
164207
});
165208
const supabase = buildSupabaseMock({ role: undefined });
166-
mockCreateClient.mockResolvedValue(supabase as any /* eslint-disable-line @typescript-eslint/no-explicit-any */);
209+
mockCreateClient.mockResolvedValue(
210+
supabase as any /* eslint-disable-line @typescript-eslint/no-explicit-any */
211+
);
167212

168213
await requireAnyRole(['INSTRUTOR', 'GERENTE']);
169214
expect(mockRedirect).toHaveBeenCalledWith('/dashboard');

0 commit comments

Comments
 (0)