From 703355a43d99f00c9575c43b8440dd8633deb2c2 Mon Sep 17 00:00:00 2001 From: Richard Gregory Date: Tue, 20 Feb 2024 18:15:31 +0100 Subject: [PATCH] Add Unit test for telegram client --- internal/client/telegram_test.go | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 internal/client/telegram_test.go diff --git a/internal/client/telegram_test.go b/internal/client/telegram_test.go new file mode 100644 index 00000000..4477ad8a --- /dev/null +++ b/internal/client/telegram_test.go @@ -0,0 +1,36 @@ +package client_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/base-org/pessimism/internal/client" + "github.com/base-org/pessimism/internal/core" +) + +func TestTelegramResponseToAlertResponse(t *testing.T) { + // Test case for a successful Telegram response + testTelegramSuccess := &client.TelegramAPIResponse{ + Ok: true, + Result: nil, + Error: "", + } + + // Test case for a failed Telegram response + testTelegramFailure := &client.TelegramAPIResponse{ + Ok: false, + Error: "error message", + } + + resSuc := testTelegramSuccess.ToAlertResponse() + resFail := testTelegramFailure.ToAlertResponse() + + // Assert that the success case is correctly interpreted + assert.Equal(t, core.SuccessStatus, resSuc.Status) + assert.Equal(t, "Message sent successfully", resSuc.Message) + + // Assert that the failure case is correctly interpreted + assert.Equal(t, core.FailureStatus, resFail.Status) + assert.Equal(t, "error message", resFail.Message) +}