Files
ashen-realms/apps/api/src/reputation/reputation.controller.spec.ts

49 lines
1.5 KiB
TypeScript

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);
});
});