From d532289b8b92411e7449848425012296daaa2632 Mon Sep 17 00:00:00 2001 From: Sergey Date: Mon, 2 Dec 2024 23:15:56 +0300 Subject: [PATCH] chore: removed unused --- pkg/types/telegram.go | 33 ------------------ pkg/types/telegram_test.go | 68 -------------------------------------- 2 files changed, 101 deletions(-) diff --git a/pkg/types/telegram.go b/pkg/types/telegram.go index 765b09a..d5d0f84 100644 --- a/pkg/types/telegram.go +++ b/pkg/types/telegram.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "net/http" - "reflect" "github.com/jarcoal/httpmock" ) @@ -45,35 +44,3 @@ func TelegramResponseHasText(text string) httpmock.Matcher { return true }) } - -func TelegramResponseHasBytesAndMarkup(text []byte, keyboard TelegramInlineKeyboardResponse) httpmock.Matcher { - return TelegramResponseHasTextAndMarkup(string(text), keyboard) -} - -func TelegramResponseHasTextAndMarkup(text string, keyboard TelegramInlineKeyboardResponse) httpmock.Matcher { - return httpmock.NewMatcher("TelegramResponseHasTextAndMarkup", - func(req *http.Request) bool { - response := TelegramResponse{} - - err := json.NewDecoder(req.Body).Decode(&response) - if err != nil { - return false - } - - if response.Text != text { - panic(fmt.Sprintf("expected %q but got %q", response.Text, text)) - } - - var responseKeyboard TelegramInlineKeyboardResponse - err = json.Unmarshal([]byte(response.ReplyMarkup), &responseKeyboard) - if err != nil { - panic(err) - } - - if !reflect.DeepEqual(responseKeyboard, keyboard) { - panic(fmt.Sprintf("expected keyboard %q but got %q", responseKeyboard, keyboard)) - } - - return true - }) -} diff --git a/pkg/types/telegram_test.go b/pkg/types/telegram_test.go index 1df81dd..ddd85c8 100644 --- a/pkg/types/telegram_test.go +++ b/pkg/types/telegram_test.go @@ -34,71 +34,3 @@ func TestTelegramResponseHasTextDoesNotMatch(t *testing.T) { matcher := TelegramResponseHasText("wrong text") matcher.Check(req) } - -func TestTelegramResponseHasTextWithMarkupNotJson(t *testing.T) { - t.Parallel() - - req := &http.Request{Body: io.NopCloser(strings.NewReader("not json"))} - matcher := TelegramResponseHasTextAndMarkup("text", TelegramInlineKeyboardResponse{}) - require.False(t, matcher.Check(req)) -} - -func TestTelegramResponseHasTextWithMarkupTextDoesNotMatch(t *testing.T) { - t.Parallel() - - defer func() { - if r := recover(); r == nil { - require.Fail(t, "Expected to have a panic here!") - } - }() - - bytes, err := json.Marshal(TelegramResponse{Text: "text"}) - require.NoError(t, err) - - req := &http.Request{Body: io.NopCloser(strings.NewReader(string(bytes)))} - matcher := TelegramResponseHasTextAndMarkup("wrong text", TelegramInlineKeyboardResponse{}) - matcher.Check(req) -} - -func TestTelegramResponseHasTextWithMarkupTextKeyboardNotJSON(t *testing.T) { - t.Parallel() - - defer func() { - if r := recover(); r == nil { - require.Fail(t, "Expected to have a panic here!") - } - }() - - bytes, err := json.Marshal(TelegramResponse{Text: "text", ReplyMarkup: "not json"}) - require.NoError(t, err) - - req := &http.Request{Body: io.NopCloser(strings.NewReader(string(bytes)))} - matcher := TelegramResponseHasTextAndMarkup("text", TelegramInlineKeyboardResponse{}) - matcher.Check(req) -} - -func TestTelegramResponseHasTextWithMarkupTextKeyboardDoesNotMatch(t *testing.T) { - t.Parallel() - - defer func() { - if r := recover(); r == nil { - require.Fail(t, "Expected to have a panic here!") - } - }() - - keyboardBytes, err := json.Marshal(TelegramInlineKeyboardResponse{ - InlineKeyboard: [][]TelegramInlineKeyboard{{ - {Unique: "unique"}, - }}, - }) - require.NoError(t, err) - - bytes, err := json.Marshal(TelegramResponse{Text: "text", ReplyMarkup: string(keyboardBytes)}) - require.NoError(t, err) - - req := &http.Request{Body: io.NopCloser(strings.NewReader(string(bytes)))} - matcher := TelegramResponseHasTextAndMarkup("text", TelegramInlineKeyboardResponse{ - InlineKeyboard: [][]TelegramInlineKeyboard{{}}, - }) - matcher.Check(req) -}