This commit is contained in:
Pavel 2024-02-01 15:26:45 +03:00
parent 2f3574f93e
commit 4c2e997cb8
5 changed files with 89 additions and 3 deletions

@ -20,7 +20,7 @@ MONGO_AUTH=admin
KAFKA_BROKERS=localhost:9092
KAFKA_TOPIC_TARIFF=tariffs
AUTH_MICROSERVICE_USER_URL=http://pena-auth-service:8000/user
AUTH_MICROSERVICE_USER_URL=http://localhost:8002/user
HUBADMIN_MICROSERVICE_TARIFF_URL=http://localhost:8001/tariff
CURRENCY_MICROSERVICE_TRANSLATE_URL=http://cbrfworker-service:8000/change
DISCOUNT_MICROSERVICE_GRPC_HOST=localhost:9040

@ -402,11 +402,11 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL
Handler: si,
}
router.DELETE(baseURL+"/account", wrapper.DeleteAccount)
router.DELETE(baseURL+"/account", wrapper.DeleteAccount)//-
router.GET(baseURL+"/account", wrapper.GetAccount)
router.PATCH(baseURL+"/account", wrapper.ChangeAccount)
router.POST(baseURL+"/account", wrapper.AddAccount)
router.DELETE(baseURL+"/account/:userId", wrapper.DeleteDirectAccount)
router.DELETE(baseURL+"/account/:userId", wrapper.DeleteDirectAccount)//-
router.GET(baseURL+"/account/:userId", wrapper.GetDirectAccount)
router.PATCH(baseURL+"/account/:userId", wrapper.SetAccountVerificationStatus)
router.GET(baseURL+"/accounts", wrapper.PaginationAccounts)

@ -0,0 +1,42 @@
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 TestAddAccount(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("64e5d9830fcca0596d82c0c1")
if isNoError := assert.NoError(t, tokenErr); !isNoError {
return
}
responseAddAccount, errAddAccount := client.Post[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
URL: "http://localhost:8000/account",
Headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", token)},
QueryParams: map[string]string{"id": "64e5d9830fcca0596d82c0c1"},
})
if isNoError := assert.NoError(t, errAddAccount); !isNoError {
return
}
if isNoRequestError := assert.Nil(t, responseAddAccount.Error); !isNoRequestError {
return
}
assert.Equal(t, "64e5d9830fcca0596d82c0c1", responseAddAccount.Body.UserID)
})
})
}

@ -49,5 +49,29 @@ func TestChangeAccount(t *testing.T) {
assert.Equal(t, "Adios payasos", responseChangeAccount.Body.Name.Orgname)
assert.Equal(t, "payasos", responseChangeAccount.Body.Name.Secondname)
})
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)
})
})
}

@ -36,5 +36,25 @@ func TestGetAccount(t *testing.T) {
assert.Equal(t, "64e5d9830fcca0596d82c0c7", responseGetAccount.Body.UserID)
})
assert.NotPanics(t, func() {
token, tokenErr := jwtUtil.Create("64e5d9830fcca0596d82c0c7")
if isNoError := assert.NoError(t, tokenErr); !isNoError {
return
}
responseGetAccount, errGetAccount := client.Get[models.Account, models.ResponseErrorHTTP](ctx, &client.RequestSettings{
URL: "http://localhost:8000/account/64e5d9830fcca0596d82c0c7",
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, "64e5d9830fcca0596d82c0c7", responseGetAccount.Body.UserID)
})
})
}