Skip to content

Commit

Permalink
tests(prophecies/armies): Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rateau-violent committed Sep 10, 2023
1 parent ee4ed05 commit f79b6c4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 27 deletions.
26 changes: 22 additions & 4 deletions doc/api/api-swagger.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
openapi: 3.0.0
info:
description: |
This is the Prophecy Api documentation
version: dev
title: "Prophecy Api"
description: |
This is the Prophecy Api documentation
version: dev
title: "Prophecy Api"

tags:
- name: account
Expand Down Expand Up @@ -719,6 +719,24 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/armyProphecyDTO'
get:
summary: Retieves the history
description: ""
tags:
- prophecies
security:
- bearerAuth: []
parameters:
- $ref: '#/components/parametersSchemes/authorization'
responses:
201:
description: Created
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/armyProphecyDTO'


# GAMES
Expand Down
26 changes: 13 additions & 13 deletions src/army/unit/unit.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Troop } from "./troop/troop.entity";
import { SpecialRuleUnitTroop } from "./troop/special-rule/special-rule-unit-troop.entity";
import { EquipmentUnitTroop } from "./troop/equipment/equipment-unit-troop.entity";
import { UnitOption } from "./option/unit-option.entity";
import { ProphecyDatasource } from "@database/prophecy.datasource";
// import { ProphecyDatasource } from "@database/prophecy.datasource";

export class UnitCharacteristic {
public type: string;
Expand Down Expand Up @@ -91,17 +91,17 @@ export class Unit {

@AfterLoad()
private async load() {
let datasource: ProphecyDatasource = new ProphecyDatasource();

await datasource.initialize();
for (const id of this.troopIds)
this.troops.push(await datasource.getRepository(Troop).findOneBy({ id: id }));
for (const id of this.specialRuleUnitTroopIds)
this.specialRuleUnitTroops.push(await datasource.getRepository(SpecialRuleUnitTroop).findOneBy({ id: id }));
for (const id of this.equipmentUnitTroopIds)
this.equipmentUnitTroops.push(await datasource.getRepository(EquipmentUnitTroop).findOneBy({ id: id }));
for (const id of this.unitOptionIds)
this.unitOptions.push(await datasource.getRepository(UnitOption).findOneBy({ id: id }));
await datasource.destroy();
// let datasource: ProphecyDatasource = new ProphecyDatasource();
//
// await datasource.initialize();
// for (const id of this.troopIds)
// this.troops.push(await datasource.getRepository(Troop).findOneBy({ id: id }));
// for (const id of this.specialRuleUnitTroopIds)
// this.specialRuleUnitTroops.push(await datasource.getRepository(SpecialRuleUnitTroop).findOneBy({ id: id }));
// for (const id of this.equipmentUnitTroopIds)
// this.equipmentUnitTroops.push(await datasource.getRepository(EquipmentUnitTroop).findOneBy({ id: id }));
// for (const id of this.unitOptionIds)
// this.unitOptions.push(await datasource.getRepository(UnitOption).findOneBy({ id: id }));
// await datasource.destroy();
}
}
4 changes: 3 additions & 1 deletion src/database/prophecy.datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ArmyListUnitMagicStandard } from "@army-list/army-list-unit/magic-stand
import { ArmyListUnitOption } from "@army-list/army-list-unit/option/army-list-unit-option.entity";
import { ArmyListUnitTroopEquipment } from "@army-list/army-list-unit/troop/equipment/army-list-unit-troop-equipment.entity";
import { ArmyListUnitTroopSpecialRule } from "@army-list/army-list-unit/troop/special-rule/army-list-unit-troop-special-rule.entity";
import { ProphecyArmy } from "@prophecy/army/prophecy-army.entity";

dotenv.config();

Expand Down Expand Up @@ -67,7 +68,8 @@ export class ProphecyDatasource extends DataSource {
ArmyListUnitMagicStandard,
ArmyListUnitOption,
ArmyListUnitTroopEquipment,
ArmyListUnitTroopSpecialRule
ArmyListUnitTroopSpecialRule,
ProphecyArmy
]
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/prophecy/prophecy.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class ProphecyController {
const username: string = req.user.username;
const prophecies: ProphecyArmy[] = await this.prophecyArmyService.findByOwner(username);

return prophecies.map((p: ProphecyArmy) => new ProphecyArmyWithIdDTO(p));
return prophecies.map((p: ProphecyArmy): ProphecyArmyWithIdDTO => new ProphecyArmyWithIdDTO(p));
}

private checkAttackingPosition(position: string): boolean {
Expand Down
9 changes: 1 addition & 8 deletions tests/api/prophecy/army/lookup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,14 @@ const USERNAME = faker.internet.userName();
const EMAIL = faker.internet.email();
const PASSWORD = faker.internet.password();

// const USERNAME1 = faker.internet.userName();
// const EMAIL1 = faker.internet.email();

let app: INestApplication;
let userToken: string;
// let user1Token: string;

let userArmyListId1: string;
let userArmyListId2: string;

let nb: number;

// let user1ArmyListId_notShared: string;
// let user1ArmyListId_shared: string;

jest.setTimeout(40000);

describe("prophecies/armies/create", () => {
Expand Down Expand Up @@ -60,7 +53,7 @@ describe("prophecies/armies/create", () => {

it("basic lookup - then should return 200 (Ok)", async () => {
const res = await request(app.getHttpServer())
.get(TestsHelper.ARMIES_LISTS_ROUTE)
.get(TestsHelper.ARMY_PROPHECY_ROUTE)
.set("Authorization", `Bearer ${userToken}`);

expect(res.status).toEqual(HttpStatus.OK);
Expand Down

0 comments on commit f79b6c4

Please sign in to comment.