Design ruling R7 abolishes XP as a concept and says the column goes with it, but no task in the plan actually dropped it -- the plan only dropped characters.experience and combat_rewards.experience_granted. Task 9 removed experienceReward from the seed literals, leaving monster_definitions.experience_reward as a NOT NULL column with no default that nothing supplies. The first monster insert against a real database would have failed on a constraint violation. No suite here could have caught it: none of them connect to Postgres. Drops the column in the slice migration (which has never been run, so amending it in place is correct rather than stacking a second one), removes the entity field, and clears the three test fixtures that still set it. silver_min/silver_max deliberately stay -- spec 15 keeps a direct currency drop available as a lore-valid exception, and XP has no such carve-out. Also retargets the seed idempotency test off renown: 1, which is the seed's own default and so could not distinguish "preserved" from "reset to default". NOTE ON SCOPE: this commit also absorbs a Prettier reformatting pass that was already sitting uncommitted in the working tree, which is why it touches ~59 files. That churn is purely cosmetic line-rewrapping -- verified by inspection, and the suite is green at 267/267 with the build at exactly the 3 expected errors owned by Tasks 10 and 11. The repo is not Prettier-clean at baseline (119 files still flagged), so this was a partial run by an earlier step, not a deliberate repo-wide format. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
207 lines
7.6 KiB
TypeScript
207 lines
7.6 KiB
TypeScript
import { QueryRunner } from 'typeorm';
|
|
import { CreateRenownAndReputation1791000000000 } from './1791000000000-CreateRenownAndReputation';
|
|
|
|
describe('CreateRenownAndReputation1791000000000', () => {
|
|
async function runUp() {
|
|
const query = jest.fn().mockResolvedValue(undefined);
|
|
const queryRunner = { query } as unknown as QueryRunner;
|
|
const migration = new CreateRenownAndReputation1791000000000();
|
|
await migration.up(queryRunner);
|
|
return query.mock.calls.map(([sql]) => sql as string);
|
|
}
|
|
|
|
async function runUpThenDown() {
|
|
const query = jest.fn().mockResolvedValue(undefined);
|
|
const queryRunner = { query } as unknown as QueryRunner;
|
|
const migration = new CreateRenownAndReputation1791000000000();
|
|
await migration.up(queryRunner);
|
|
const upCount = query.mock.calls.length;
|
|
await migration.down(queryRunner);
|
|
return query.mock.calls.slice(upCount).map(([sql]) => sql as string);
|
|
}
|
|
|
|
it('replaces level/experience with a renown column on characters', async () => {
|
|
const up = await runUp();
|
|
|
|
expect(up).toEqual(
|
|
expect.arrayContaining([
|
|
expect.stringContaining('ALTER TABLE "characters" ADD COLUMN "renown"'),
|
|
expect.stringContaining('DROP COLUMN "level"'),
|
|
expect.stringContaining('DROP COLUMN "experience"'),
|
|
]),
|
|
);
|
|
});
|
|
|
|
it('backfills renown from level BEFORE dropping the level column', async () => {
|
|
const up = await runUp();
|
|
|
|
const backfillIndex = up.findIndex((sql) =>
|
|
sql.includes('LEAST(GREATEST("level", 1), 15)'),
|
|
);
|
|
const dropLevelIndex = up.findIndex((sql) =>
|
|
sql.includes('DROP COLUMN "level"'),
|
|
);
|
|
|
|
expect(backfillIndex).toBeGreaterThanOrEqual(0);
|
|
expect(dropLevelIndex).toBeGreaterThanOrEqual(0);
|
|
// Reversing these two would silently discard every character's progression.
|
|
expect(backfillIndex).toBeLessThan(dropLevelIndex);
|
|
});
|
|
|
|
it('adds the renown range constraint only AFTER the backfill has populated valid values', async () => {
|
|
const up = await runUp();
|
|
|
|
const backfillIndex = up.findIndex((sql) =>
|
|
sql.includes('LEAST(GREATEST("level", 1), 15)'),
|
|
);
|
|
const constraintIndex = up.findIndex((sql) =>
|
|
sql.includes('CHK_characters_renown'),
|
|
);
|
|
|
|
expect(backfillIndex).toBeGreaterThanOrEqual(0);
|
|
expect(constraintIndex).toBeGreaterThanOrEqual(0);
|
|
// ADD CONSTRAINT validates the whole table; running it before the backfill
|
|
// would only pass by coincidence of the column DEFAULT being in range.
|
|
expect(backfillIndex).toBeLessThan(constraintIndex);
|
|
});
|
|
|
|
it('drops required_level from item_definitions', async () => {
|
|
const up = await runUp();
|
|
|
|
expect(up).toEqual(
|
|
expect.arrayContaining([
|
|
expect.stringContaining(
|
|
'ALTER TABLE "item_definitions" DROP COLUMN "required_level"',
|
|
),
|
|
]),
|
|
);
|
|
});
|
|
|
|
it('rebuilds item_type_enum with exactly the five Slice 0.6.5 values, migrating existing rows', async () => {
|
|
const up = await runUp();
|
|
|
|
expect(up).toEqual(
|
|
expect.arrayContaining([
|
|
expect.stringContaining(
|
|
`SET "type" = 'EQUIPMENT' WHERE "type" IN ('WEAPON', 'ARMOR')`,
|
|
),
|
|
expect.stringContaining(
|
|
`SET "type" = 'TRADE_GOOD' WHERE "type" = 'MATERIAL'`,
|
|
),
|
|
expect.stringContaining('DROP TYPE "item_type_enum"'),
|
|
expect.stringContaining(
|
|
`CREATE TYPE "item_type_enum" AS ENUM ('EQUIPMENT', 'TRADE_GOOD', 'TROPHY', 'QUEST_ITEM', 'CONSUMABLE')`,
|
|
),
|
|
]),
|
|
);
|
|
});
|
|
|
|
it('drops experience_granted from combat_rewards', async () => {
|
|
const up = await runUp();
|
|
|
|
expect(up).toEqual(
|
|
expect.arrayContaining([
|
|
expect.stringContaining(
|
|
'ALTER TABLE "combat_rewards" DROP COLUMN "experience_granted"',
|
|
),
|
|
]),
|
|
);
|
|
});
|
|
|
|
/**
|
|
* XP is abolished outright (design R7), so the column goes with the concept.
|
|
* It is NOT NULL with no default, so leaving it behind while the seed stops
|
|
* supplying a value would fail every monster insert against a real database
|
|
* -- a break no suite here can catch, since none of them connect to Postgres.
|
|
*/
|
|
it('drops experience_reward from monster_definitions', async () => {
|
|
const up = await runUp();
|
|
|
|
expect(up).toEqual(
|
|
expect.arrayContaining([
|
|
expect.stringContaining(
|
|
'ALTER TABLE "monster_definitions" DROP COLUMN "experience_reward"',
|
|
),
|
|
]),
|
|
);
|
|
});
|
|
|
|
it('keeps silver_min and silver_max on monster_definitions', async () => {
|
|
const up = await runUp();
|
|
|
|
expect(up.join(' ')).not.toContain('"silver_min"');
|
|
expect(up.join(' ')).not.toContain('"silver_max"');
|
|
});
|
|
|
|
it('creates all five new tables with their unique constraints', async () => {
|
|
const up = await runUp();
|
|
|
|
expect(up).toEqual(
|
|
expect.arrayContaining([
|
|
expect.stringContaining('CREATE TABLE "reputation_factions"'),
|
|
expect.stringContaining(
|
|
'CREATE UNIQUE INDEX "IDX_reputation_factions_key"',
|
|
),
|
|
expect.stringContaining('CREATE TABLE "character_reputation"'),
|
|
expect.stringContaining(
|
|
'CREATE UNIQUE INDEX "IDX_character_reputation_character_faction" ON "character_reputation" ("character_id", "faction_id")',
|
|
),
|
|
expect.stringContaining('CREATE TABLE "renown_milestone_definitions"'),
|
|
expect.stringContaining(
|
|
'CREATE UNIQUE INDEX "IDX_renown_milestone_definitions_key"',
|
|
),
|
|
expect.stringContaining('CREATE TABLE "character_renown_milestones"'),
|
|
expect.stringContaining(
|
|
'CREATE UNIQUE INDEX "IDX_character_renown_milestones_character_milestone" ON "character_renown_milestones" ("character_id", "milestone_id")',
|
|
),
|
|
expect.stringContaining('CREATE TABLE "turn_in_definitions"'),
|
|
expect.stringContaining(
|
|
'CREATE UNIQUE INDEX "IDX_turn_in_definitions_key"',
|
|
),
|
|
]),
|
|
);
|
|
});
|
|
|
|
it('down() reverses every up() step in exact opposite order, dropping the five new tables first', async () => {
|
|
const down = await runUpThenDown();
|
|
|
|
expect(down).toEqual(
|
|
expect.arrayContaining([
|
|
expect.stringContaining('DROP TABLE "turn_in_definitions"'),
|
|
expect.stringContaining('DROP TABLE "character_renown_milestones"'),
|
|
expect.stringContaining('DROP TABLE "renown_milestone_definitions"'),
|
|
expect.stringContaining('DROP TABLE "character_reputation"'),
|
|
expect.stringContaining('DROP TABLE "reputation_factions"'),
|
|
expect.stringContaining(
|
|
'ALTER TABLE "monster_definitions" ADD COLUMN "experience_reward"',
|
|
),
|
|
expect.stringContaining(
|
|
'ALTER TABLE "combat_rewards" ADD COLUMN "experience_granted"',
|
|
),
|
|
expect.stringContaining(
|
|
'ALTER TABLE "item_definitions" ADD COLUMN "required_level"',
|
|
),
|
|
expect.stringContaining('ALTER TABLE "characters" ADD COLUMN "level"'),
|
|
expect.stringContaining(
|
|
'ALTER TABLE "characters" ADD COLUMN "experience"',
|
|
),
|
|
expect.stringContaining(
|
|
'ALTER TABLE "characters" DROP COLUMN "renown"',
|
|
),
|
|
]),
|
|
);
|
|
const turnInDropIndex = down.findIndex((sql) =>
|
|
sql.includes('DROP TABLE "turn_in_definitions"'),
|
|
);
|
|
const reputationFactionsDropIndex = down.findIndex((sql) =>
|
|
sql.includes('DROP TABLE "reputation_factions"'),
|
|
);
|
|
|
|
expect(turnInDropIndex).toBeGreaterThanOrEqual(0);
|
|
expect(reputationFactionsDropIndex).toBeGreaterThanOrEqual(0);
|
|
// turn_in_definitions has FK dependencies on reputation_factions and
|
|
// item_definitions that must be gone before those tables are touched.
|
|
expect(turnInDropIndex).toBeLessThan(reputationFactionsDropIndex);
|
|
});
|
|
});
|