42 lines
1.5 KiB
TypeScript
42 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 { 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: [], rewards: null };
|
|
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);
|
|
});
|
|
});
|