forked from ebhomengo/niki
add benefactor kind box tests
Signed-off-by: Reza Mobaraki <rezam578@gmail.com>
This commit is contained in:
parent
a43e973b01
commit
92720e143f
|
@ -28,6 +28,10 @@ type BenefactorAddressTestSuit struct {
|
||||||
teardown func()
|
teardown func()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBenefactorAddressTestSuit(t *testing.T) {
|
||||||
|
suite.Run(t, new(BenefactorAddressTestSuit))
|
||||||
|
}
|
||||||
|
|
||||||
// SetupTest runs before each test in the suite
|
// SetupTest runs before each test in the suite
|
||||||
func (suite *BenefactorAddressTestSuit) SetupTest() {
|
func (suite *BenefactorAddressTestSuit) SetupTest() {
|
||||||
teardown := setup.SeedMariaDB(testContainer.GetMariaDBConfig())
|
teardown := setup.SeedMariaDB(testContainer.GetMariaDBConfig())
|
||||||
|
@ -68,10 +72,6 @@ func (suite *BenefactorAddressTestSuit) SetupTest() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBenefactorAddressTestSuit(t *testing.T) {
|
|
||||||
suite.Run(t, new(BenefactorAddressTestSuit))
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestBenefactorAddressGet tests the GET /address/:id endpoint
|
// TestBenefactorAddressGet tests the GET /address/:id endpoint
|
||||||
func (suite *BenefactorAddressTestSuit) TestBenefactorAddressGet() {
|
func (suite *BenefactorAddressTestSuit) TestBenefactorAddressGet() {
|
||||||
token := LoginBenefactor(suite.benefactorPhone)
|
token := LoginBenefactor(suite.benefactorPhone)
|
||||||
|
|
|
@ -0,0 +1,119 @@
|
||||||
|
//go:build end2end
|
||||||
|
|
||||||
|
package end2end
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/delivery/http_server/end2end/setup"
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
benefactorkindboxparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BenefactorKindBoxTestSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
benefactorPhone string
|
||||||
|
benefactorID uint
|
||||||
|
kindBoxID uint
|
||||||
|
kindBboxGetAllExpected map[string]interface{}
|
||||||
|
kindBoxGetExpected benefactorkindboxparam.KindBoxGetResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBenefactorKindBoxTestSuite(t *testing.T) {
|
||||||
|
suite.Run(t, new(BenefactorKindBoxTestSuite))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *BenefactorKindBoxTestSuite) SetupTest() {
|
||||||
|
teardown := setup.SeedMariaDB(testContainer.GetMariaDBConfig())
|
||||||
|
suite.T().Cleanup(teardown)
|
||||||
|
suite.benefactorPhone = "09384664404"
|
||||||
|
suite.kindBoxID = 1
|
||||||
|
suite.kindBboxGetAllExpected = map[string]interface{}{
|
||||||
|
"count": 1,
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
"ID" : 1,
|
||||||
|
"KindBoxReqID" : 1,
|
||||||
|
"BenefactorID" : 1,
|
||||||
|
"KindBoxType" : "on-table",
|
||||||
|
"Amount" : 0,
|
||||||
|
"SerialNumber" : "serial-1",
|
||||||
|
"Status" : "delivered",
|
||||||
|
"DeliverReferTimeID" : 1,
|
||||||
|
"DeliverReferDate" : "2024-08-26T18:19:26Z",
|
||||||
|
"DeliverAddressID" : 1,
|
||||||
|
"SenderAgentID" : 1,
|
||||||
|
"DeliveredAt" : "2024-09-02T18:19:26Z",
|
||||||
|
"ReturnReferTimeID" : 0,
|
||||||
|
"ReturnReferDate" : "0001-01-01T00:00:00Z",
|
||||||
|
"ReturnAddressID" : 0,
|
||||||
|
"ReceiverAgentID" : 0,
|
||||||
|
"ReturnedAt" : "0001-01-01T00:00:00Z"
|
||||||
|
*/
|
||||||
|
suite.kindBoxGetExpected = benefactorkindboxparam.KindBoxGetResponse{
|
||||||
|
KindBox: entity.KindBox{
|
||||||
|
ID: suite.kindBoxID,
|
||||||
|
KindBoxReqID: 1,
|
||||||
|
BenefactorID: 1,
|
||||||
|
KindBoxType: "on-table",
|
||||||
|
Amount: 0,
|
||||||
|
SerialNumber: "serial-1",
|
||||||
|
Status: "delivered",
|
||||||
|
DeliverReferTimeID: 1,
|
||||||
|
DeliverReferDate: time.Now().AddDate(0, 0, 7).UTC(),
|
||||||
|
DeliverAddressID: 1,
|
||||||
|
SenderAgentID: 1,
|
||||||
|
DeliveredAt: time.Now().AddDate(0, 0, 7).UTC(),
|
||||||
|
ReturnReferTimeID: 0,
|
||||||
|
ReturnReferDate: time.Time{},
|
||||||
|
ReturnAddressID: 0,
|
||||||
|
ReceiverAgentID: 0,
|
||||||
|
ReturnedAt: time.Time{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *BenefactorKindBoxTestSuite) TestBenefactorKindBoxGetAll() {
|
||||||
|
token := LoginBenefactor(suite.benefactorPhone)
|
||||||
|
url := fmt.Sprintf("/benefactor/kindboxes")
|
||||||
|
responseRecord := CreateRequest("GET", url, token, nil)
|
||||||
|
suite.Require().Equal(http.StatusOK, responseRecord.Code)
|
||||||
|
|
||||||
|
var response benefactorkindboxparam.KindBoxGetAllResponse
|
||||||
|
err := json.NewDecoder(responseRecord.Body).Decode(&response)
|
||||||
|
suite.Require().NoError(err)
|
||||||
|
suite.Require().Equal(suite.kindBboxGetAllExpected["count"], len(response.AllKindBox))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *BenefactorKindBoxTestSuite) TestBenefactorKindBoxGet() {
|
||||||
|
token := LoginBenefactor(suite.benefactorPhone)
|
||||||
|
url := fmt.Sprintf("/benefactor/kindboxes/%d", suite.kindBoxID)
|
||||||
|
responseRecord := CreateRequest("GET", url, token, nil)
|
||||||
|
suite.Require().Equal(http.StatusOK, responseRecord.Code)
|
||||||
|
|
||||||
|
var response benefactorkindboxparam.KindBoxGetResponse
|
||||||
|
err := json.NewDecoder(responseRecord.Body).Decode(&response)
|
||||||
|
suite.Require().NoError(err)
|
||||||
|
suite.Require().Equal(suite.kindBoxGetExpected.KindBox.ID, response.KindBox.ID)
|
||||||
|
suite.Require().Equal(suite.kindBoxGetExpected.KindBox.KindBoxReqID, response.KindBox.KindBoxReqID)
|
||||||
|
suite.Require().Equal(suite.kindBoxGetExpected.KindBox.BenefactorID, response.KindBox.BenefactorID)
|
||||||
|
suite.Require().Equal(suite.kindBoxGetExpected.KindBox.KindBoxType, response.KindBox.KindBoxType)
|
||||||
|
suite.Require().Equal(suite.kindBoxGetExpected.KindBox.Amount, response.KindBox.Amount)
|
||||||
|
suite.Require().Equal(suite.kindBoxGetExpected.KindBox.SerialNumber, response.KindBox.SerialNumber)
|
||||||
|
suite.Require().Equal(suite.kindBoxGetExpected.KindBox.Status, response.KindBox.Status)
|
||||||
|
suite.Require().Equal(suite.kindBoxGetExpected.KindBox.DeliverReferTimeID, response.KindBox.DeliverReferTimeID)
|
||||||
|
suite.Require().Equal(suite.kindBoxGetExpected.KindBox.DeliverReferDate.Format("2006-01-02"), response.KindBox.DeliverReferDate.Format("2006-01-02"))
|
||||||
|
suite.Require().Equal(suite.kindBoxGetExpected.KindBox.DeliverAddressID, response.KindBox.DeliverAddressID)
|
||||||
|
suite.Require().Equal(suite.kindBoxGetExpected.KindBox.SenderAgentID, response.KindBox.SenderAgentID)
|
||||||
|
suite.Require().Equal(suite.kindBoxGetExpected.KindBox.DeliveredAt.Format("2006-01-02"), response.KindBox.DeliveredAt.Format("2006-01-02"))
|
||||||
|
suite.Require().Equal(suite.kindBoxGetExpected.KindBox.ReturnReferTimeID, response.KindBox.ReturnReferTimeID)
|
||||||
|
suite.Require().Equal(suite.kindBoxGetExpected.KindBox.ReturnReferDate.Format("2006-01-02"), response.KindBox.ReturnReferDate.Format("2006-01-02"))
|
||||||
|
suite.Require().Equal(suite.kindBoxGetExpected.KindBox.ReturnAddressID, response.KindBox.ReturnAddressID)
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue