feat: wire HuntingController/HuntingModule and enrich current-location with monster pool
Registers HuntingModule (POST /api/hunts) into the DI graph alongside its new entities, and adds possibleMonsters (enabled LocationMonster pool, weight-descending, empty when hunting is disabled) to WorldService.getCurrentLocation. Also updates the pre-existing DB-less app.e2e-spec.ts to override HuntingModule the same way the other feature modules already are, since it now needs a real DataSource.
This commit is contained in:
50
apps/api/src/hunting/hunting.controller.spec.ts
Normal file
50
apps/api/src/hunting/hunting.controller.spec.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
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 { HuntingController } from './hunting.controller';
|
||||
import { HuntingService } from './hunting.service';
|
||||
|
||||
describe('HuntingController', () => {
|
||||
let app: INestApplication<App>;
|
||||
const startHunt = jest.fn();
|
||||
|
||||
beforeEach(async () => {
|
||||
startHunt.mockReset();
|
||||
const module = await Test.createTestingModule({
|
||||
controllers: [HuntingController],
|
||||
providers: [
|
||||
{
|
||||
provide: HuntingService,
|
||||
useValue: { startHunt },
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
app = module.createNestApplication<App>();
|
||||
configureApplication(app);
|
||||
await app.init();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
it('delegates to huntingService.startHunt with the demo character id and returns its result', async () => {
|
||||
const huntResult = {
|
||||
id: 'hunt-1',
|
||||
location: { id: 'loc-1', key: 'burned-road', name: 'Verbrannte Strasse' },
|
||||
encounters: [],
|
||||
};
|
||||
startHunt.mockResolvedValue(huntResult);
|
||||
|
||||
const response = await request(app.getHttpServer())
|
||||
.post('/api/hunts')
|
||||
.expect(201);
|
||||
|
||||
expect(startHunt).toHaveBeenCalledWith(DEMO_CHARACTER_ID);
|
||||
expect(response.body).toEqual(huntResult);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user