feat(reputation): add ReputationService, rank resolver integration, and GET /api/reputation
This commit is contained in:
48
apps/api/src/reputation/reputation.controller.spec.ts
Normal file
48
apps/api/src/reputation/reputation.controller.spec.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import request from 'supertest';
|
||||
import { App } from 'supertest/types';
|
||||
import { configureApplication } from '../app.config';
|
||||
import { DEMO_CHARACTER_ID } from '../demo/demo-character.constants';
|
||||
import { ReputationController } from './reputation.controller';
|
||||
import { ReputationService } from './reputation.service';
|
||||
|
||||
describe('ReputationController', () => {
|
||||
let app: INestApplication<App>;
|
||||
const getCharacterReputation = jest.fn();
|
||||
|
||||
beforeEach(async () => {
|
||||
getCharacterReputation.mockReset();
|
||||
const module = await Test.createTestingModule({
|
||||
controllers: [ReputationController],
|
||||
providers: [{ provide: ReputationService, useValue: { getCharacterReputation } }],
|
||||
}).compile();
|
||||
|
||||
app = module.createNestApplication<App>();
|
||||
configureApplication(app);
|
||||
await app.init();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
it('delegates GET /api/reputation to reputationService.getCharacterReputation', async () => {
|
||||
const entries = [
|
||||
{
|
||||
factionKey: 'border-guard',
|
||||
factionName: 'Grenzwacht',
|
||||
reputation: 40,
|
||||
rank: 'STRANGER',
|
||||
rankLabel: 'Fremder',
|
||||
nextThreshold: 100,
|
||||
},
|
||||
];
|
||||
getCharacterReputation.mockResolvedValue(entries);
|
||||
|
||||
const response = await request(app.getHttpServer()).get('/api/reputation').expect(200);
|
||||
|
||||
expect(getCharacterReputation).toHaveBeenCalledWith(DEMO_CHARACTER_ID);
|
||||
expect(response.body).toEqual(entries);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user