feat(combat): add HTTP controllers for starting, reading, and acting on combats
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
41
apps/api/src/combat/hunt-encounter-attack.controller.spec.ts
Normal file
41
apps/api/src/combat/hunt-encounter-attack.controller.spec.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
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 { CombatService } from './combat.service';
|
||||
import { HuntEncounterAttackController } from './hunt-encounter-attack.controller';
|
||||
|
||||
describe('HuntEncounterAttackController', () => {
|
||||
let app: INestApplication<App>;
|
||||
const startCombat = jest.fn();
|
||||
|
||||
beforeEach(async () => {
|
||||
startCombat.mockReset();
|
||||
const module = await Test.createTestingModule({
|
||||
controllers: [HuntEncounterAttackController],
|
||||
providers: [{ provide: CombatService, useValue: { startCombat } }],
|
||||
}).compile();
|
||||
|
||||
app = module.createNestApplication<App>();
|
||||
configureApplication(app);
|
||||
await app.init();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
it('delegates to combatService.startCombat with the demo character id and the encounter id', async () => {
|
||||
const combat = { id: 'combat-1', status: 'ACTIVE', round: 1, player: {}, monster: {}, events: [] };
|
||||
startCombat.mockResolvedValue(combat);
|
||||
|
||||
const response = await request(app.getHttpServer())
|
||||
.post('/api/hunt-encounters/encounter-1/attack')
|
||||
.expect(201);
|
||||
|
||||
expect(startCombat).toHaveBeenCalledWith(DEMO_CHARACTER_ID, 'encounter-1');
|
||||
expect(response.body).toEqual(combat);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user