From 7815ae7451c71b43e88e57f7d3d6010ab73e9aa0 Mon Sep 17 00:00:00 2001 From: Sam Huynh Date: Sun, 15 Dec 2024 09:41:07 +1100 Subject: [PATCH] hotfix: add logs when it cannot save aoc key (#247) * hotfix: add logs when it cannot save aoc key * test: silence logger in testing --- .../server-settings/set-aoc-settings.test.ts | 6 ++---- .../server-settings/set-aoc-settings.ts | 4 ++-- src/slash-commands/server-settings/utils.ts | 15 +++++++++++++-- src/utils/logger.ts | 1 + 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/slash-commands/server-settings/set-aoc-settings.test.ts b/src/slash-commands/server-settings/set-aoc-settings.test.ts index 55bc96f7..b29218c1 100644 --- a/src/slash-commands/server-settings/set-aoc-settings.test.ts +++ b/src/slash-commands/server-settings/set-aoc-settings.test.ts @@ -17,7 +17,7 @@ describe('Set aoc key', () => { }); it('should reply with error if it cannot set the key', async () => { - mockSetAocSettings.mockRejectedValueOnce(new Error('Synthetic Error')); + mockSetAocSettings.mockRejectedValueOnce(new Error('Synthetic Error save aoc settings')); mockChatInputInteraction.options.getString.mockImplementation((name) => { switch (name) { case 'key': { @@ -37,14 +37,12 @@ describe('Set aoc key', () => { expect(mockSetAocSettings).toHaveBeenCalledOnce(); expect(mockChatInputInteraction.reply).toHaveBeenCalledOnce(); - expect(mockChatInputInteraction.reply).toHaveBeenCalledWith('Cannot set this AOC key. Please try again'); + expect(mockChatInputInteraction.reply).toHaveBeenCalledWith('Cannot set this AOC key. Please try again. Error: Error: Synthetic Error save aoc settings'); }); it('Should be able to set AOC key and reply', async () => { mockSetAocSettings.mockResolvedValueOnce({ guildId: faker.string.numeric(), - reminderChannel: null, - autobumpThreads: [], aocLeaderboardId: faker.string.numeric(), }); mockChatInputInteraction.options.getString.mockImplementation((name) => { diff --git a/src/slash-commands/server-settings/set-aoc-settings.ts b/src/slash-commands/server-settings/set-aoc-settings.ts index d3336e26..2c852a18 100644 --- a/src/slash-commands/server-settings/set-aoc-settings.ts +++ b/src/slash-commands/server-settings/set-aoc-settings.ts @@ -18,8 +18,8 @@ export const execute: SlashCommandHandler = async (interaction) => { const op = await Result.safe(setAocSettings(guildId, key, leaderboardId)); if (op.isErr()) { - logger.info(`[set-aoc-key]: ${interaction.member!.user.username} failed to set AOC Key.`); - await interaction.reply('Cannot set this AOC key. Please try again'); + logger.info(`[set-aoc-key]: ${interaction.member!.user.username} failed to set AOC Key. Error: ${op.unwrapErr()}`); + await interaction.reply(`Cannot set this AOC key. Please try again. Error: ${op.unwrapErr()}`); return; } diff --git a/src/slash-commands/server-settings/utils.ts b/src/slash-commands/server-settings/utils.ts index 69c29c44..934c862a 100644 --- a/src/slash-commands/server-settings/utils.ts +++ b/src/slash-commands/server-settings/utils.ts @@ -31,7 +31,18 @@ export const setAocSettings = async (guildId: string, aocKey: string, aocLeaderb const db = getDbClient(); return db.serverChannelsSettings.upsert({ where: { guildId }, - update: { aocKey, aocLeaderboardId }, - create: { guildId, aocKey }, + update: { + aocKey, + aocLeaderboardId, + }, + create: { + guildId, + aocKey, + aocLeaderboardId, + }, + select: { + guildId: true, + aocLeaderboardId: true, + }, }); }; diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 1a60427b..2ba35b32 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -13,6 +13,7 @@ const devOptions: pino.LoggerOptions = { colorize: true, }, }, + enabled: !process.env.VITEST, }; const prodOptions: pino.LoggerOptions = {