generated from VLADIMIR/template
fix
This commit is contained in:
@@ -31,6 +31,9 @@ func participationError(err error) string {
|
||||
}
|
||||
func (s *server) GetParticipation(ctx context.Context, req *proto.GetParticipationReq) (*proto.ParticipationRsp, error) {
|
||||
_ = grpc.SetHeader(ctx, metadata.Pairs("Cache-Control", "no-store"))
|
||||
if req == nil {
|
||||
return &proto.ParticipationRsp{Error: participationError(participation_service.ErrParticipationLink)}, nil
|
||||
}
|
||||
p, err := s.participationService.GetParticipation(ctx, req.Token)
|
||||
result := mapParticipationResponse(p)
|
||||
if err != nil {
|
||||
@@ -40,8 +43,11 @@ func (s *server) GetParticipation(ctx context.Context, req *proto.GetParticipati
|
||||
}
|
||||
func (s *server) AnswerParticipation(ctx context.Context, req *proto.AnswerParticipationReq) (*proto.ParticipationRsp, error) {
|
||||
_ = grpc.SetHeader(ctx, metadata.Pairs("Cache-Control", "no-store"))
|
||||
if req == nil {
|
||||
return &proto.ParticipationRsp{Error: participationError(participation_service.ErrParticipationLink)}, nil
|
||||
}
|
||||
if req.Answer != "confirmed" && req.Answer != "cancelled" {
|
||||
return &proto.ParticipationRsp{Error: "Выберите подтверждение или отмену участия"}, nil
|
||||
return &proto.ParticipationRsp{Error: participation_service.ErrInvalidAnswer.Error()}, nil
|
||||
}
|
||||
p, err := s.participationService.AnswerParticipation(ctx, req.Token, req.Answer)
|
||||
result := mapParticipationResponse(p)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"evening_detective_server/internal/services/participation_service"
|
||||
)
|
||||
|
||||
func TestParticipationError(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
err error
|
||||
want string
|
||||
}{
|
||||
{"invalid link", participation_service.ErrParticipationLink, "Ссылка недействительна"},
|
||||
{"closed", participation_service.ErrParticipationClosed, "Приём ответов закрыт"},
|
||||
{"final", participation_service.ErrParticipationFinal, "Решение уже принято и не может быть изменено"},
|
||||
{"internal", errors.New("private database detail"), "Не удалось обработать ответ. Попробуйте позже."},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := participationError(tc.err); got != tc.want {
|
||||
t.Fatalf("message=%q, want %q", got, tc.want)
|
||||
}
|
||||
if strings.Contains(participationError(tc.err), "private database detail") {
|
||||
t.Fatal("private error exposed")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user