customer/tests/integration/update_account_name_test.go
2023-09-14 10:07:28 +00:00

52 lines
1.6 KiB
Go

package integration_test
import (
"context"
"fmt"
"testing"
"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"
)
func TestUpdateAccountName(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("807f1f77bcf81cd799439077")
if isNoError := assert.NoError(t, tokenErr); !isNoError {
return
}
response, getAccountErr := client.Patch[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
URL: "http://localhost:8082/account",
Body: models.Name{
FirstName: "Ivan",
Secondname: "Ivanov",
Middlename: "Ivanovich",
Orgname: "OOO Моя Оборона",
},
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
})
if isNoError := assert.NoError(t, getAccountErr); !isNoError {
return
}
if isNoRequestError := assert.Nil(t, response.Error); !isNoRequestError {
return
}
assert.Equal(t, "807f1f77bcf81cd799439077", response.Body.UserID)
assert.Equal(t, "Ivan", response.Body.Name.FirstName)
assert.Equal(t, "Ivanov", response.Body.Name.Secondname)
assert.Equal(t, "Ivanovich", response.Body.Name.Middlename)
assert.Equal(t, "OOO Моя Оборона", response.Body.Name.Orgname)
})
})
}