package e2e_test 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" ) 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{ URL: "http://localhost:8000/account", Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)}, }) if isNoError := assert.NoError(t, errGetAccount); !isNoError { return } if isNoRequestError := assert.Nil(t, responseGetAccount.Error); !isNoRequestError { return } assert.Equal(t, "64e5d9830fcca0596d82c0c7", responseGetAccount.Body.UserID) }) }) t.Run("Получение аккаунта юзера по id", 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{ URL: "http://localhost:8000/account/64e5d9830fcca0596d82c0c7", Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)}, }) if isNoError := assert.NoError(t, errGetAccount); !isNoError { return } if isNoRequestError := assert.Nil(t, responseGetAccount.Error); !isNoRequestError { return } assert.Equal(t, "64e5d9830fcca0596d82c0c7", responseGetAccount.Body.UserID) }) }) t.Run("Получение аккаунтов с пагинацией", func(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() assert.NotPanics(t, func() { page := 0 limit := 3 params := swagger.PaginationAccountsParams{ Page: &page, Limit: &limit, } responseGetAccount, errGetAccount := client.Get[models.PaginationResponse[models.Account], models.ResponseErrorHTTP](ctx, &client.RequestSettings{ URL: "http://localhost:8000/accounts", Body: params, }) if isNoError := assert.NoError(t, errGetAccount); !isNoError { return } if isNoRequestError := assert.Nil(t, responseGetAccount.Error); !isNoRequestError { return } fmt.Println(responseGetAccount.Body) }) }) }