63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package bot_all
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"go.uber.org/mock/gomock"
|
|
|
|
"git.3crabs.ru/VLADIMIR/butler/internal/modules/messenger"
|
|
messenger_mocks "git.3crabs.ru/VLADIMIR/butler/internal/modules/messenger/mocks"
|
|
"git.3crabs.ru/VLADIMIR/butler/internal/modules/storage"
|
|
storage_mocks "git.3crabs.ru/VLADIMIR/butler/internal/modules/storage/mocks"
|
|
)
|
|
|
|
func Test_botAll_Process(t *testing.T) {
|
|
t.Parallel()
|
|
tests := []struct {
|
|
name string
|
|
messenger func(ctrl *gomock.Controller) messenger.IMessenger
|
|
storage func(ctrl *gomock.Controller) storage.IStorage
|
|
msg messenger.Message
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "hello message",
|
|
messenger: func(ctrl *gomock.Controller) messenger.IMessenger {
|
|
m := messenger_mocks.NewMockIMessenger(ctrl)
|
|
m.EXPECT().SendMessage(gomock.Any(), gomock.Any()).Times(0)
|
|
return m
|
|
},
|
|
storage: func(ctrl *gomock.Controller) storage.IStorage {
|
|
m := storage_mocks.NewMockIStorage(ctrl)
|
|
m.EXPECT().UpsertUser(gomock.Any(), storage.User{ChatID: "123", UserID: "username"}).Times(1)
|
|
m.EXPECT().GetAllUsersByChatID(gomock.Any(), gomock.Any()).Times(0)
|
|
return m
|
|
},
|
|
msg: messenger.Message{
|
|
ChatID: "123",
|
|
UserID: "username",
|
|
Text: "hello",
|
|
},
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
ctx := context.Background()
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
|
|
bot := &botAll{
|
|
messenger: tt.messenger(ctrl),
|
|
storage: tt.storage(ctrl),
|
|
}
|
|
if err := bot.Process(ctx, tt.msg); (err != nil) != tt.wantErr {
|
|
t.Errorf("botAll.Process() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|