Skip to content

Conversation

@jkrizsan
Copy link
Contributor

Brief description

Add tests for statisticKeeper module

Change list

  • Add StatisticsKeeper test module
  • Implement the PlayerStatisticService.updatePlayerStatistic() test suite

@jkrizsan jkrizsan added PR Pull request test Tests to add labels May 29, 2025
@github-actions github-actions bot added the feature New feature to add label May 29, 2025
@MikhailDeriabin MikhailDeriabin linked an issue May 30, 2025 that may be closed by this pull request
1 task
@MikhailDeriabin MikhailDeriabin removed the feature New feature to add label May 30, 2025
@MikhailDeriabin MikhailDeriabin moved this from Backlog to In progress in Altzone-Server May 30, 2025
…error responses from PlayerService

Error was caused by `PlayerService` returning null instead of error in case the player is not found. Bug is fixed by adding if statement which returns ServiceError NOT_FOUND if the service returns null
@MikhailDeriabin
Copy link
Collaborator

MikhailDeriabin commented May 30, 2025

@jkrizsan

Check that your husky is working, which should run prettier automatically, before the push, because there was wrong formatting in test file

Copy link
Collaborator

@MikhailDeriabin MikhailDeriabin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall good and thorough tests, some small adjustments required

return await module.resolve(PlayerStatisticService);
}

static async getPlayerService() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use PlayerModule testing module to get PlayerService instead of adding a method it here. StatisticsKeeperModule should have only methods for creating own classes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do that than the mocks will not work. I think because my original solution is getting a reference to the PlayerService instance that is a dependency of the PlayerStatisticService. The purposed solution will get a reference to an another PlayerService.


static async getPlayerService() {
const module = await StatisticsKeeperCommonModule.getModule();
return await module.resolve(PlayerService);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not have to specify the await here, since it is not necessary

it('Should increase the players playedBattles if the input is valid | PlayerEvent.BATTLE_PLAYED', async () => {
const gameStatistics = gameStatisticsBuilder.setWonBattles(0).build();

const player = playerBuilder
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the creation of player object into beforeEach(), since you are using this object in almost all the cases. Then remove its creation from all of the test cases

);

expect(result).toBe(false);
expect(error[0]).toBeInstanceOf(ServiceError);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use the .toContainSENOT_FOUND() instead of checking the error type and its reason

@MikhailDeriabin MikhailDeriabin enabled auto-merge May 30, 2025 14:44
@jkrizsan
Copy link
Contributor Author

k

I think now it's working

image

@MikhailDeriabin MikhailDeriabin merged commit 1d10890 into dev May 31, 2025
@MikhailDeriabin MikhailDeriabin deleted the feature/add-tests-for-statisticKeeper-module-406 branch May 31, 2025 12:05
@github-project-automation github-project-automation bot moved this from In progress to Done in Altzone-Server May 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR Pull request test Tests to add

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Add tests for statisticKeeper module

4 participants