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"
|
2024-11-18 07:23:41 +00:00
|
|
|
|
"gitea.pena/PenaSide/customer/internal/models"
|
|
|
|
|
"gitea.pena/PenaSide/customer/pkg/client"
|
|
|
|
|
"gitea.pena/PenaSide/customer/tests/helpers"
|
2024-02-01 11:28:21 +00:00
|
|
|
|
"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() {
|
2024-05-23 15:08:54 +00:00
|
|
|
|
token, tokenErr := jwtUtil.Create("64ebda4387392e122e5d411f")
|
2024-02-01 11:28:21 +00:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-23 15:08:54 +00:00
|
|
|
|
assert.Equal(t, "64ebda4387392e122e5d411f", responseGetAccount.Body.UserID)
|
2024-02-01 11:28:21 +00:00
|
|
|
|
})
|
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() {
|
2024-05-23 15:08:54 +00:00
|
|
|
|
token, tokenErr := jwtUtil.Create("64e5e1ca87392e122e5d3de7")
|
2024-02-01 12:26:45 +00:00
|
|
|
|
if isNoError := assert.NoError(t, tokenErr); !isNoError {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
responseGetAccount, errGetAccount := client.Get[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
2024-06-10 10:16:24 +00:00
|
|
|
|
URL: "http://localhost:8083/account/64e5e1ca87392e122e5d3de7",
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-23 15:08:54 +00:00
|
|
|
|
assert.Equal(t, "64e5e1ca87392e122e5d3de7", responseGetAccount.Body.UserID)
|
2024-02-01 12:26:45 +00:00
|
|
|
|
})
|
2024-02-01 11:28:21 +00:00
|
|
|
|
})
|
2024-02-01 12:58:51 +00:00
|
|
|
|
t.Run("Получение аккаунтов с пагинацией", func(t *testing.T) {
|
2024-06-10 10:16:24 +00:00
|
|
|
|
token, tokenErr := jwtUtil.Create("64e5e1ca87392e122e5d3de7")
|
|
|
|
|
if isNoError := assert.NoError(t, tokenErr); !isNoError {
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-02-01 12:58:51 +00:00
|
|
|
|
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-06-10 10:16:24 +00:00
|
|
|
|
URL: "http://localhost:8083/accounts",
|
|
|
|
|
Body: params,
|
|
|
|
|
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
|
2024-02-01 12:58:51 +00:00
|
|
|
|
})
|
|
|
|
|
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
|
|
|
|
}
|