59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import { NotFoundException } from '@nestjs/common';
|
|
import { Repository } from 'typeorm';
|
|
import { DEMO_CHARACTER_ID } from '../demo/demo-character.constants';
|
|
import { SOUTH_GATE_ID } from '../database/seeds/vertical-slice.constants';
|
|
import { Character } from './entities/character.entity';
|
|
import { CharactersService } from './characters.service';
|
|
|
|
describe('CharactersService', () => {
|
|
it('returns the demo character with its current location summary', async () => {
|
|
const repository = {
|
|
findOne: jest.fn().mockResolvedValue({
|
|
id: DEMO_CHARACTER_ID,
|
|
name: 'Aric Duskwalker',
|
|
level: 1,
|
|
experience: 0,
|
|
currentHp: 100,
|
|
baseHp: 100,
|
|
baseAttack: 6,
|
|
currentLocation: {
|
|
id: SOUTH_GATE_ID,
|
|
key: 'south-gate',
|
|
name: 'S\u00fcdtor von Graufurt',
|
|
},
|
|
}),
|
|
} as unknown as Repository<Character>;
|
|
const service = new CharactersService(repository);
|
|
|
|
await expect(service.getDemoCharacter()).resolves.toEqual({
|
|
id: DEMO_CHARACTER_ID,
|
|
name: 'Aric Duskwalker',
|
|
level: 1,
|
|
experience: 0,
|
|
currentHp: 100,
|
|
maxHp: 100,
|
|
attack: 6,
|
|
currentLocation: {
|
|
id: SOUTH_GATE_ID,
|
|
key: 'south-gate',
|
|
name: 'S\u00fcdtor von Graufurt',
|
|
},
|
|
});
|
|
expect(repository.findOne).toHaveBeenCalledWith({
|
|
where: { id: DEMO_CHARACTER_ID },
|
|
relations: { currentLocation: true },
|
|
});
|
|
});
|
|
|
|
it('reports a missing demo seed as not found', async () => {
|
|
const repository = {
|
|
findOne: jest.fn().mockResolvedValue(null),
|
|
} as unknown as Repository<Character>;
|
|
const service = new CharactersService(repository);
|
|
|
|
await expect(service.getDemoCharacter()).rejects.toBeInstanceOf(
|
|
NotFoundException,
|
|
);
|
|
});
|
|
});
|