|
1 | 1 | import { Test, TestingModule } from '@nestjs/testing'; |
2 | | -import { BadRequestException, UnauthorizedException } from '@nestjs/common'; |
| 2 | +import { BadRequestException } from '@nestjs/common'; |
3 | 3 | import { ReputationController } from '../../../../src/modules/reputation/reputation.controller'; |
4 | 4 | import { ReputationService } from '../../../../src/modules/reputation/reputation.service'; |
5 | 5 |
|
@@ -99,9 +99,28 @@ describe('ReputationController', () => { |
99 | 99 | // GET /reputation/me |
100 | 100 | // --------------------------------------------------------------------------- |
101 | 101 | describe('getMyScore', () => { |
102 | | - it('should throw UnauthorizedException since auth guard is not yet wired', async () => { |
103 | | - await expect(controller.getMyScore({})).rejects.toThrow( |
104 | | - UnauthorizedException, |
| 102 | + it('should return reputation data for the authenticated user', async () => { |
| 103 | + mockReputationService.getReputationScore.mockResolvedValue(mockReputationResponse); |
| 104 | + |
| 105 | + const req = { user: { wallet: validWallet } }; |
| 106 | + const result = await controller.getMyScore(req); |
| 107 | + |
| 108 | + expect(result).toEqual({ |
| 109 | + success: true, |
| 110 | + data: mockReputationResponse, |
| 111 | + message: 'Your reputation data retrieved successfully', |
| 112 | + }); |
| 113 | + expect(reputationService.getReputationScore).toHaveBeenCalledWith(validWallet); |
| 114 | + }); |
| 115 | + |
| 116 | + it('should propagate service errors to the caller', async () => { |
| 117 | + mockReputationService.getReputationScore.mockRejectedValue( |
| 118 | + new Error('Contract read failed'), |
| 119 | + ); |
| 120 | + |
| 121 | + const req = { user: { wallet: validWallet } }; |
| 122 | + await expect(controller.getMyScore(req)).rejects.toThrow( |
| 123 | + 'Contract read failed', |
105 | 124 | ); |
106 | 125 | }); |
107 | 126 | }); |
|
0 commit comments