generated from VLADIMIR/template
add conclusion
This commit is contained in:
@@ -710,6 +710,17 @@ func (s *server) UpdateScenarioIntro(ctx context.Context, req *proto.UpdateScena
|
||||
return &proto.UpdateScenarioIntroRsp{}, nil
|
||||
}
|
||||
|
||||
func (s *server) UpdateScenarioConclusion(ctx context.Context, req *proto.UpdateScenarioConclusionReq) (*proto.UpdateScenarioConclusionRsp, error) {
|
||||
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
if !roles.HasRole(claims, roles.Author) {
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if err := s.scenarioService.UpdateScenarioConclusion(ctx, int(req.Id), convertConclusion(req.Conclusion), claims.UserID, roles.HasRole(claims, roles.Admin)); err != nil {
|
||||
return &proto.UpdateScenarioConclusionRsp{Error: err.Error()}, nil
|
||||
}
|
||||
return &proto.UpdateScenarioConclusionRsp{}, nil
|
||||
}
|
||||
|
||||
// DownloadScenarioArchive отдаёт ZIP-архив сценария; ошибки — gRPC-статусами.
|
||||
func (s *server) DownloadScenarioArchive(ctx context.Context, req *proto.DownloadScenarioArchiveReq) (*httpbody.HttpBody, error) {
|
||||
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
|
||||
@@ -49,11 +49,26 @@ func mapStory(o *storytelling.Story) *proto.Story {
|
||||
return &proto.Story{
|
||||
Background: o.Background,
|
||||
Introduction: mapIntroduction(o.Introduction),
|
||||
Conclusion: mapConclusion(o.Conclusion),
|
||||
Places: mapPlaces(o.Places),
|
||||
Questions: mapQuestions(o.Questions),
|
||||
}
|
||||
}
|
||||
|
||||
func mapConclusion(o *storytelling.Conclusion) *proto.Conclusion {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return &proto.Conclusion{Text: o.Text, Video: o.Video}
|
||||
}
|
||||
|
||||
func convertConclusion(o *proto.Conclusion) *storytelling.Conclusion {
|
||||
if o == nil || (o.Text == "" && o.Video == "") {
|
||||
return nil
|
||||
}
|
||||
return &storytelling.Conclusion{Text: textFormatter.FormatText(o.Text), Video: o.Video}
|
||||
}
|
||||
|
||||
func mapIntroduction(o *storytelling.Introduction) *proto.Introduction {
|
||||
if o == nil {
|
||||
return nil
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"evening_detective_server/internal/modules/cleaner"
|
||||
"evening_detective_server/internal/modules/storytelling"
|
||||
proto "evening_detective_server/proto"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
)
|
||||
|
||||
func TestConclusionMapping(t *testing.T) {
|
||||
input := &proto.Conclusion{Text: "Разгадка", Video: "ending.mp4"}
|
||||
story := &storytelling.Story{Conclusion: convertConclusion(input)}
|
||||
if got := mapStory(story).Conclusion; got == nil || got.Text != input.Text || got.Video != input.Video {
|
||||
t.Fatalf("author conclusion: %+v", got)
|
||||
}
|
||||
player := storytelling.NewStory(cleaner.NewCleaner()).GetStory(story, nil)
|
||||
data, err := protojson.Marshal(mapStory(player))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(string(data), "conclusion") || strings.Contains(string(data), input.Text) || strings.Contains(string(data), input.Video) {
|
||||
t.Fatalf("player response leaks conclusion: %s", data)
|
||||
}
|
||||
if convertConclusion(nil) != nil || convertConclusion(&proto.Conclusion{}) != nil {
|
||||
t.Fatal("empty conclusion must clear it")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user