package benefactorkindboxreqservice_test import ( "context" "fmt" "testing" "time" benefactorkindboxreqparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" benefactorkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box_req" "git.gocasts.ir/ebhomengo/niki/test/mock" "github.com/stretchr/testify/assert" ) func TestAdd(t *testing.T) { testCases := []struct { name string repoErr bool expectedErr error req benefactorkindboxreqparam.KindBoxReqAddRequest }{ { name: "repo fails", repoErr: true, expectedErr: richerror.New("userkindboxreqservice.Add").WithErr(fmt.Errorf(benefactorkindboxreqmock.RepoErr)).WithKind(richerror.KindUnexpected), req: benefactorkindboxreqparam.KindBoxReqAddRequest{ BenefactorID: 1, AddressID: 1, ReferDate: time.Now(), CountRequested: 1, TypeID: 1, }, }, { name: "ordinary", req: benefactorkindboxreqparam.KindBoxReqAddRequest{ BenefactorID: 1, AddressID: 1, ReferDate: time.Now(), CountRequested: 1, TypeID: 1, }, }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { repo := benefactorkindboxreqmock.NewMockRepository(tc.repoErr) svc := benefactorkindboxreqservice.New(repo) ctx := context.Background() kindBoxreq, err := svc.Add(ctx, tc.req) if tc.expectedErr != nil { assert.Equal(t, tc.expectedErr.Error(), err.Error()) assert.Empty(t, kindBoxreq) return } assert.NoError(t, err) assert.NotEmpty(t, kindBoxreq) }) } }