generated from PenaSide/GolangTemplate
add test
This commit is contained in:
parent
fbf19a2630
commit
370a2c7e2c
@ -606,6 +606,8 @@ func (api *API2) CalculateLTV(ctx echo.Context) error {
|
||||
return api.error(ctx, http.StatusBadRequest, "failed to bind request")
|
||||
}
|
||||
|
||||
fmt.Println(req)
|
||||
|
||||
if req.From > req.To && req.To != 0 {
|
||||
api.logger.Error("From timestamp must be less than To timestamp unless To is 0")
|
||||
return api.error(ctx, http.StatusBadRequest, "From timestamp must be less than To timestamp unless To is 0")
|
||||
@ -623,6 +625,8 @@ func (api *API2) CalculateLTV(ctx echo.Context) error {
|
||||
LTV: ltv,
|
||||
}
|
||||
|
||||
fmt.Println(response)
|
||||
|
||||
return ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
@ -651,6 +655,7 @@ func (api *API2) GetRecentTariffs(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
func (api *API2) SendReport(ctx echo.Context) error {
|
||||
fmt.Println("SendReport")
|
||||
historyID := ctx.Param("id")
|
||||
if historyID == "" {
|
||||
api.logger.Error("history id is missing in <GetHistoryById> of <HistoryService>")
|
||||
|
@ -1,4 +1,4 @@
|
||||
package integration
|
||||
package e2e_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -36,8 +36,8 @@ func TestCalculateLTV(t *testing.T) {
|
||||
to := toTime.Unix()
|
||||
fmt.Println(from, to)
|
||||
|
||||
response, err := client.Post[struct{}, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
||||
URL: "http://" + "localhost:8000" + "/history/ltv",
|
||||
response, err := client.Post[interface{}, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
||||
URL: "http://localhost:8000/history/ltv",
|
||||
Body: swagger.CalculateLTVJSONBody{From: from, To: to},
|
||||
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
|
||||
})
|
35
tests/e2e/recentTariffs_test.go
Normal file
35
tests/e2e/recentTariffs_test.go
Normal file
@ -0,0 +1,35 @@
|
||||
package e2e_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/client"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/tests/helpers"
|
||||
)
|
||||
|
||||
func TestGetRecentTariffs(t *testing.T) {
|
||||
jwtUtil := helpers.InitializeJWT()
|
||||
|
||||
t.Run("Get Recent Tariffs", func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
userID := "64e5d9830fcca0596d82c0c7"
|
||||
|
||||
token, tokenErr := jwtUtil.Create(userID)
|
||||
assert.NoError(t, tokenErr)
|
||||
|
||||
responseGetRecentTariffs, errGetRecentTariffs := client.Get[[]models.TariffID, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
||||
URL: "http://localhost:8000/recent",
|
||||
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
|
||||
})
|
||||
assert.NoError(t, errGetRecentTariffs)
|
||||
assert.Nil(t, responseGetRecentTariffs.Error)
|
||||
fmt.Println(responseGetRecentTariffs.Body)
|
||||
assert.NotNil(t, responseGetRecentTariffs.Body)
|
||||
})
|
||||
}
|
38
tests/e2e/sendReport_test.go
Normal file
38
tests/e2e/sendReport_test.go
Normal file
@ -0,0 +1,38 @@
|
||||
package e2e_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/client"
|
||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/tests/helpers"
|
||||
)
|
||||
|
||||
// todo thinking
|
||||
func TestSendReport(t *testing.T) {
|
||||
jwtUtil := helpers.InitializeJWT()
|
||||
|
||||
t.Run("Send Report", func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
historyID := "641b2d73e0e07a7e90b59616"
|
||||
|
||||
token, tokenErr := jwtUtil.Create("64e5d9830fcca0596d82c0c1")
|
||||
assert.NoError(t, tokenErr)
|
||||
|
||||
responseSendReport, errSendReport := client.Post[interface{}, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
||||
URL: "http://localhost:8000/sendReport",
|
||||
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
|
||||
Body: map[string]interface{}{"id": historyID},
|
||||
})
|
||||
assert.NoError(t, errSendReport)
|
||||
assert.Nil(t, responseSendReport.Error)
|
||||
|
||||
assert.Equal(t, http.StatusOK, responseSendReport.StatusCode)
|
||||
})
|
||||
}
|
@ -22,7 +22,7 @@ func TestHistoryReport(t *testing.T) {
|
||||
}
|
||||
|
||||
response, err := client.Post[struct{}, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
||||
URL: "http://" + customerServiceBase + "/sendReport",
|
||||
URL: "http://" + "localhost:8000" + "/sendReport",
|
||||
Body: swagger.SendReportJSONBody{Id: "10002"},
|
||||
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user