Skip to content

Commit

Permalink
fix(release-notes): stop sending the log message in sonia guild if no…
Browse files Browse the repository at this point in the history
…thing was sent

since the release notes are trigger on start, if sonia reboots the release notes will run and will send a message in sonia guild into logs channel to say that no release notes message was sent.
it's useless since this will never happen
  • Loading branch information
C0ZEN committed May 1, 2021
1 parent 05b01e6 commit 0dfbcad
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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<Message>()],
[null, null],
[createMock<Message>(), null],
[createMock<Message>(), createMock<Message>()],
];

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<Message>()],
[null, null],
[createMock<Message>(), null],
[createMock<Message>(), createMock<Message>()],
];

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);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 0dfbcad

Please sign in to comment.