generated from PenaSide/GolangTemplate
99 lines
3.0 KiB
Go
99 lines
3.0 KiB
Go
package e2e_test
|
||
|
||
import (
|
||
"context"
|
||
"fmt"
|
||
"github.com/stretchr/testify/assert"
|
||
"gitea.pena/PenaSide/customer/internal/models"
|
||
"gitea.pena/PenaSide/customer/pkg/client"
|
||
"gitea.pena/PenaSide/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("64ebda4387392e122e5d411f")
|
||
if isNoError := assert.NoError(t, tokenErr); !isNoError {
|
||
return
|
||
}
|
||
|
||
responseGetAccount, errGetAccount := client.Get[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
||
URL: "http://localhost:8082/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, "64ebda4387392e122e5d411f", 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("64e5e1ca87392e122e5d3de7")
|
||
if isNoError := assert.NoError(t, tokenErr); !isNoError {
|
||
return
|
||
}
|
||
|
||
responseGetAccount, errGetAccount := client.Get[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
||
URL: "http://localhost:8083/account/64e5e1ca87392e122e5d3de7",
|
||
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, "64e5e1ca87392e122e5d3de7", responseGetAccount.Body.UserID)
|
||
})
|
||
})
|
||
t.Run("Получение аккаунтов с пагинацией", func(t *testing.T) {
|
||
token, tokenErr := jwtUtil.Create("64e5e1ca87392e122e5d3de7")
|
||
if isNoError := assert.NoError(t, tokenErr); !isNoError {
|
||
return
|
||
}
|
||
ctx, cancel := context.WithCancel(context.Background())
|
||
defer cancel()
|
||
assert.NotPanics(t, func() {
|
||
|
||
page := 0
|
||
limit := 3
|
||
|
||
params := struct {
|
||
Page int
|
||
Limit int
|
||
}{
|
||
Page: page,
|
||
Limit: limit,
|
||
}
|
||
|
||
responseGetAccount, errGetAccount := client.Get[models.PaginationResponse[models.Account], models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
||
URL: "http://localhost:8083/accounts",
|
||
Body: params,
|
||
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
|
||
}
|
||
|
||
fmt.Println(responseGetAccount.Body)
|
||
})
|
||
})
|
||
}
|