github.com/k0marov/go-socnet@v0.0.0-20220715154813-90d07867c782/features/profiles/domain/contexters/contexters_test.go (about) 1 package contexters_test 2 3 import ( 4 likeable_contexters "github.com/k0marov/go-socnet/core/abstract/ownable_likeable/contexters" 5 "github.com/k0marov/go-socnet/core/general/core_values" 6 . "github.com/k0marov/go-socnet/core/helpers/test_helpers" 7 "testing" 8 9 "github.com/k0marov/go-socnet/features/profiles/domain/contexters" 10 "github.com/k0marov/go-socnet/features/profiles/domain/entities" 11 ) 12 13 func TestProfileContextAdder(t *testing.T) { 14 profile := RandomProfile() 15 caller := RandomId() 16 t.Run("happy case", func(t *testing.T) { 17 context := RandomLikeableContext() 18 getContext := func(targetId string, owner, callerId core_values.UserId) (likeable_contexters.OwnLikeContext, error) { 19 if targetId == profile.Id && owner == profile.Id && callerId == caller { 20 return context, nil 21 } 22 panic("unexpected args") 23 } 24 contextedProfile, err := contexters.NewProfileContextAdder(getContext)(profile, caller) 25 AssertNoError(t, err) 26 wantProfile := entities.ContextedProfile{ 27 Profile: profile, 28 OwnLikeContext: context, 29 } 30 Assert(t, contextedProfile, wantProfile, "returned profile") 31 }) 32 t.Run("error case - getting context throws", func(t *testing.T) { 33 getContext := func(targetId string, owner, callerId core_values.UserId) (likeable_contexters.OwnLikeContext, error) { 34 return likeable_contexters.OwnLikeContext{}, RandomError() 35 } 36 _, err := contexters.NewProfileContextAdder(getContext)(profile, caller) 37 AssertSomeError(t, err) 38 }) 39 40 }