add test
This commit is contained in:
parent
2889f35a3d
commit
1e3f5eb91d
|
@ -37,8 +37,11 @@ func (bot *botAll) Process(ctx context.Context, msg messenger.Message) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
usernames := lo.Map(users, func(item storage.User, _ int) string {
|
usernames := lo.FilterMap(users, func(item storage.User, _ int) (string, bool) {
|
||||||
return item.UserID
|
if item.UserID == msg.UserID {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
return item.UserID, true
|
||||||
})
|
})
|
||||||
if len(usernames) > 0 {
|
if len(usernames) > 0 {
|
||||||
bot.messenger.SendMessage(
|
bot.messenger.SendMessage(
|
||||||
|
|
|
@ -41,6 +41,98 @@ func Test_botAll_Process(t *testing.T) {
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "message with all and empty users",
|
||||||
|
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()).
|
||||||
|
Return([]storage.User{{UserID: "username"}}, nil).
|
||||||
|
Times(1)
|
||||||
|
return m
|
||||||
|
},
|
||||||
|
msg: messenger.Message{
|
||||||
|
ChatID: "123",
|
||||||
|
UserID: "username",
|
||||||
|
Text: "hello @all",
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "message with all and one user",
|
||||||
|
messenger: func(ctrl *gomock.Controller) messenger.IMessenger {
|
||||||
|
m := messenger_mocks.NewMockIMessenger(ctrl)
|
||||||
|
m.EXPECT().
|
||||||
|
SendMessage(
|
||||||
|
gomock.Any(),
|
||||||
|
&messenger.Message{
|
||||||
|
ChatID: "123",
|
||||||
|
Text: "username2",
|
||||||
|
},
|
||||||
|
).
|
||||||
|
Times(1)
|
||||||
|
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()).
|
||||||
|
Return([]storage.User{
|
||||||
|
{UserID: "username"},
|
||||||
|
{UserID: "username2"},
|
||||||
|
}, nil).
|
||||||
|
Times(1)
|
||||||
|
return m
|
||||||
|
},
|
||||||
|
msg: messenger.Message{
|
||||||
|
ChatID: "123",
|
||||||
|
UserID: "username",
|
||||||
|
Text: "hello @all",
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "message with all and one user",
|
||||||
|
messenger: func(ctrl *gomock.Controller) messenger.IMessenger {
|
||||||
|
m := messenger_mocks.NewMockIMessenger(ctrl)
|
||||||
|
m.EXPECT().
|
||||||
|
SendMessage(
|
||||||
|
gomock.Any(),
|
||||||
|
&messenger.Message{
|
||||||
|
ChatID: "123",
|
||||||
|
Text: "username2 username3",
|
||||||
|
},
|
||||||
|
).
|
||||||
|
Times(1)
|
||||||
|
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()).
|
||||||
|
Return([]storage.User{
|
||||||
|
{UserID: "username"},
|
||||||
|
{UserID: "username2"},
|
||||||
|
{UserID: "username3"},
|
||||||
|
}, nil).
|
||||||
|
Times(1)
|
||||||
|
return m
|
||||||
|
},
|
||||||
|
msg: messenger.Message{
|
||||||
|
ChatID: "123",
|
||||||
|
UserID: "username",
|
||||||
|
Text: "hello @all",
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
tt := tt
|
tt := tt
|
||||||
|
|
Loading…
Reference in New Issue