test(engine): run economic actions at month boundaries
This commit is contained in:
@@ -5,6 +5,7 @@ import { createGamePostgresConnector, type GamePrismaClient } from '@sammo-ts/in
|
||||
import { createDatabaseTurnHooks } from '../src/turn/databaseHooks.js';
|
||||
import { InMemoryTurnWorld } from '../src/turn/inMemoryWorld.js';
|
||||
import { createProcessSemiAnnualHandler } from '../src/turn/monthlySemiAnnualAction.js';
|
||||
import { createMonthlyEventHandler } from '../src/turn/monthlyEventHandler.js';
|
||||
import type { TurnGeneral, TurnWorldSnapshot, TurnWorldState } from '../src/turn/types.js';
|
||||
|
||||
const databaseUrl = process.env.INPUT_EVENT_DATABASE_URL;
|
||||
@@ -169,8 +170,8 @@ integration('monthly semi-annual database persistence', () => {
|
||||
const row = await db.worldState.create({
|
||||
data: {
|
||||
scenarioCode: 'monthly-semi-annual-persistence',
|
||||
currentYear: 193,
|
||||
currentMonth: 1,
|
||||
currentYear: 192,
|
||||
currentMonth: 12,
|
||||
tickSeconds: 600,
|
||||
config: {},
|
||||
meta: {},
|
||||
@@ -178,8 +179,8 @@ integration('monthly semi-annual database persistence', () => {
|
||||
});
|
||||
const state: TurnWorldState = {
|
||||
id: row.id,
|
||||
currentYear: 193,
|
||||
currentMonth: 1,
|
||||
currentYear: 192,
|
||||
currentMonth: 12,
|
||||
tickSeconds: 600,
|
||||
lastTurnTime: new Date('2026-07-25T00:10:00.000Z'),
|
||||
meta: {},
|
||||
@@ -203,27 +204,32 @@ integration('monthly semi-annual database persistence', () => {
|
||||
nations: [nation],
|
||||
troops: [],
|
||||
diplomacy: [],
|
||||
events: [],
|
||||
events: [
|
||||
{
|
||||
id: 1,
|
||||
targetCode: 'month',
|
||||
priority: 0,
|
||||
condition: true,
|
||||
action: [['ProcessSemiAnnual', 'gold']],
|
||||
meta: {},
|
||||
},
|
||||
],
|
||||
initialEvents: [],
|
||||
};
|
||||
const world = new InMemoryTurnWorld(state, snapshot, {
|
||||
let world: InMemoryTurnWorld | null = null;
|
||||
const actions = new Map([['ProcessSemiAnnual', createProcessSemiAnnualHandler({ getWorld: () => world })]]);
|
||||
world = new InMemoryTurnWorld(state, snapshot, {
|
||||
schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] },
|
||||
calendarHandler: createMonthlyEventHandler({
|
||||
getWorld: () => world,
|
||||
startYear: 190,
|
||||
actions,
|
||||
}),
|
||||
});
|
||||
const dbHooks = await createDatabaseTurnHooks(databaseUrl!, world);
|
||||
|
||||
try {
|
||||
const handler = createProcessSemiAnnualHandler({ getWorld: () => world });
|
||||
await handler(
|
||||
['gold'],
|
||||
{
|
||||
year: 193,
|
||||
month: 1,
|
||||
startyear: 190,
|
||||
currentEventID: 1,
|
||||
turnTime: state.lastTurnTime,
|
||||
},
|
||||
{ id: 1, targetCode: 'month', priority: 0, condition: true, action: [], meta: {} }
|
||||
);
|
||||
await world.advanceMonth(new Date('0193-01-01T00:00:00.000Z'));
|
||||
await dbHooks.hooks.flushChanges?.({
|
||||
lastTurnTime: state.lastTurnTime.toISOString(),
|
||||
processedGenerals: 0,
|
||||
|
||||
Reference in New Issue
Block a user