Skip to content

Commit

Permalink
Fix router authentication in a test context
Browse files Browse the repository at this point in the history
  • Loading branch information
farnoux committed Nov 25, 2024
1 parent 2529f8c commit f6030fb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { AuthenticatedUser } from './../../auth/models/auth.models';
import { inferProcedureInput } from '@trpc/server';
import { getYoloDodoUser } from '../../../test/auth/auth-utils';
import { getTestRouter } from '../../../test/common/app-utils';
import { User } from '../../auth/models/auth.models';
import { AppRouter, TrpcRouter } from '../../trpc/trpc.router';
import { FicheActionStatutsEnumType } from '../models/fiche-action.table';

type Input = inferProcedureInput<AppRouter['plans']['fiches']['countByStatut']>;

describe('CountByStatutRouter', () => {
let router: TrpcRouter;
let yoloDodoUser: User;
let yoloDodoUser: AuthenticatedUser;

beforeAll(async () => {
router = await getTestRouter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export class IndicateursController {
@Query() request: GetIndicateursValeursRequestClass,
@TokenInfo() tokenInfo: AuthenticatedUser
): Promise<GetIndicateursValeursResponseClass> {
console.log('tokenInfo', tokenInfo);
return this.indicateurService.getIndicateurValeursGroupees(
request,
tokenInfo
Expand Down
16 changes: 15 additions & 1 deletion backend/test/auth/auth-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { createClient, SupabaseClient } from '@supabase/supabase-js';
import { YOLO_DODO_CREDENTIALS } from './test-users.samples';
import {
AuthUser,
isAuthenticatedUser,
} from '../../src/auth/models/auth.models';

let supabase: SupabaseClient;

Expand Down Expand Up @@ -30,5 +34,15 @@ export async function getYoloDodoUser() {
expect.fail('Could not authenticated user yolododo');
}

return user;
const authUser = {
id: user.id,
role: user.role,
isAnonymous: user.is_anonymous,
} as AuthUser;

if (!isAuthenticatedUser(authUser)) {
expect.fail('Could not authenticated user yolododo');
}

return authUser;
}

0 comments on commit f6030fb

Please sign in to comment.