1- import { Test , TestingModule } from '@nestjs/testing' ;
2- import { ExecutionContext , UnauthorizedException } from '@nestjs/common' ;
3- import { SignatureAuthGuard } from './signature.auth' ;
4- import { verifySignature } from '../utils/signature' ;
51import { ChainId , EscrowUtils } from '@human-protocol/sdk' ;
6- import { AuthSignatureRole } from '../enums/role' ;
7- import { HEADER_SIGNATURE_KEY } from '../constant' ;
8- import { AssignmentRepository } from '../../modules/assignment/assignment.repository' ;
2+ import { ExecutionContext } from '@nestjs/common' ;
93import { Reflector } from '@nestjs/core' ;
4+ import { Test , TestingModule } from '@nestjs/testing' ;
5+ import { AssignmentRepository } from '../../modules/assignment/assignment.repository' ;
6+ import { HEADER_SIGNATURE_KEY } from '../constant' ;
7+ import { AuthSignatureRole } from '../enums/role' ;
8+ import { AuthError , NotFoundError } from '../errors' ;
9+ import { verifySignature } from '../utils/signature' ;
10+ import { SignatureAuthGuard } from './signature.auth' ;
1011
1112jest . mock ( '../utils/signature' ) ;
1213jest . mock ( '@human-protocol/sdk' , ( ) => ( {
@@ -84,7 +85,7 @@ describe('SignatureAuthGuard', () => {
8485 ) ;
8586 } ) ;
8687
87- it ( 'should throw UnauthorizedException if signature is not verified' , async ( ) => {
88+ it ( 'should throw AuthError if signature is not verified' , async ( ) => {
8889 reflector . get = jest
8990 . fn ( )
9091 . mockReturnValue ( [ AuthSignatureRole . JobLauncher ] ) ;
@@ -96,9 +97,7 @@ describe('SignatureAuthGuard', () => {
9697 } ;
9798 ( verifySignature as jest . Mock ) . mockReturnValue ( false ) ;
9899
99- await expect ( guard . canActivate ( context ) ) . rejects . toThrow (
100- UnauthorizedException ,
101- ) ;
100+ await expect ( guard . canActivate ( context ) ) . rejects . toThrow ( AuthError ) ;
102101 } ) ;
103102
104103 it ( 'should handle Worker role and verify signature' , async ( ) => {
@@ -118,7 +117,7 @@ describe('SignatureAuthGuard', () => {
118117 expect ( assignmentRepository . findOneById ) . toHaveBeenCalledWith ( '1' ) ;
119118 } ) ;
120119
121- it ( 'should throw UnauthorizedException if assignment is not found for Worker role' , async ( ) => {
120+ it ( 'should throw AuthError if assignment is not found for Worker role' , async ( ) => {
122121 reflector . get = jest . fn ( ) . mockReturnValue ( [ AuthSignatureRole . Worker ] ) ;
123122
124123 mockRequest . headers [ HEADER_SIGNATURE_KEY ] = 'validSignature' ;
@@ -128,9 +127,7 @@ describe('SignatureAuthGuard', () => {
128127 ( verifySignature as jest . Mock ) . mockReturnValue ( true ) ;
129128 assignmentRepository . findOneById . mockResolvedValue ( null ) ;
130129
131- await expect ( guard . canActivate ( context ) ) . rejects . toThrow (
132- UnauthorizedException ,
133- ) ;
130+ await expect ( guard . canActivate ( context ) ) . rejects . toThrow ( NotFoundError ) ;
134131 } ) ;
135132
136133 it ( 'should handle multiple roles and verify signature' , async ( ) => {
0 commit comments