Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gpont committed Aug 7, 2024
1 parent 68d2fe1 commit 65d91aa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/controllers/bot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ describe('Bot Commands', () => {
),
);
});

it('should error with duplicate group code', async () => {
const chatId = createChat();
await createGroup(String(chatId));
const sendMessage = jest.spyOn(bot, 'sendMessage');
const msg = {
chat: { id: chatId },
text: '/create_group',
from: { username: 'test' },
} as unknown as TelegramBot.Message;

await emitMsg(msg);

expect(sendMessage).toHaveBeenCalledWith(
msg.chat.id,
expect.stringContaining('Группа уже создана'),
);
});
});

describe('join_group', () => {
Expand Down
13 changes: 9 additions & 4 deletions src/controllers/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ const rawBotHandlers: [RegExp, THandler][] = [
/\/create_group/,
(bot) => async (msg) => {
const chatId = msg.chat.id;
const group = await findGroupByCode(String(chatId));
if (group) {
bot.sendMessage(chatId, texts.group_already_created + group.code);
return;
}
await createGroup(String(chatId));
bot.sendMessage(chatId, `${texts.group_created} ${chatId}`);
},
Expand Down Expand Up @@ -178,11 +183,11 @@ const rawBotHandlers: [RegExp, THandler][] = [
const chatId = msg.chat.id;

const group = await checkAndGetGroup(msg);
const movies = await checkAndGetMoviesList(group.id);
const movies = (await checkAndGetMoviesList(group.id)).filter(
(movie) => !movie.is_vetoed,
);

const movie = movies.filter((movie) => !movie.is_vetoed)[
Math.floor(Math.random() * movies.length)
];
const movie = movies[Math.floor(Math.random() * movies.length)];
bot.sendMessage(chatId, getMovieDescription(movie), MSG_OPTIONS);
},
],
Expand Down
1 change: 1 addition & 0 deletions src/texts.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"group_created": "Группа создана! Код для присоединения:",
"joined_group": "Вы присоединились к группе!",
"group_not_found": "Группа с таким кодом не найдена.",
"group_already_created": "Группа уже создана. Код присоединения: ",
"no_group_code": "Код группы не указан.",
"movie_suggested": "Фильм предложен",
"not_in_group": "Вы не состоите ни в одной группе.",
Expand Down

0 comments on commit 65d91aa

Please sign in to comment.