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:
@@ -2,6 +2,7 @@ import { Module } from '@nestjs/common';
|
|||||||
import { CharactersModule } from './characters/characters.module';
|
import { CharactersModule } from './characters/characters.module';
|
||||||
import { DatabaseModule } from './database/database.module';
|
import { DatabaseModule } from './database/database.module';
|
||||||
import { HealthModule } from './health/health.module';
|
import { HealthModule } from './health/health.module';
|
||||||
|
import { HuntingModule } from './hunting/hunting.module';
|
||||||
import { TravelModule } from './travel/travel.module';
|
import { TravelModule } from './travel/travel.module';
|
||||||
import { WorldModule } from './world/world.module';
|
import { WorldModule } from './world/world.module';
|
||||||
|
|
||||||
@@ -12,6 +13,7 @@ import { WorldModule } from './world/world.module';
|
|||||||
CharactersModule,
|
CharactersModule,
|
||||||
TravelModule,
|
TravelModule,
|
||||||
WorldModule,
|
WorldModule,
|
||||||
|
HuntingModule,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
13
apps/api/src/hunting/hunting.controller.ts
Normal file
13
apps/api/src/hunting/hunting.controller.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { Controller, Post } from '@nestjs/common';
|
||||||
|
import { DEMO_CHARACTER_ID } from '../demo/demo-character.constants';
|
||||||
|
import { HuntResultDto, HuntingService } from './hunting.service';
|
||||||
|
|
||||||
|
@Controller('hunts')
|
||||||
|
export class HuntingController {
|
||||||
|
constructor(private readonly huntingService: HuntingService) {}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
startHunt(): Promise<HuntResultDto> {
|
||||||
|
return this.huntingService.startHunt(DEMO_CHARACTER_ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
apps/api/src/hunting/hunting.module.ts
Normal file
30
apps/api/src/hunting/hunting.module.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { Character } from '../characters/entities/character.entity';
|
||||||
|
import { LocationMonster } from '../monsters/entities/location-monster.entity';
|
||||||
|
import { MonsterDefinition } from '../monsters/entities/monster-definition.entity';
|
||||||
|
import { TravelModule } from '../travel/travel.module';
|
||||||
|
import { Hunt } from './entities/hunt.entity';
|
||||||
|
import { HuntEncounter } from './entities/hunt-encounter.entity';
|
||||||
|
import { HuntingController } from './hunting.controller';
|
||||||
|
import { HuntingService } from './hunting.service';
|
||||||
|
import { RANDOM_SOURCE, systemRandomSource } from './random-source';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
TypeOrmModule.forFeature([
|
||||||
|
MonsterDefinition,
|
||||||
|
LocationMonster,
|
||||||
|
Hunt,
|
||||||
|
HuntEncounter,
|
||||||
|
Character,
|
||||||
|
]),
|
||||||
|
TravelModule,
|
||||||
|
],
|
||||||
|
controllers: [HuntingController],
|
||||||
|
providers: [
|
||||||
|
HuntingService,
|
||||||
|
{ provide: RANDOM_SOURCE, useValue: systemRandomSource },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
export class HuntingModule {}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { Character } from '../characters/entities/character.entity';
|
import { Character } from '../characters/entities/character.entity';
|
||||||
|
import { LocationMonster } from '../monsters/entities/location-monster.entity';
|
||||||
|
import { MonsterDefinition } from '../monsters/entities/monster-definition.entity';
|
||||||
import { TravelModule } from '../travel/travel.module';
|
import { TravelModule } from '../travel/travel.module';
|
||||||
import { LocationConnection } from './entities/location-connection.entity';
|
import { LocationConnection } from './entities/location-connection.entity';
|
||||||
import { WorldController } from './world.controller';
|
import { WorldController } from './world.controller';
|
||||||
@@ -8,7 +10,12 @@ import { WorldService } from './world.service';
|
|||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forFeature([Character, LocationConnection]),
|
TypeOrmModule.forFeature([
|
||||||
|
Character,
|
||||||
|
LocationConnection,
|
||||||
|
LocationMonster,
|
||||||
|
MonsterDefinition,
|
||||||
|
]),
|
||||||
TravelModule,
|
TravelModule,
|
||||||
],
|
],
|
||||||
controllers: [WorldController],
|
controllers: [WorldController],
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
BURNED_ROAD_ID,
|
BURNED_ROAD_ID,
|
||||||
SOUTH_GATE_ID,
|
SOUTH_GATE_ID,
|
||||||
} from '../database/seeds/vertical-slice.constants';
|
} from '../database/seeds/vertical-slice.constants';
|
||||||
|
import { LocationMonster } from '../monsters/entities/location-monster.entity';
|
||||||
import { TravelService } from '../travel/travel.service';
|
import { TravelService } from '../travel/travel.service';
|
||||||
import { LocationConnection } from './entities/location-connection.entity';
|
import { LocationConnection } from './entities/location-connection.entity';
|
||||||
import { LocationDefinition } from './entities/location-definition.entity';
|
import { LocationDefinition } from './entities/location-definition.entity';
|
||||||
@@ -102,7 +103,16 @@ describe('WorldService', () => {
|
|||||||
const connections = {
|
const connections = {
|
||||||
find: findConnections,
|
find: findConnections,
|
||||||
} as unknown as Repository<LocationConnection>;
|
} as unknown as Repository<LocationConnection>;
|
||||||
const service = new WorldService(travelService, characters, connections);
|
const findLocationMonsters = jest.fn();
|
||||||
|
const locationMonsters = {
|
||||||
|
find: findLocationMonsters,
|
||||||
|
} as unknown as Repository<LocationMonster>;
|
||||||
|
const service = new WorldService(
|
||||||
|
travelService,
|
||||||
|
characters,
|
||||||
|
connections,
|
||||||
|
locationMonsters,
|
||||||
|
);
|
||||||
|
|
||||||
const result = await service.getCurrentLocation(CHARACTER_ID);
|
const result = await service.getCurrentLocation(CHARACTER_ID);
|
||||||
|
|
||||||
@@ -131,6 +141,7 @@ describe('WorldService', () => {
|
|||||||
danger: 'LOW',
|
danger: 'LOW',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
possibleMonsters: [],
|
||||||
});
|
});
|
||||||
expect(findCharacter).toHaveBeenCalledWith({
|
expect(findCharacter).toHaveBeenCalledWith({
|
||||||
where: { id: CHARACTER_ID },
|
where: { id: CHARACTER_ID },
|
||||||
@@ -140,6 +151,51 @@ describe('WorldService', () => {
|
|||||||
where: { fromLocationId: SOUTH_GATE_ID, enabled: true },
|
where: { fromLocationId: SOUTH_GATE_ID, enabled: true },
|
||||||
relations: { toLocation: true },
|
relations: { toLocation: true },
|
||||||
});
|
});
|
||||||
|
expect(findLocationMonsters).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the enabled monster pool by name, ordered by weight descending, when hunting is enabled', async () => {
|
||||||
|
const location = burnedRoad();
|
||||||
|
const travelService = {
|
||||||
|
completeTravelIfDue: jest.fn().mockResolvedValue({ status: 'IDLE' }),
|
||||||
|
} as unknown as TravelService;
|
||||||
|
const characters = {
|
||||||
|
findOne: jest.fn().mockResolvedValue({
|
||||||
|
id: CHARACTER_ID,
|
||||||
|
currentLocationId: BURNED_ROAD_ID,
|
||||||
|
currentLocation: location,
|
||||||
|
}),
|
||||||
|
} as unknown as Repository<Character>;
|
||||||
|
const connections = {
|
||||||
|
find: jest.fn().mockResolvedValue([]),
|
||||||
|
} as unknown as Repository<LocationConnection>;
|
||||||
|
const findLocationMonsters = jest
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValue([
|
||||||
|
{ monster: { name: 'Aschenratte' } },
|
||||||
|
{ monster: { name: 'Stra\u00dfenr\u00e4uber' } },
|
||||||
|
]);
|
||||||
|
const locationMonsters = {
|
||||||
|
find: findLocationMonsters,
|
||||||
|
} as unknown as Repository<LocationMonster>;
|
||||||
|
const service = new WorldService(
|
||||||
|
travelService,
|
||||||
|
characters,
|
||||||
|
connections,
|
||||||
|
locationMonsters,
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = await service.getCurrentLocation(CHARACTER_ID);
|
||||||
|
|
||||||
|
expect(result.possibleMonsters).toEqual([
|
||||||
|
'Aschenratte',
|
||||||
|
'Stra\u00dfenr\u00e4uber',
|
||||||
|
]);
|
||||||
|
expect(findLocationMonsters).toHaveBeenCalledWith({
|
||||||
|
where: { locationId: BURNED_ROAD_ID, enabled: true },
|
||||||
|
relations: { monster: true },
|
||||||
|
order: { weight: 'DESC' },
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports a missing character after travel completion', async () => {
|
it('reports a missing character after travel completion', async () => {
|
||||||
@@ -157,11 +213,21 @@ describe('WorldService', () => {
|
|||||||
const connections = {
|
const connections = {
|
||||||
find: findConnections,
|
find: findConnections,
|
||||||
} as unknown as Repository<LocationConnection>;
|
} as unknown as Repository<LocationConnection>;
|
||||||
const service = new WorldService(travelService, characters, connections);
|
const findLocationMonsters = jest.fn();
|
||||||
|
const locationMonsters = {
|
||||||
|
find: findLocationMonsters,
|
||||||
|
} as unknown as Repository<LocationMonster>;
|
||||||
|
const service = new WorldService(
|
||||||
|
travelService,
|
||||||
|
characters,
|
||||||
|
connections,
|
||||||
|
locationMonsters,
|
||||||
|
);
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
service.getCurrentLocation(CHARACTER_ID),
|
service.getCurrentLocation(CHARACTER_ID),
|
||||||
).rejects.toBeInstanceOf(NotFoundException);
|
).rejects.toBeInstanceOf(NotFoundException);
|
||||||
expect(findConnections).not.toHaveBeenCalled();
|
expect(findConnections).not.toHaveBeenCalled();
|
||||||
|
expect(findLocationMonsters).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Injectable, NotFoundException } from '@nestjs/common';
|
|||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { Character } from '../characters/entities/character.entity';
|
import { Character } from '../characters/entities/character.entity';
|
||||||
|
import { LocationMonster } from '../monsters/entities/location-monster.entity';
|
||||||
import { TravelService } from '../travel/travel.service';
|
import { TravelService } from '../travel/travel.service';
|
||||||
import { LocationConnection } from './entities/location-connection.entity';
|
import { LocationConnection } from './entities/location-connection.entity';
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ export interface CurrentLocationResponse {
|
|||||||
huntingEnabled: boolean;
|
huntingEnabled: boolean;
|
||||||
artworkPath: string;
|
artworkPath: string;
|
||||||
connections: CurrentLocationConnection[];
|
connections: CurrentLocationConnection[];
|
||||||
|
possibleMonsters: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -40,6 +42,8 @@ export class WorldService {
|
|||||||
private readonly characters: Repository<Character>,
|
private readonly characters: Repository<Character>,
|
||||||
@InjectRepository(LocationConnection)
|
@InjectRepository(LocationConnection)
|
||||||
private readonly connections: Repository<LocationConnection>,
|
private readonly connections: Repository<LocationConnection>,
|
||||||
|
@InjectRepository(LocationMonster)
|
||||||
|
private readonly locationMonsters: Repository<LocationMonster>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async getCurrentLocation(
|
async getCurrentLocation(
|
||||||
@@ -61,6 +65,10 @@ export class WorldService {
|
|||||||
});
|
});
|
||||||
const location = character.currentLocation;
|
const location = character.currentLocation;
|
||||||
|
|
||||||
|
const possibleMonsters = location.huntingEnabled
|
||||||
|
? await this.getPossibleMonsters(location.id)
|
||||||
|
: [];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: location.id,
|
id: location.id,
|
||||||
key: location.key,
|
key: location.key,
|
||||||
@@ -84,9 +92,19 @@ export class WorldService {
|
|||||||
travelDurationSeconds: connection.travelDurationSeconds,
|
travelDurationSeconds: connection.travelDurationSeconds,
|
||||||
danger: this.toDangerRating(connection.ambushChance),
|
danger: this.toDangerRating(connection.ambushChance),
|
||||||
})),
|
})),
|
||||||
|
possibleMonsters,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async getPossibleMonsters(locationId: string): Promise<string[]> {
|
||||||
|
const pool = await this.locationMonsters.find({
|
||||||
|
where: { locationId, enabled: true },
|
||||||
|
relations: { monster: true },
|
||||||
|
order: { weight: 'DESC' },
|
||||||
|
});
|
||||||
|
return pool.map((entry) => entry.monster.name);
|
||||||
|
}
|
||||||
|
|
||||||
private toDangerRating(ambushChance: string): 'LOW' | 'HIGH' {
|
private toDangerRating(ambushChance: string): 'LOW' | 'HIGH' {
|
||||||
return Number(ambushChance) <= 0.05 ? 'LOW' : 'HIGH';
|
return Number(ambushChance) <= 0.05 ? 'LOW' : 'HIGH';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { AppModule } from './../src/app.module';
|
|||||||
import { CharactersModule } from './../src/characters/characters.module';
|
import { CharactersModule } from './../src/characters/characters.module';
|
||||||
import { DatabaseModule } from './../src/database/database.module';
|
import { DatabaseModule } from './../src/database/database.module';
|
||||||
import { configureApplication } from './../src/app.config';
|
import { configureApplication } from './../src/app.config';
|
||||||
|
import { HuntingModule } from './../src/hunting/hunting.module';
|
||||||
import { TravelModule } from './../src/travel/travel.module';
|
import { TravelModule } from './../src/travel/travel.module';
|
||||||
import { WorldModule } from './../src/world/world.module';
|
import { WorldModule } from './../src/world/world.module';
|
||||||
|
|
||||||
@@ -21,6 +22,9 @@ class TestTravelModule {}
|
|||||||
@Module({})
|
@Module({})
|
||||||
class TestWorldModule {}
|
class TestWorldModule {}
|
||||||
|
|
||||||
|
@Module({})
|
||||||
|
class TestHuntingModule {}
|
||||||
|
|
||||||
describe('API (e2e)', () => {
|
describe('API (e2e)', () => {
|
||||||
let app: INestApplication<App>;
|
let app: INestApplication<App>;
|
||||||
|
|
||||||
@@ -36,6 +40,8 @@ describe('API (e2e)', () => {
|
|||||||
.useModule(TestTravelModule)
|
.useModule(TestTravelModule)
|
||||||
.overrideModule(WorldModule)
|
.overrideModule(WorldModule)
|
||||||
.useModule(TestWorldModule)
|
.useModule(TestWorldModule)
|
||||||
|
.overrideModule(HuntingModule)
|
||||||
|
.useModule(TestHuntingModule)
|
||||||
.compile();
|
.compile();
|
||||||
|
|
||||||
app = moduleFixture.createNestApplication();
|
app = moduleFixture.createNestApplication();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { AppModule } from './../src/app.module';
|
|||||||
import { CharactersModule } from './../src/characters/characters.module';
|
import { CharactersModule } from './../src/characters/characters.module';
|
||||||
import { DatabaseModule } from './../src/database/database.module';
|
import { DatabaseModule } from './../src/database/database.module';
|
||||||
import { configureApplication } from './../src/app.config';
|
import { configureApplication } from './../src/app.config';
|
||||||
|
import { HuntingModule } from './../src/hunting/hunting.module';
|
||||||
import { TravelModule } from './../src/travel/travel.module';
|
import { TravelModule } from './../src/travel/travel.module';
|
||||||
import { WorldModule } from './../src/world/world.module';
|
import { WorldModule } from './../src/world/world.module';
|
||||||
import { DEMO_CHARACTER_ID } from './../src/demo/demo-character.constants';
|
import { DEMO_CHARACTER_ID } from './../src/demo/demo-character.constants';
|
||||||
@@ -31,6 +32,9 @@ class TestTravelModule {}
|
|||||||
@Module({})
|
@Module({})
|
||||||
class TestWorldModule {}
|
class TestWorldModule {}
|
||||||
|
|
||||||
|
@Module({})
|
||||||
|
class TestHuntingModule {}
|
||||||
|
|
||||||
describe('Visible vertical slice smoke (e2e)', () => {
|
describe('Visible vertical slice smoke (e2e)', () => {
|
||||||
describe('without a developer database', () => {
|
describe('without a developer database', () => {
|
||||||
let app: INestApplication<App>;
|
let app: INestApplication<App>;
|
||||||
@@ -47,6 +51,8 @@ describe('Visible vertical slice smoke (e2e)', () => {
|
|||||||
.useModule(TestTravelModule)
|
.useModule(TestTravelModule)
|
||||||
.overrideModule(WorldModule)
|
.overrideModule(WorldModule)
|
||||||
.useModule(TestWorldModule)
|
.useModule(TestWorldModule)
|
||||||
|
.overrideModule(HuntingModule)
|
||||||
|
.useModule(TestHuntingModule)
|
||||||
.compile();
|
.compile();
|
||||||
|
|
||||||
app = moduleFixture.createNestApplication();
|
app = moduleFixture.createNestApplication();
|
||||||
@@ -153,9 +159,7 @@ describe('Visible vertical slice smoke (e2e)', () => {
|
|||||||
.expect(400);
|
.expect(400);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(
|
it('POST /api/travel starts a travel, rejects a concurrent start, and completes into the moved character (full happy path)', async () => {
|
||||||
'POST /api/travel starts a travel, rejects a concurrent start, and completes into the moved character (full happy path)',
|
|
||||||
async () => {
|
|
||||||
// `GET current-location` lazily completes any overdue travel left
|
// `GET current-location` lazily completes any overdue travel left
|
||||||
// behind by a previous run before we read the starting point, so
|
// behind by a previous run before we read the starting point, so
|
||||||
// this test is safe to re-run without a fresh seed.
|
// this test is safe to re-run without a fresh seed.
|
||||||
@@ -227,9 +231,95 @@ describe('Visible vertical slice smoke (e2e)', () => {
|
|||||||
.get('/api/world/current-location')
|
.get('/api/world/current-location')
|
||||||
.expect(200);
|
.expect(200);
|
||||||
expect(restoredLocation.body.id).toBe(originLocationId);
|
expect(restoredLocation.body.id).toBe(originLocationId);
|
||||||
},
|
}, 30_000);
|
||||||
30_000,
|
|
||||||
|
it('POST /api/hunts starts a hunt at burned-road, and a second call supersedes the first', async () => {
|
||||||
|
// Get to burned-road (the only hunting-enabled seeded location),
|
||||||
|
// remembering the origin so we can restore it afterwards and keep
|
||||||
|
// this test safely re-runnable.
|
||||||
|
const origin = await request(app.getHttpServer())
|
||||||
|
.get('/api/world/current-location')
|
||||||
|
.expect(200);
|
||||||
|
const originLocationId: string = origin.body.id;
|
||||||
|
const originLocationKey: string = origin.body.key;
|
||||||
|
|
||||||
|
let atBurnedRoad = origin.body;
|
||||||
|
if (originLocationKey !== 'burned-road') {
|
||||||
|
const toBurnedRoad = origin.body.connections.find(
|
||||||
|
(connection: { targetLocation: { key: string } }) =>
|
||||||
|
connection.targetLocation.key === 'burned-road',
|
||||||
);
|
);
|
||||||
|
expect(toBurnedRoad).toBeDefined();
|
||||||
|
|
||||||
|
await request(app.getHttpServer())
|
||||||
|
.post('/api/travel')
|
||||||
|
.send({ targetLocationId: toBurnedRoad.targetLocation.id })
|
||||||
|
.expect(201);
|
||||||
|
|
||||||
|
await pollUntilTravelCompletes(app, toBurnedRoad.travelDurationSeconds);
|
||||||
|
|
||||||
|
const arrived = await request(app.getHttpServer())
|
||||||
|
.get('/api/world/current-location')
|
||||||
|
.expect(200);
|
||||||
|
atBurnedRoad = arrived.body;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(atBurnedRoad.key).toBe('burned-road');
|
||||||
|
expect(atBurnedRoad.possibleMonsters).toEqual([
|
||||||
|
'Aschenratte',
|
||||||
|
'Straßenräuber',
|
||||||
|
]);
|
||||||
|
|
||||||
|
const firstHunt = await request(app.getHttpServer())
|
||||||
|
.post('/api/hunts')
|
||||||
|
.expect(201);
|
||||||
|
|
||||||
|
expect(typeof firstHunt.body.id).toBe('string');
|
||||||
|
expect(firstHunt.body.location).toMatchObject({ key: 'burned-road' });
|
||||||
|
expect(firstHunt.body.encounters).toHaveLength(3);
|
||||||
|
for (const encounter of firstHunt.body.encounters as Array<{
|
||||||
|
id: string;
|
||||||
|
monster: { key: string };
|
||||||
|
dangerRating: string;
|
||||||
|
}>) {
|
||||||
|
expect(typeof encounter.id).toBe('string');
|
||||||
|
expect(['ash-rat', 'road-bandit']).toContain(encounter.monster.key);
|
||||||
|
expect([
|
||||||
|
'WEAK',
|
||||||
|
'MATCH',
|
||||||
|
'STRONG',
|
||||||
|
'VERY_DANGEROUS',
|
||||||
|
'DEADLY',
|
||||||
|
]).toContain(encounter.dangerRating);
|
||||||
|
}
|
||||||
|
|
||||||
|
const secondHunt = await request(app.getHttpServer())
|
||||||
|
.post('/api/hunts')
|
||||||
|
.expect(201);
|
||||||
|
|
||||||
|
expect(typeof secondHunt.body.id).toBe('string');
|
||||||
|
expect(secondHunt.body.id).not.toBe(firstHunt.body.id);
|
||||||
|
|
||||||
|
// Restore the demo character to its original location so the suite
|
||||||
|
// stays safely re-runnable.
|
||||||
|
if (originLocationKey !== 'burned-road') {
|
||||||
|
const returnConnection = atBurnedRoad.connections.find(
|
||||||
|
(connection: { targetLocation: { id: string } }) =>
|
||||||
|
connection.targetLocation.id === originLocationId,
|
||||||
|
);
|
||||||
|
expect(returnConnection).toBeDefined();
|
||||||
|
|
||||||
|
await request(app.getHttpServer())
|
||||||
|
.post('/api/travel')
|
||||||
|
.send({ targetLocationId: originLocationId })
|
||||||
|
.expect(201);
|
||||||
|
|
||||||
|
await pollUntilTravelCompletes(
|
||||||
|
app,
|
||||||
|
returnConnection.travelDurationSeconds,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, 30_000);
|
||||||
|
|
||||||
async function pollUntilTravelCompletes(
|
async function pollUntilTravelCompletes(
|
||||||
application: INestApplication<App>,
|
application: INestApplication<App>,
|
||||||
|
|||||||
Reference in New Issue
Block a user