Skip to content

Commit 5d76373

Browse files
committed
fix: update reputation controller test to match guard-wired endpoint
1 parent eaf8815 commit 5d76373

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

test/unit/modules/reputation/reputation.controller.spec.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Test, TestingModule } from '@nestjs/testing';
2-
import { BadRequestException, UnauthorizedException } from '@nestjs/common';
2+
import { BadRequestException } from '@nestjs/common';
33
import { ReputationController } from '../../../../src/modules/reputation/reputation.controller';
44
import { ReputationService } from '../../../../src/modules/reputation/reputation.service';
55

@@ -99,9 +99,28 @@ describe('ReputationController', () => {
9999
// GET /reputation/me
100100
// ---------------------------------------------------------------------------
101101
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',
105124
);
106125
});
107126
});

0 commit comments

Comments
 (0)