generated from PenaSide/GolangTemplate
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package integration
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/stretchr/testify/assert"
|
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/swagger"
|
|
"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"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestCalculateLTV(t *testing.T) {
|
|
ctx := context.Background()
|
|
jwtUtil := helpers.InitializeJWT()
|
|
token, err := jwtUtil.Create("807f1f77bcf81cd799439077")
|
|
|
|
if ok := assert.NoError(t, err); !ok {
|
|
return
|
|
}
|
|
|
|
layout := "2006-01-02T15:04:05.000Z"
|
|
fromString := "2023-11-08T22:29:48.719Z"
|
|
toString := "2023-12-27T15:00:00.000Z"
|
|
fromTime, err := time.Parse(layout, fromString)
|
|
if err != nil {
|
|
fmt.Println("error:", err)
|
|
}
|
|
toTime, err := time.Parse(layout, toString)
|
|
if err != nil {
|
|
fmt.Println("error:", err)
|
|
}
|
|
from := fromTime.Unix()
|
|
to := toTime.Unix()
|
|
fmt.Println(from, to)
|
|
|
|
response, err := client.Post[struct{}, 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)},
|
|
})
|
|
if ok := assert.NoError(t, err); !ok {
|
|
return
|
|
}
|
|
if ok := assert.Nil(t, response.Error); !ok {
|
|
return
|
|
}
|
|
|
|
assert.Equal(t, 200, response.StatusCode)
|
|
|
|
fmt.Println(response.Body)
|
|
}
|