Skip to content

Commit e120589

Browse files
author
Pierre Chabardes
committed
feat(hero): add equip item e2e test
1 parent 0aeaefb commit e120589

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/heroes/tests/heroes.e2e-spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { EntityManager } from 'typeorm';
44
import { Hero } from '../infrastructure/typeorm/hero.orm-entity';
55
import { createTestModule } from '../../common/utils/test/testing-module';
66
import { HeroModule } from '../hero.module';
7+
import { Item } from '../../items/infrastructure/typeorm/item.orm-entity';
78

89
describe('Heroes module (e2e)', () => {
910
let app: INestApplication;
@@ -62,4 +63,26 @@ describe('Heroes module (e2e)', () => {
6263

6364
expect(body.data.getHero).toMatchObject(hero);
6465
});
66+
67+
it('should equip an item', async () => {
68+
const heroData = { name: heroName, level: 1, currentHp: 5 };
69+
const { id: heroId } = await entityManager.save(Hero, heroData);
70+
const { id: itemId } = await entityManager.save(Item, {
71+
name: 'Excalibur',
72+
ownerId: heroId,
73+
});
74+
75+
const { body } = await request(app.getHttpServer())
76+
.post('/graphql')
77+
.send({
78+
query: `mutation {
79+
equipItem(heroId: "${heroId}", itemId: "${itemId}")
80+
}`,
81+
})
82+
.expect(200);
83+
84+
expect(body.data.equipItem).toBeTruthy();
85+
const hero = await entityManager.findOneById(Hero, heroId);
86+
expect(hero.equippedItem).toStrictEqual(itemId);
87+
});
6588
});

0 commit comments

Comments
 (0)