customer/tests/e2e/getAccount_test.go

41 lines
1.2 KiB
Go
Raw Normal View History

2024-02-01 11:39:55 +00:00
package e2e_test
2024-02-01 11:28:21 +00:00
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 TestGetAccount(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("64e5d9830fcca0596d82c0c7")
if isNoError := assert.NoError(t, tokenErr); !isNoError {
return
}
responseGetAccount, errGetAccount := client.Get[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
2024-02-01 11:39:55 +00:00
URL: "http://localhost:8000/account",
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
2024-02-01 11:28:21 +00:00
})
if isNoError := assert.NoError(t, errGetAccount); !isNoError {
return
}
if isNoRequestError := assert.Nil(t, responseGetAccount.Error); !isNoRequestError {
return
}
assert.Equal(t, "64e5d9830fcca0596d82c0c7", responseGetAccount.Body.UserID)
})
})
}