Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mymmrac committed May 24, 2024
1 parent fa92b56 commit 4d70e2f
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,12 @@ func TestTypesConstants(t *testing.T) {
{
PollTypeRegular, PollTypeQuiz,
},
{
BackgroundFilledSolid, BackgroundFilledGradient, BackgroundFilledFreeformGradient,
},
{
BackgroundTypeNameFill, BackgroundTypeNameWallpaper, BackgroundTypeNamePattern, BackgroundTypeNameChatTheme,
},
{
MarkupTypeReplyKeyboard, MarkupTypeReplyKeyboardRemove, MarkupTypeInlineKeyboard, MarkupTypeForceReply,
},
Expand Down Expand Up @@ -1289,3 +1295,104 @@ func Test_ChatBoostRemoved_UnmarshalJSON(t *testing.T) {
})
}
}

func Test_BackgroundTypeFill_UnmarshalJSON(t *testing.T) {
tests := []struct {
name string
json string
data *BackgroundTypeFill
isError bool
}{
{
name: "success",
json: `{"type": "fill", "fill": {"type": "solid"}}`,
data: &BackgroundTypeFill{
Type: BackgroundTypeNameFill,
Fill: &BackgroundFillSolid{
Type: BackgroundFilledSolid,
},
},
isError: false,
},
{
name: "error_invalid",
json: "",
data: nil,
isError: true,
},
{
name: "error_no_fill",
json: `{}`,
data: nil,
isError: true,
},
{
name: "error_invalid_fill",
json: `{"fill": {"type": ""}`,
data: nil,
isError: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &BackgroundTypeFill{}
err := c.UnmarshalJSON([]byte(tt.json))
if tt.isError {
require.Error(t, err)
return
}
require.NoError(t, err)
assert.EqualValues(t, tt.data, c)
})
}
}

func Test_ChatBackground_UnmarshalJSON(t *testing.T) {
tests := []struct {
name string
json string
data *ChatBackground
isError bool
}{
{
name: "success",
json: `{"type": {"type": "wallpaper"}}`,
data: &ChatBackground{
Type: &BackgroundTypeWallpaper{
Type: BackgroundTypeNameWallpaper,
},
},
isError: false,
},
{
name: "error_invalid",
json: "",
data: nil,
isError: true,
},
{
name: "error_no_type",
json: `{}`,
data: nil,
isError: true,
},
{
name: "error_invalid_type",
json: `{"type": {"type": ""}`,
data: nil,
isError: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &ChatBackground{}
err := c.UnmarshalJSON([]byte(tt.json))
if tt.isError {
require.Error(t, err)
return
}
require.NoError(t, err)
assert.EqualValues(t, tt.data, c)
})
}
}

0 comments on commit 4d70e2f

Please sign in to comment.