2024-02-01 11:39:55 +00:00
|
|
|
package e2e_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"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"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestChangeAccount(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
|
|
|
|
}
|
|
|
|
|
|
|
|
updateRequest := models.Name{
|
|
|
|
Middlename: "Aloha",
|
|
|
|
FirstName: "Holla",
|
|
|
|
Orgname: "Adios payasos",
|
|
|
|
Secondname: "payasos",
|
|
|
|
}
|
|
|
|
|
|
|
|
responseChangeAccount, errChangeAccount := client.Patch[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
|
|
|
URL: "http://localhost:8000/account",
|
|
|
|
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
|
|
|
|
Body: updateRequest,
|
|
|
|
})
|
|
|
|
if isNoError := assert.NoError(t, errChangeAccount); !isNoError {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if isNoRequestError := assert.Nil(t, responseChangeAccount.Error); !isNoRequestError {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "64e5d9830fcca0596d82c0c7", responseChangeAccount.Body.UserID)
|
|
|
|
assert.Equal(t, "Aloha", responseChangeAccount.Body.Name.Middlename)
|
|
|
|
assert.Equal(t, "Holla", responseChangeAccount.Body.Name.FirstName)
|
|
|
|
assert.Equal(t, "Adios payasos", responseChangeAccount.Body.Name.Orgname)
|
|
|
|
assert.Equal(t, "payasos", responseChangeAccount.Body.Name.Secondname)
|
|
|
|
})
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
statusRequest := models.SetAccountStatus{
|
|
|
|
Status: models.AccountStatusOrg,
|
|
|
|
}
|
|
|
|
|
|
|
|
responseStatusAccount, errStatusAccount := client.Patch[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
|
|
|
|
URL: "http://localhost:8000/account/64e5d9830fcca0596d82c0c7",
|
|
|
|
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
|
|
|
|
Body: statusRequest,
|
|
|
|
})
|
|
|
|
if isNoError := assert.NoError(t, errStatusAccount); !isNoError {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if isNoRequestError := assert.Nil(t, responseStatusAccount.Error); !isNoRequestError {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, statusRequest.Status, responseStatusAccount.Body.Status)
|
|
|
|
})
|
2024-02-01 11:39:55 +00:00
|
|
|
})
|
|
|
|
}
|