Skip to content

Commit

Permalink
hotfix: add logs when it cannot save aoc key (#247)
Browse files Browse the repository at this point in the history
* hotfix: add logs when it cannot save aoc key

* test: silence logger in testing
  • Loading branch information
samhwang authored Dec 14, 2024
1 parent dd0274d commit 7815ae7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/slash-commands/server-settings/set-aoc-settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand All @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/slash-commands/server-settings/set-aoc-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
15 changes: 13 additions & 2 deletions src/slash-commands/server-settings/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
};
1 change: 1 addition & 0 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const devOptions: pino.LoggerOptions = {
colorize: true,
},
},
enabled: !process.env.VITEST,
};

const prodOptions: pino.LoggerOptions = {
Expand Down

0 comments on commit 7815ae7

Please sign in to comment.