Skip to content

Commit

Permalink
fix: dont notify when setting the same player's name (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc authored Jan 5, 2021
1 parent cb6ad98 commit 4ebfc6e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/players/services/players.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ describe('PlayersService', () => {
expect(ret.role).toEqual('super-user');
});

it('should emit the playerRegisters event', async () => new Promise(resolve => {
it('should emit the playerRegisters event', async () => new Promise<void>(resolve => {
events.playerRegisters.subscribe(({ player }) => {
expect(player).toBeTruthy();
expect(player.steamId).toEqual(mockSteamProfile.id);
Expand Down Expand Up @@ -416,6 +416,14 @@ describe('PlayersService', () => {
expect(ret.name).toEqual('NEW_NAME');
});

describe('when setting the same name', () => {
it('should not update player name', async () => {
const spy = jest.spyOn(discordService.getAdminsChannel(), 'send');
await service.updatePlayer(mockPlayer.id, { name: `${mockPlayer.name}` }, admin.id);
expect(spy).not.toHaveBeenCalled();
});
});

it('should update player role', async () => {
const ret1 = await service.updatePlayer(mockPlayer.id, { role: 'admin' }, admin.id);
expect(ret1.role).toEqual('admin');
Expand Down
2 changes: 1 addition & 1 deletion src/players/services/players.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class PlayersService implements OnModuleInit {

const player = await this.getById(playerId);
if (player) {
if (update.name) {
if (update.name && player.name !== update.name) {
const oldName = player.name;
player.name = update.name;

Expand Down

0 comments on commit 4ebfc6e

Please sign in to comment.