Skip to content

Commit

Permalink
feat(hero): add equip item e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Chabardes committed Jun 8, 2022
1 parent 9b12eb1 commit 2557bea
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/heroes/tests/heroes.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Connection } from 'typeorm';
import { Hero } from '../infrastructure/typeorm/hero.orm-entity';
import { createTestModule } from '../../common/utils/test/testing-module';
import { HeroModule } from '../hero.module';
import { Item } from '../../items/infrastructure/typeorm/item.orm-entity';

describe('Heroes module (e2e)', () => {
let app: INestApplication;
Expand Down Expand Up @@ -63,4 +64,29 @@ describe('Heroes module (e2e)', () => {

expect(body.data.getHero).toMatchObject(hero);
});

it('should equip an item', async () => {
const heroData = { name: heroName, level: 1, currentHp: 5 };
const { id: heroId } = await connection.manager
.create(Hero, heroData)
.save();
const { id: itemId } = await connection.manager
.create(Item, { name: 'Excalibur', ownerId: heroId })
.save();

const { body } = await request(app.getHttpServer())
.post('/graphql')
.send({
query: `mutation {
equipItem(heroId: "${heroId}", itemId: "${itemId}")
}`,
})
.expect(200);

expect(body.data.equipItem).toBeTruthy();
const hero = await connection.manager.findOne(Hero, {
id: heroId,
});
expect(hero.equippedItem).toStrictEqual(itemId);
});
});

0 comments on commit 2557bea

Please # to comment.