package e2e_test

import (
	"context"
	"fmt"
	"github.com/stretchr/testify/assert"
	"net/http"
	"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 TestCurrencies(t *testing.T) {
	jwtUtil := helpers.InitializeJWT()
	t.Run("Получение текущих доступных курсов", func(t *testing.T) {
		ctx, cancel := context.WithCancel(context.Background())
		defer cancel()

		assert.NotPanics(t, func() {
			token, tokenErr := jwtUtil.Create("6597babdd1ba7e2dbd32d7e3")
			if isNoError := assert.NoError(t, tokenErr); !isNoError {
				return
			}
			responseGetCurrencies, errCurrencies := client.Get[[]models.CurrencyList, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
				URL:     "http://localhost:8082/currencies",
				Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
			})
			if isNoError := assert.NoError(t, errCurrencies); !isNoError {
				return
			}
			if isNoRequestError := assert.Nil(t, responseGetCurrencies.Error); !isNoRequestError {
				return
			}

			fmt.Println(responseGetCurrencies.Body)
			assert.Equal(t, http.StatusOK, responseGetCurrencies.StatusCode)
		})
	})

}
