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

134 lines
4.7 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 TestSetAccountVerificationStatusNO(t *testing.T) {
jwtUtil := helpers.InitializeJWT()
t.Run("Успешная установка статуса верификации <no> аккаунту", 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/807f1f77bcf81cd799439077",
Body: models.SetAccountStatus{Status: models.AccountStatusNo},
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, models.AccountStatusNo, response.Body.Status)
})
})
}
func TestSetAccountVerificationStatusORG(t *testing.T) {
jwtUtil := helpers.InitializeJWT()
t.Run("Успешная установка статуса верификации <org> аккаунту", 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/807f1f77bcf81cd799439077",
Body: models.SetAccountStatus{Status: models.AccountStatusOrg},
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, models.AccountStatusOrg, response.Body.Status)
})
})
}
func TestSetAccountVerificationStatusNKO(t *testing.T) {
jwtUtil := helpers.InitializeJWT()
t.Run("Успешная установка статуса верификации <nko> аккаунту", 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/807f1f77bcf81cd799439077",
Body: models.SetAccountStatus{Status: models.AccountStatusNko},
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, models.AccountStatusNko, response.Body.Status)
})
})
}
func TestSetAccountVerificationStatusFailure(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/807f1f77bcf81cd799439077",
Body: models.SetAccountStatus{Status: "radnom-status"},
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
})
if isNoError := assert.NoError(t, getAccountErr); !isNoError {
return
}
if isNotNil := assert.NotNil(t, response.Error); isNotNil {
assert.Equal(t, 400, response.StatusCode)
}
})
})
}