Skip to content

Commit

Permalink
chore: removed unused
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Dec 2, 2024
1 parent 38f4d50 commit d532289
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 101 deletions.
33 changes: 0 additions & 33 deletions pkg/types/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"reflect"

"github.com/jarcoal/httpmock"
)
Expand Down Expand Up @@ -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
})
}
68 changes: 0 additions & 68 deletions pkg/types/telegram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit d532289

Please sign in to comment.