53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
import 'reflect-metadata';
|
|
import { getMetadataArgsStorage } from 'typeorm';
|
|
import { CharacterEquipment } from '../../equipment/entities/character-equipment.entity';
|
|
|
|
describe('character_equipment schema', () => {
|
|
it('stores slot as a non-nullable equipment_slot_enum column', () => {
|
|
const metadata = getMetadataArgsStorage();
|
|
const column = metadata.columns.find(
|
|
(candidate) =>
|
|
candidate.target === CharacterEquipment && candidate.propertyName === 'slot',
|
|
);
|
|
|
|
expect(column).toBeDefined();
|
|
expect(column?.options.type).toBe('enum');
|
|
expect(column?.options.enumName).toBe('equipment_slot_enum');
|
|
expect(column?.options.nullable).toBeFalsy();
|
|
});
|
|
|
|
it('enforces one equipped item per character per slot', () => {
|
|
const metadata = getMetadataArgsStorage();
|
|
const index = metadata.indices.find(
|
|
(candidate) =>
|
|
candidate.target === CharacterEquipment &&
|
|
candidate.columns?.includes('characterId') &&
|
|
candidate.columns?.includes('slot'),
|
|
);
|
|
|
|
expect(index).toBeDefined();
|
|
const indexMetadata = index as typeof index & {
|
|
options?: { unique?: boolean };
|
|
unique?: boolean;
|
|
};
|
|
expect(indexMetadata?.options?.unique ?? indexMetadata?.unique).toBe(true);
|
|
});
|
|
|
|
it('forbids one CharacterItem from occupying more than one equipment slot', () => {
|
|
const metadata = getMetadataArgsStorage();
|
|
const index = metadata.indices.find(
|
|
(candidate) =>
|
|
candidate.target === CharacterEquipment &&
|
|
candidate.columns?.length === 1 &&
|
|
candidate.columns?.includes('characterItemId'),
|
|
);
|
|
|
|
expect(index).toBeDefined();
|
|
const indexMetadata = index as typeof index & {
|
|
options?: { unique?: boolean };
|
|
unique?: boolean;
|
|
};
|
|
expect(indexMetadata?.options?.unique ?? indexMetadata?.unique).toBe(true);
|
|
});
|
|
});
|