customer/tests/e2e/getAccount_test.go

94 lines
2.9 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-03-11 18:19:39 +00:00
URL: "http://localhost:8082/account",
2024-02-01 11:39:55 +00:00
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)
})
2024-02-01 12:58:51 +00:00
})
t.Run("Получение аккаунта юзера по id", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
2024-02-01 12:26:45 +00:00
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-03-11 18:19:39 +00:00
URL: "http://localhost:8082/account/64e5d9830fcca0596d82c0c7",
2024-02-01 12:26:45 +00:00
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)
})
2024-02-01 11:28:21 +00:00
})
2024-02-01 12:58:51 +00:00
t.Run("Получение аккаунтов с пагинацией", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
assert.NotPanics(t, func() {
page := 0
limit := 3
2024-05-20 12:32:59 +00:00
params := struct {
Page int
Limit int
}{
Page: page,
Limit: limit,
2024-02-01 12:58:51 +00:00
}
responseGetAccount, errGetAccount := client.Get[models.PaginationResponse[models.Account], models.ResponseErrorHTTP](ctx, &client.RequestSettings{
2024-03-11 18:19:39 +00:00
URL: "http://localhost:8082/accounts",
2024-02-01 12:58:51 +00:00
Body: params,
})
if isNoError := assert.NoError(t, errGetAccount); !isNoError {
return
}
if isNoRequestError := assert.Nil(t, responseGetAccount.Error); !isNoRequestError {
return
}
fmt.Println(responseGetAccount.Body)
})
})
2024-02-01 11:28:21 +00:00
}