generated from VLADIMIR/template
fix
This commit is contained in:
@@ -12,8 +12,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"evening_detective_server/internal/repos/teams_repo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TeamRegistrationHandler принимает вебхук Яндекс Форм отдельно от пользовательского JWT.
|
// TeamRegistrationHandler принимает вебхук Яндекс Форм отдельно от пользовательского JWT.
|
||||||
@@ -65,7 +63,7 @@ func TeamRegistrationHandler(token string, register func(context.Context, int, s
|
|||||||
switch {
|
switch {
|
||||||
case errors.Is(err, team_service.ErrInvalidRegistration):
|
case errors.Is(err, team_service.ErrInvalidRegistration):
|
||||||
fail(http.StatusBadRequest, err.Error())
|
fail(http.StatusBadRequest, err.Error())
|
||||||
case errors.Is(err, teams_repo.ErrRegistrationClosed):
|
case errors.Is(err, team_service.ErrRegistrationClosed):
|
||||||
fail(http.StatusConflict, err.Error())
|
fail(http.StatusConflict, err.Error())
|
||||||
case err != nil:
|
case err != nil:
|
||||||
fail(http.StatusInternalServerError, "Не удалось зарегистрировать команду")
|
fail(http.StatusInternalServerError, "Не удалось зарегистрировать команду")
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"evening_detective_server/internal/repos/teams_repo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTeamRegistrationHandler(t *testing.T) {
|
func TestTeamRegistrationHandler(t *testing.T) {
|
||||||
@@ -34,7 +32,7 @@ func TestTeamRegistrationHandler(t *testing.T) {
|
|||||||
{"jsonrpc string count", "secret", "Bearer secret", "42", "delivery", `{"jsonrpc":"2.0","method":"register","params":{"name":"Команда","email":"captain@example.org","participantsCount":"5"},"id":1}`, nil, 200, true},
|
{"jsonrpc string count", "secret", "Bearer secret", "42", "delivery", `{"jsonrpc":"2.0","method":"register","params":{"name":"Команда","email":"captain@example.org","participantsCount":"5"},"id":1}`, nil, 200, true},
|
||||||
{"too large", "secret", "Bearer secret", "42", "delivery", `{"name":"` + strings.Repeat("a", 17000) + `"}`, nil, 400, false},
|
{"too large", "secret", "Bearer secret", "42", "delivery", `{"name":"` + strings.Repeat("a", 17000) + `"}`, nil, 400, false},
|
||||||
{"invalid fields", "secret", "Bearer secret", "42", "delivery", valid, team_service.ErrInvalidRegistration, 400, true},
|
{"invalid fields", "secret", "Bearer secret", "42", "delivery", valid, team_service.ErrInvalidRegistration, 400, true},
|
||||||
{"closed", "secret", "Bearer secret", "42", "delivery", valid, teams_repo.ErrRegistrationClosed, 409, true},
|
{"closed", "secret", "Bearer secret", "42", "delivery", valid, team_service.ErrRegistrationClosed, 409, true},
|
||||||
{"internal", "secret", "Bearer secret", "42", "delivery", valid, errors.New("private database detail"), 500, true},
|
{"internal", "secret", "Bearer secret", "42", "delivery", valid, errors.New("private database detail"), 500, true},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
|||||||
@@ -10,7 +10,12 @@ import (
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrInvalidRegistration = errors.New("Укажите название команды (до 255 символов), почту капитана и положительное количество участников")
|
var (
|
||||||
|
// ErrInvalidRegistration — входные данные регистрации команды некорректны.
|
||||||
|
ErrInvalidRegistration = errors.New("Укажите название команды (до 255 символов), почту капитана и положительное количество участников")
|
||||||
|
// ErrRegistrationClosed — игра не найдена или регистрация в неё закрыта.
|
||||||
|
ErrRegistrationClosed = errors.New("Игра не найдена или регистрация уже закрыта")
|
||||||
|
)
|
||||||
|
|
||||||
type Registration struct {
|
type Registration struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|||||||
@@ -96,6 +96,9 @@ func (s *TeamService) RegisterTeam(ctx context.Context, gameID int, deliveryID s
|
|||||||
autoConfirm := time.Now().Before(game.StartAt.Add(-24*time.Hour)) == false
|
autoConfirm := time.Now().Before(game.StartAt.Add(-24*time.Hour)) == false
|
||||||
id, err := s.teamsRepo.RegisterTeamWithParticipation(ctx, gameID, deliveryID, registration.Name, registration.Email, registration.ParticipantsCount, password, autoConfirm)
|
id, err := s.teamsRepo.RegisterTeamWithParticipation(ctx, gameID, deliveryID, registration.Name, registration.Email, registration.ParticipantsCount, password, autoConfirm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, teams_repo.ErrRegistrationClosed) {
|
||||||
|
return 0, ErrRegistrationClosed
|
||||||
|
}
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
if s.emailSender == nil {
|
if s.emailSender == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user