diff --git a/README.md b/README.md index 11acace..f652b11 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,9 @@ telegram. - [ ] Unit testing of: - [X] Core functionality - [ ] Helper methods - - [ ] Methods + - [X] Methods - [X] Types +- [ ] `New` helper funcs - [ ] Add more examples - [ ] Create Wiki page - [ ] Publish stable version diff --git a/common_test.go b/common_test.go index a970aa6..6d2fff7 100644 --- a/common_test.go +++ b/common_test.go @@ -37,3 +37,7 @@ func (t testNamedReade) Read(p []byte) (n int, err error) { func (t testNamedReade) Name() string { return "test" } + +var testInputFile = InputFile{ + File: testNamedReade{}, +} diff --git a/methods_test.go b/methods_test.go index 0dad198..a2ea3de 100644 --- a/methods_test.go +++ b/methods_test.go @@ -2325,3 +2325,189 @@ func TestBot_GetGameHighScores(t *testing.T) { assert.Nil(t, gameHighScores) }) } + +func TestSetWebhookParams_fileParameters(t *testing.T) { + p := &SetWebhookParams{ + Certificate: &testInputFile, + } + + assert.Equal(t, map[string]api.NamedReader{ + "certificate": testNamedReade{}, + }, p.fileParameters()) +} + +func TestSendPhotoParams_fileParameters(t *testing.T) { + p := &SendPhotoParams{ + Photo: testInputFile, + } + + assert.Equal(t, map[string]api.NamedReader{ + "photo": testNamedReade{}, + }, p.fileParameters()) +} + +func TestSendAudioParams_fileParameters(t *testing.T) { + p := &SendAudioParams{ + Audio: testInputFile, + Thumb: &testInputFile, + } + + assert.Equal(t, map[string]api.NamedReader{ + "audio": testNamedReade{}, + "thumb": testNamedReade{}, + }, p.fileParameters()) +} + +func TestSendDocumentParams_fileParameters(t *testing.T) { + p := &SendDocumentParams{ + Document: testInputFile, + Thumb: &testInputFile, + } + + assert.Equal(t, map[string]api.NamedReader{ + "document": testNamedReade{}, + "thumb": testNamedReade{}, + }, p.fileParameters()) +} + +func TestSendVideoParams_fileParameters(t *testing.T) { + p := &SendVideoParams{ + Video: testInputFile, + Thumb: &testInputFile, + } + + assert.Equal(t, map[string]api.NamedReader{ + "video": testNamedReade{}, + "thumb": testNamedReade{}, + }, p.fileParameters()) +} + +func TestSendAnimationParams_fileParameters(t *testing.T) { + p := &SendAnimationParams{ + Animation: testInputFile, + Thumb: &testInputFile, + } + + assert.Equal(t, map[string]api.NamedReader{ + "animation": testNamedReade{}, + "thumb": testNamedReade{}, + }, p.fileParameters()) +} + +func TestSendVoiceParams_fileParameters(t *testing.T) { + p := &SendVoiceParams{ + Voice: testInputFile, + } + + assert.Equal(t, map[string]api.NamedReader{ + "voice": testNamedReade{}, + }, p.fileParameters()) +} + +func TestSendVideoNoteParams_fileParameters(t *testing.T) { + p := &SendVideoNoteParams{ + VideoNote: testInputFile, + Thumb: &testInputFile, + } + + assert.Equal(t, map[string]api.NamedReader{ + "video_note": testNamedReade{}, + "thumb": testNamedReade{}, + }, p.fileParameters()) +} + +func TestSendMediaGroupParams_fileParameters(t *testing.T) { + p := &SendMediaGroupParams{ + Media: []InputMedia{ + &InputMediaDocument{ + Media: testInputFile, + Thumb: &testInputFile, + }, + &InputMediaVideo{ + Media: testInputFile, + Thumb: &InputFile{File: nil}, + }, + }, + } + + assert.Equal(t, map[string]api.NamedReader{ + "test": testNamedReade{}, + }, p.fileParameters()) +} + +func TestSetChatPhotoParams_fileParameters(t *testing.T) { + p := &SetChatPhotoParams{ + Photo: testInputFile, + } + + assert.Equal(t, map[string]api.NamedReader{ + "photo": testNamedReade{}, + }, p.fileParameters()) +} + +func TestEditMessageMediaParams_fileParameters(t *testing.T) { + p := &EditMessageMediaParams{ + Media: &InputMediaVideo{ + Media: testInputFile, + Thumb: &InputFile{File: nil}, + }, + } + + assert.Equal(t, map[string]api.NamedReader{ + "test": testNamedReade{}, + }, p.fileParameters()) +} + +func TestSendStickerParams_fileParameters(t *testing.T) { + p := &SendStickerParams{ + Sticker: testInputFile, + } + + assert.Equal(t, map[string]api.NamedReader{ + "sticker": testNamedReade{}, + }, p.fileParameters()) +} + +func TestUploadStickerFileParams_fileParameters(t *testing.T) { + p := &UploadStickerFileParams{ + PngSticker: testInputFile, + } + + assert.Equal(t, map[string]api.NamedReader{ + "png_sticker": testNamedReade{}, + }, p.fileParameters()) +} + +func TestCreateNewStickerSetParams_fileParameters(t *testing.T) { + p := &CreateNewStickerSetParams{ + PngSticker: &testInputFile, + TgsSticker: &testInputFile, + } + + assert.Equal(t, map[string]api.NamedReader{ + "png_sticker": testNamedReade{}, + "tgs_sticker": testNamedReade{}, + }, p.fileParameters()) +} + +func TestAddStickerToSetParams_fileParameters(t *testing.T) { + p := &AddStickerToSetParams{ + PngSticker: &testInputFile, + TgsSticker: &testInputFile, + } + + assert.Equal(t, map[string]api.NamedReader{ + "png_sticker": testNamedReade{}, + "tgs_sticker": testNamedReade{}, + }, p.fileParameters()) +} + +func TestSetStickerSetThumbParams_fileParameters(t *testing.T) { + p := &SetStickerSetThumbParams{ + Thumb: &testInputFile, + } + + assert.Equal(t, map[string]api.NamedReader{ + "thumb": testNamedReade{}, + }, p.fileParameters()) +} diff --git a/types_test.go b/types_test.go index dadf365..8e50394 100644 --- a/types_test.go +++ b/types_test.go @@ -476,9 +476,7 @@ func TestInputFile_MarshalJSON(t *testing.T) { func TestInputMedia_fileParameters(t *testing.T) { im := &InputMediaPhoto{ - Media: InputFile{ - File: testNamedReade{}, - }, + Media: testInputFile, } assert.Equal(t, map[string]api.NamedReader{ @@ -489,12 +487,8 @@ func TestInputMedia_fileParameters(t *testing.T) { func TestInputMediaVideo_fileParameters(t *testing.T) { im := &InputMediaVideo{ - Media: InputFile{ - File: testNamedReade{}, - }, - Thumb: &InputFile{ - File: testNamedReade{}, - }, + Media: testInputFile, + Thumb: &testInputFile, } assert.Equal(t, map[string]api.NamedReader{ @@ -506,12 +500,8 @@ func TestInputMediaVideo_fileParameters(t *testing.T) { func TestInputMediaAnimation_fileParameters(t *testing.T) { im := &InputMediaAnimation{ - Media: InputFile{ - File: testNamedReade{}, - }, - Thumb: &InputFile{ - File: testNamedReade{}, - }, + Media: testInputFile, + Thumb: &testInputFile, } assert.Equal(t, map[string]api.NamedReader{ @@ -523,12 +513,8 @@ func TestInputMediaAnimation_fileParameters(t *testing.T) { func TestInputMediaAudio_fileParameters(t *testing.T) { im := &InputMediaAudio{ - Media: InputFile{ - File: testNamedReade{}, - }, - Thumb: &InputFile{ - File: testNamedReade{}, - }, + Media: testInputFile, + Thumb: &testInputFile, } assert.Equal(t, map[string]api.NamedReader{ @@ -540,12 +526,8 @@ func TestInputMediaAudio_fileParameters(t *testing.T) { func TestInputMediaDocument_fileParameters(t *testing.T) { im := &InputMediaDocument{ - Media: InputFile{ - File: testNamedReade{}, - }, - Thumb: &InputFile{ - File: testNamedReade{}, - }, + Media: testInputFile, + Thumb: &testInputFile, } assert.Equal(t, map[string]api.NamedReader{