forked from ebhomengo/niki
1
0
Fork 0

add benefactor kind box tests

Signed-off-by: Reza Mobaraki <rezam578@gmail.com>
This commit is contained in:
Reza Mobaraki 2024-09-02 21:55:16 +03:30
parent a43e973b01
commit 92720e143f
No known key found for this signature in database
GPG Key ID: 922CBCF25B541A6F
2 changed files with 123 additions and 4 deletions

View File

@ -28,6 +28,10 @@ type BenefactorAddressTestSuit struct {
teardown func()
}
func TestBenefactorAddressTestSuit(t *testing.T) {
suite.Run(t, new(BenefactorAddressTestSuit))
}
// SetupTest runs before each test in the suite
func (suite *BenefactorAddressTestSuit) SetupTest() {
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
func (suite *BenefactorAddressTestSuit) TestBenefactorAddressGet() {
token := LoginBenefactor(suite.benefactorPhone)

View File

@ -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)
}