3
0
corteza/system/service/user_test.go
Tit Petric fdf24b3e2c Refactor for new system service
- upd(all): indent spec.json files on all apps
- upd(auth): rename auth app to cmd
- upd(sam): move orgs, teams to system
- upd(system): extend spec.json for check
- upd(codegen): include system/
- upd(codegen): always generate spec files
- upd(sam): references from auth to system
2018-11-05 12:04:04 +01:00

41 lines
822 B
Go

package service
import (
"context"
"testing"
"github.com/crusttech/crust/system/types"
"github.com/golang/mock/gomock"
"github.com/titpetric/factory"
)
func TestUser(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
usr := &types.User{ID: factory.Sonyflake.NextID()}
usrRpoMock := NewMockRepository(mockCtrl)
usrRpoMock.EXPECT().WithCtx(gomock.Any()).AnyTimes().Return(usrRpoMock)
usrRpoMock.EXPECT().
FindUserByID(usr.ID).
Times(1).
Return(usr, nil)
svc := User()
svc.rpo = usrRpoMock
found, err := svc.FindByID(context.Background(), usr.ID)
if err != nil {
t.Fatal("Did not expect an error")
}
if found == nil {
t.Fatal("Expecting an user to be found")
}
if found.ID != usr.ID {
t.Fatal("Expecting found user to have the same ID as the find param")
}
}