|
| 1 | +package handler |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + "time" |
| 6 | + |
| 7 | + "github.com/gofrs/uuid" |
| 8 | + "github.com/golang/mock/gomock" |
| 9 | + "github.com/leandro-lugaresi/hub" |
| 10 | + "github.com/stretchr/testify/assert" |
| 11 | + |
| 12 | + intevent "github.com/traPtitech/traQ/event" |
| 13 | + "github.com/traPtitech/traQ/model" |
| 14 | + "github.com/traPtitech/traQ/service/bot/event" |
| 15 | + "github.com/traPtitech/traQ/service/bot/event/payload" |
| 16 | + "github.com/traPtitech/traQ/service/bot/handler/mock_handler" |
| 17 | +) |
| 18 | + |
| 19 | +func TestUserActivated(t *testing.T) { |
| 20 | + t.Parallel() |
| 21 | + |
| 22 | + b := &model.Bot{ |
| 23 | + ID: uuid.NewV3(uuid.Nil, "b"), |
| 24 | + BotUserID: uuid.NewV3(uuid.Nil, "bu"), |
| 25 | + SubscribeEvents: model.BotEventTypesFromArray([]string{event.UserActivated.String()}), |
| 26 | + State: model.BotActive, |
| 27 | + } |
| 28 | + |
| 29 | + t.Run("success", func(t *testing.T) { |
| 30 | + t.Parallel() |
| 31 | + ctrl := gomock.NewController(t) |
| 32 | + handlerCtx := mock_handler.NewMockContext(ctrl) |
| 33 | + registerBot(t, handlerCtx, b) |
| 34 | + |
| 35 | + user := &model.User{ |
| 36 | + ID: uuid.NewV3(uuid.Nil, "u"), |
| 37 | + Name: "activated_user", |
| 38 | + Status: model.UserAccountStatusActive, |
| 39 | + Bot: false, |
| 40 | + } |
| 41 | + et := time.Now() |
| 42 | + |
| 43 | + expectMulticast(handlerCtx, event.UserActivated, payload.MakeUserActivated(et, user), []*model.Bot{b}) |
| 44 | + assert.NoError(t, UserActivated(handlerCtx, et, intevent.UserActivated, hub.Fields{ |
| 45 | + "user": user, |
| 46 | + })) |
| 47 | + }) |
| 48 | +} |
0 commit comments