diff --git a/src/features/firebase/services/guilds/firebase-guilds-new-version-count.service.spec.ts b/src/features/firebase/services/guilds/firebase-guilds-new-version-count.service.spec.ts index 6e77a4033..d117f58bd 100644 --- a/src/features/firebase/services/guilds/firebase-guilds-new-version-count.service.spec.ts +++ b/src/features/firebase/services/guilds/firebase-guilds-new-version-count.service.spec.ts @@ -102,6 +102,22 @@ describe(`FirebaseGuildsNewVersionCountService`, (): void => { message: `text-no release note message sent`, } as ILoggerLog); }); + + it(`should not get a message response about the count`, (): void => { + expect.assertions(1); + + service.countChannelsAndGuilds(guildMessages); + + expect(firebaseGuildsNewVersionCountMessageResponseServiceGetMessageResponseSpy).not.toHaveBeenCalled(); + }); + + it(`should not send the message response about the count into the Sonia logs channel`, (): void => { + expect.assertions(1); + + service.countChannelsAndGuilds(guildMessages); + + expect(discordGuildSoniaServiceSendMessageToChannelSpy).not.toHaveBeenCalled(); + }); }); describe(`when the given guild messages is an empty array`, (): void => { @@ -120,6 +136,22 @@ describe(`FirebaseGuildsNewVersionCountService`, (): void => { message: `text-no release note message sent`, } as ILoggerLog); }); + + it(`should not get a message response about the count`, (): void => { + expect.assertions(1); + + service.countChannelsAndGuilds(guildMessages); + + expect(firebaseGuildsNewVersionCountMessageResponseServiceGetMessageResponseSpy).not.toHaveBeenCalled(); + }); + + it(`should not send the message response about the count into the Sonia logs channel`, (): void => { + expect.assertions(1); + + service.countChannelsAndGuilds(guildMessages); + + expect(discordGuildSoniaServiceSendMessageToChannelSpy).not.toHaveBeenCalled(); + }); }); describe(`when the given guild messages is an array with one undefined value`, (): void => { @@ -138,6 +170,22 @@ describe(`FirebaseGuildsNewVersionCountService`, (): void => { message: `text-no release note message sent for the value-1 guild`, } as ILoggerLog); }); + + it(`should not get a message response about the count`, (): void => { + expect.assertions(1); + + service.countChannelsAndGuilds(guildMessages); + + expect(firebaseGuildsNewVersionCountMessageResponseServiceGetMessageResponseSpy).not.toHaveBeenCalled(); + }); + + it(`should not send the message response about the count into the Sonia logs channel`, (): void => { + expect.assertions(1); + + service.countChannelsAndGuilds(guildMessages); + + expect(discordGuildSoniaServiceSendMessageToChannelSpy).not.toHaveBeenCalled(); + }); }); describe(`when the given guild messages is an array with two undefined values`, (): void => { @@ -156,6 +204,22 @@ describe(`FirebaseGuildsNewVersionCountService`, (): void => { message: `text-no release note message sent for the value-2 guilds`, } as ILoggerLog); }); + + it(`should not get a message response about the count`, (): void => { + expect.assertions(1); + + service.countChannelsAndGuilds(guildMessages); + + expect(firebaseGuildsNewVersionCountMessageResponseServiceGetMessageResponseSpy).not.toHaveBeenCalled(); + }); + + it(`should not send the message response about the count into the Sonia logs channel`, (): void => { + expect.assertions(1); + + service.countChannelsAndGuilds(guildMessages); + + expect(discordGuildSoniaServiceSendMessageToChannelSpy).not.toHaveBeenCalled(); + }); }); describe(`when the given guild messages is an array with one empty array`, (): void => { @@ -174,6 +238,22 @@ describe(`FirebaseGuildsNewVersionCountService`, (): void => { message: `text-no release note message sent for the value-1 guild`, } as ILoggerLog); }); + + it(`should not get a message response about the count`, (): void => { + expect.assertions(1); + + service.countChannelsAndGuilds(guildMessages); + + expect(firebaseGuildsNewVersionCountMessageResponseServiceGetMessageResponseSpy).not.toHaveBeenCalled(); + }); + + it(`should not send the message response about the count into the Sonia logs channel`, (): void => { + expect.assertions(1); + + service.countChannelsAndGuilds(guildMessages); + + expect(discordGuildSoniaServiceSendMessageToChannelSpy).not.toHaveBeenCalled(); + }); }); describe(`when the given guild messages is an array with two empty arrays`, (): void => { @@ -192,6 +272,22 @@ describe(`FirebaseGuildsNewVersionCountService`, (): void => { message: `text-no release note message sent for the value-2 guilds`, } as ILoggerLog); }); + + it(`should not get a message response about the count`, (): void => { + expect.assertions(1); + + service.countChannelsAndGuilds(guildMessages); + + expect(firebaseGuildsNewVersionCountMessageResponseServiceGetMessageResponseSpy).not.toHaveBeenCalled(); + }); + + it(`should not send the message response about the count into the Sonia logs channel`, (): void => { + expect.assertions(1); + + service.countChannelsAndGuilds(guildMessages); + + expect(discordGuildSoniaServiceSendMessageToChannelSpy).not.toHaveBeenCalled(); + }); }); describe(`when the given guild messages is an array with one array of one undefined value`, (): void => { @@ -210,6 +306,22 @@ describe(`FirebaseGuildsNewVersionCountService`, (): void => { message: `text-no release note message sent for the value-1 guild`, } as ILoggerLog); }); + + it(`should not get a message response about the count`, (): void => { + expect.assertions(1); + + service.countChannelsAndGuilds(guildMessages); + + expect(firebaseGuildsNewVersionCountMessageResponseServiceGetMessageResponseSpy).not.toHaveBeenCalled(); + }); + + it(`should not send the message response about the count into the Sonia logs channel`, (): void => { + expect.assertions(1); + + service.countChannelsAndGuilds(guildMessages); + + expect(discordGuildSoniaServiceSendMessageToChannelSpy).not.toHaveBeenCalled(); + }); }); describe(`when the given guild messages is an array with two arrays of one undefined value`, (): void => { @@ -228,6 +340,22 @@ describe(`FirebaseGuildsNewVersionCountService`, (): void => { message: `text-no release note message sent for the value-2 guilds`, } as ILoggerLog); }); + + it(`should not get a message response about the count`, (): void => { + expect.assertions(1); + + service.countChannelsAndGuilds(guildMessages); + + expect(firebaseGuildsNewVersionCountMessageResponseServiceGetMessageResponseSpy).not.toHaveBeenCalled(); + }); + + it(`should not send the message response about the count into the Sonia logs channel`, (): void => { + expect.assertions(1); + + service.countChannelsAndGuilds(guildMessages); + + expect(discordGuildSoniaServiceSendMessageToChannelSpy).not.toHaveBeenCalled(); + }); }); describe(`when the given guild messages is an array with one array of one message`, (): void => { @@ -246,6 +374,27 @@ describe(`FirebaseGuildsNewVersionCountService`, (): void => { message: `text-value-1 release note message sent over value-1 guild of value-1`, } as ILoggerLog); }); + + it(`should get a message response about the count`, (): void => { + expect.assertions(2); + + service.countChannelsAndGuilds(guildMessages); + + expect(firebaseGuildsNewVersionCountMessageResponseServiceGetMessageResponseSpy).toHaveBeenCalledTimes(1); + expect(firebaseGuildsNewVersionCountMessageResponseServiceGetMessageResponseSpy).toHaveBeenCalledWith(1, 1, 1); + }); + + it(`should send the message response about the count into the Sonia logs channel`, (): void => { + expect.assertions(2); + + service.countChannelsAndGuilds(guildMessages); + + expect(discordGuildSoniaServiceSendMessageToChannelSpy).toHaveBeenCalledTimes(1); + expect(discordGuildSoniaServiceSendMessageToChannelSpy).toHaveBeenCalledWith({ + channelName: `logs`, + messageResponse: discordMessageResponse, + } as IDiscordGuildSoniaSendMessageToChannel); + }); }); describe(`when the given guild messages is an array with two arrays of one message`, (): void => { @@ -264,6 +413,27 @@ describe(`FirebaseGuildsNewVersionCountService`, (): void => { message: `text-value-2 release note messages sent over value-2 guilds of value-2`, } as ILoggerLog); }); + + it(`should get a message response about the count`, (): void => { + expect.assertions(2); + + service.countChannelsAndGuilds(guildMessages); + + expect(firebaseGuildsNewVersionCountMessageResponseServiceGetMessageResponseSpy).toHaveBeenCalledTimes(1); + expect(firebaseGuildsNewVersionCountMessageResponseServiceGetMessageResponseSpy).toHaveBeenCalledWith(2, 2, 2); + }); + + it(`should send the message response about the count into the Sonia logs channel`, (): void => { + expect.assertions(2); + + service.countChannelsAndGuilds(guildMessages); + + expect(discordGuildSoniaServiceSendMessageToChannelSpy).toHaveBeenCalledTimes(1); + expect(discordGuildSoniaServiceSendMessageToChannelSpy).toHaveBeenCalledWith({ + channelName: `logs`, + messageResponse: discordMessageResponse, + } as IDiscordGuildSoniaSendMessageToChannel); + }); }); describe(`when it is a mix of guilds with and without messages`, (): void => { @@ -289,43 +459,27 @@ describe(`FirebaseGuildsNewVersionCountService`, (): void => { message: `text-value-4 release note messages sent over value-3 guilds of value-6`, } as ILoggerLog); }); - }); - it(`should get a message response about the count`, (): void => { - expect.assertions(2); - guildMessages = [ - [], - [null], - [createMock()], - [null, null], - [createMock(), null], - [createMock(), createMock()], - ]; - - service.countChannelsAndGuilds(guildMessages); - - expect(firebaseGuildsNewVersionCountMessageResponseServiceGetMessageResponseSpy).toHaveBeenCalledTimes(1); - expect(firebaseGuildsNewVersionCountMessageResponseServiceGetMessageResponseSpy).toHaveBeenCalledWith(6, 3, 4); - }); + it(`should get a message response about the count`, (): void => { + expect.assertions(2); - it(`should send the message response about the count into the Sonia logs channel`, (): void => { - expect.assertions(2); - guildMessages = [ - [], - [null], - [createMock()], - [null, null], - [createMock(), null], - [createMock(), createMock()], - ]; - - service.countChannelsAndGuilds(guildMessages); - - expect(discordGuildSoniaServiceSendMessageToChannelSpy).toHaveBeenCalledTimes(1); - expect(discordGuildSoniaServiceSendMessageToChannelSpy).toHaveBeenCalledWith({ - channelName: `logs`, - messageResponse: discordMessageResponse, - } as IDiscordGuildSoniaSendMessageToChannel); + service.countChannelsAndGuilds(guildMessages); + + expect(firebaseGuildsNewVersionCountMessageResponseServiceGetMessageResponseSpy).toHaveBeenCalledTimes(1); + expect(firebaseGuildsNewVersionCountMessageResponseServiceGetMessageResponseSpy).toHaveBeenCalledWith(6, 3, 4); + }); + + it(`should send the message response about the count into the Sonia logs channel`, (): void => { + expect.assertions(2); + + service.countChannelsAndGuilds(guildMessages); + + expect(discordGuildSoniaServiceSendMessageToChannelSpy).toHaveBeenCalledTimes(1); + expect(discordGuildSoniaServiceSendMessageToChannelSpy).toHaveBeenCalledWith({ + channelName: `logs`, + messageResponse: discordMessageResponse, + } as IDiscordGuildSoniaSendMessageToChannel); + }); }); }); }); diff --git a/src/features/firebase/services/guilds/firebase-guilds-new-version-count.service.ts b/src/features/firebase/services/guilds/firebase-guilds-new-version-count.service.ts index f732704c1..47f0fe9ab 100644 --- a/src/features/firebase/services/guilds/firebase-guilds-new-version-count.service.ts +++ b/src/features/firebase/services/guilds/firebase-guilds-new-version-count.service.ts @@ -13,6 +13,7 @@ const DEFAULT_GUILD_COUNT = 0; const ONE_GUILD = 1; const DEFAULT_CHANNEL_COUNT = 0; const ONE_CHANNEL = 1; +const NO_CHANNEL = 0; export class FirebaseGuildsNewVersionCountService extends AbstractService { private static _instance: FirebaseGuildsNewVersionCountService; @@ -68,14 +69,16 @@ export class FirebaseGuildsNewVersionCountService extends AbstractService { this._logGuildAndChannelCount(totalGuildCount, guildCount, channelCount); - DiscordGuildSoniaService.getInstance().sendMessageToChannel({ - channelName: DiscordGuildSoniaChannelNameEnum.LOGS, - messageResponse: FirebaseGuildsNewVersionCountMessageResponseService.getInstance().getMessageResponse( - totalGuildCount, - guildCount, - channelCount - ), - }); + if (_.gt(channelCount, NO_CHANNEL)) { + DiscordGuildSoniaService.getInstance().sendMessageToChannel({ + channelName: DiscordGuildSoniaChannelNameEnum.LOGS, + messageResponse: FirebaseGuildsNewVersionCountMessageResponseService.getInstance().getMessageResponse( + totalGuildCount, + guildCount, + channelCount + ), + }); + } } private _logGuildAndChannelCount(