Skip to content

Commit

Permalink
Fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
w3bdesign committed Jan 26, 2025
1 parent 9f1af07 commit 1db9b20
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions backend/src/auth/guards/jwt-auth.guard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,12 @@ describe('JwtAuthGuard', () => {
}

const testErrorScenario = (
error: Error | null,
error: Error | string | null,
info: JwtError | null,
expectedError: UnauthorizedException | Error
) => {
expect(() => guard.handleRequest(error, false, info)).toThrow(expectedError);
};

const testStringErrorScenario = (
errorMessage: string,
info: JwtError | null,
expectedError: UnauthorizedException | Error
) => {
const error = new Error(errorMessage);
expect(() => guard.handleRequest(error, false, info)).toThrow(expectedError);
const finalError = typeof error === 'string' ? new Error(error) : error;
expect(() => guard.handleRequest(finalError, false, info)).toThrow(expectedError);
};

it('should return user when authentication is successful', () => {
Expand All @@ -132,7 +124,12 @@ describe('JwtAuthGuard', () => {
expect(result).toBe(user);
});

const errorScenarios = [
const errorScenarios: Array<{
description: string;
error: Error | string | null;
info: JwtError | null;
expectedError: UnauthorizedException | Error;
}> = [
{
description: 'user not authenticated',
error: null,
Expand Down Expand Up @@ -166,7 +163,7 @@ describe('JwtAuthGuard', () => {

it('should convert non-Error error to UnauthorizedException', () => {
const errorMessage = 'string error';
testStringErrorScenario(
testErrorScenario(
errorMessage,
null,
new UnauthorizedException(errorMessage)
Expand Down

0 comments on commit 1db9b20

Please sign in to comment.