package e2e

import (
	"context"
	"fmt"
	"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"
	"testing"
)

func TestPostWalletRspay(t *testing.T) {
	jwtUtil := helpers.InitializeJWT()

	t.Run("rspay", func(t *testing.T) {
		ctx, cancel := context.WithCancel(context.Background())
		defer cancel()

		req := struct {
			Money float32
		}{
			Money: 100,
		}

		assert.NotPanics(t, func() {
			token, tokenErr := jwtUtil.Create("6597babdd1ba7e2dbd32d7e3")
			if isNoError := assert.NoError(t, tokenErr); !isNoError {
				return
			}

			response, err := client.Post[interface{}, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
				URL:     "http://localhost:8082/wallet/rspay",
				Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
				Body:    req,
			})
			if isNoError := assert.NoError(t, err); !isNoError {
				return
			}
			if isNoRequestError := assert.Nil(t, response.Error); !isNoRequestError {
				return
			}
		})
	})

}
