diff --git a/src/jobspy/main.py b/src/jobspy/main.py index b51a827..b7e2780 100644 --- a/src/jobspy/main.py +++ b/src/jobspy/main.py @@ -25,7 +25,7 @@ async def main(): new_jobs = jobRepository.insertManyIfNotFound(jobs) for new_job in new_jobs: - await telegramBot.send_job(new_job) + await telegramBot.sendJob(new_job) # Run the async main function if __name__ == "__main__": diff --git a/src/jobspy/telegram_bot.py b/src/jobspy/telegram_bot.py index 60b19a7..d3649e0 100644 --- a/src/jobspy/telegram_bot.py +++ b/src/jobspy/telegram_bot.py @@ -14,7 +14,7 @@ class TelegramBot: self.chatId = os.getenv("TELEGRAM_CHAT_ID") self.bot = Bot(token=self._api_token) - async def send_job(self, job: JobPost): + async def sendJob(self, job: JobPost): """ Send JobPost details to Telegram chat. """ @@ -22,7 +22,7 @@ class TelegramBot: f"Job ID: {job.id}\n" \ f"Job Title: {job.title}\n" \ f"Company: {job.company_name}\n" \ - f"Location: {job.location}\n" \ + f"Location: {job.location.display_location()}\n" \ f"Link: {job.job_url}\n" try: await self.bot.sendMessage(chat_id=self.chatId, text=message) diff --git a/src/tests/test_telegram.py b/src/tests/test_telegram.py new file mode 100644 index 0000000..eca0cac --- /dev/null +++ b/src/tests/test_telegram.py @@ -0,0 +1,33 @@ +import asyncio +from dotenv import load_dotenv +from jobspy.db.job_repository import JobRepository +from jobspy.telegram_bot import TelegramBot +from tests.test_util import createMockJob + +load_dotenv() + + +class TelegramTests: + + def __init__(self): + """ + This block ensures that the script runs the test only when executed directly, + not when imported as a module. + """ + self.bot = TelegramBot() + + async def send_job(self): + """ + Sents a mock job Telegram using Telegram Bot. + """ + job = createMockJob() + await self.bot.sendJob(job) + print(f"Test sent job finished.") + + +if __name__ == '__main__': + # Create an instance of DatabaseTests + tests = TelegramTests() + + # Run the send_job test + asyncio.run(tests.send_job())