forked from ebhomengo/niki
1
0
Fork 0
niki/validator/benefactor/kind_box_req/update_test.go

55 lines
2.0 KiB
Go
Raw Permalink Normal View History

package benefactorkindboxreqvalidator
import (
"context"
"testing"
"time"
"git.gocasts.ir/ebhomengo/niki/entity"
addressparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/address"
kindboxreqparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
refertimeparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/refer_time"
"github.com/stretchr/testify/assert"
)
func TestValidator_ValidateUpdateRequest(t *testing.T) {
mockRepository := NewMockRepository(t)
mockBenefactorSvc := NewMockBenefactorSvc(t)
mockAddressSvc := NewMockAddressSvc(t)
mockReferTimeSvc := NewMockReferTimeSvc(t)
validator := New(mockBenefactorSvc, mockAddressSvc, mockReferTimeSvc, mockRepository)
ctx := context.Background()
t.Run("Successful validation", func(t *testing.T) {
req := kindboxreqparam.KindBoxReqUpdateRequest{
KindBoxReqID: 1,
BenefactorID: 1,
KindBoxType: entity.KindBoxOnTable,
CountRequested: 1,
Description: "test",
DeliverReferTimeID: 1,
DeliverReferDate: time.Now().Add(time.Hour * 24),
DeliverAddressID: 1,
}
mockRepository.EXPECT().KindBoxRequestExist(ctx, req.KindBoxReqID).Return(true, nil).Once()
mockRepository.EXPECT().GetKindBoxReqByID(ctx, req.KindBoxReqID).Return(
entity.KindBoxReq{BenefactorID: req.BenefactorID, Status: entity.KindBoxReqPendingStatus},
nil,
).Twice()
mockAddressSvc.EXPECT().AddressExistByID(ctx, addressparam.GetAddressByIDRequest{ID: req.DeliverAddressID}).Return(
addressparam.GetAddressByIDResponse{Address: entity.Address{BenefactorID: req.BenefactorID}},
nil,
).Once()
mockReferTimeSvc.EXPECT().GetReferTimeByID(ctx, refertimeparam.GetReferTimeRequest{ReferTimeID: req.DeliverReferTimeID}).Return(
refertimeparam.GetReferTimeResponse{ReferTime: entity.ReferTime{Status: entity.ReferTimeActiveStatus}},
nil,
).Once()
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
assert.NoError(t, err)
assert.Nil(t, fieldErrors)
})
}