generated from VLADIMIR/template
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package app
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"evening_detective_server/internal/modules/team_qr_pdf"
|
|
"evening_detective_server/internal/services/game_model"
|
|
"evening_detective_server/proto"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
)
|
|
|
|
func TestGameWiFiVisibility(t *testing.T) {
|
|
game := &game_model.Game{WiFiName: "Детектив", WiFiPassword: "secret"}
|
|
settings := mapGameSettings(game)
|
|
if settings.WifiName != game.WiFiName || settings.WifiPassword != game.WiFiPassword {
|
|
t.Fatal("management settings missing")
|
|
}
|
|
for _, result := range []*proto.Game{mapGame(game), mapGameSummary(game)} {
|
|
if result.WifiName != "" || result.WifiPassword != "" {
|
|
t.Fatal("Wi-Fi exposed outside management settings")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGameWiFiOptionalUpdate(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
body string
|
|
present bool
|
|
}{
|
|
{`{}`, false},
|
|
{`{"wifiName":"", "wifiPassword":""}`, true},
|
|
{`{"wifiName":"Venue", "wifiPassword":" secret "}`, true},
|
|
} {
|
|
var req proto.UpdateGameReq
|
|
if err := protojson.Unmarshal([]byte(tc.body), &req); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if (req.WifiName != nil) != tc.present || (req.WifiPassword != nil) != tc.present {
|
|
t.Fatal("missing fields cannot be distinguished from clearing")
|
|
}
|
|
}
|
|
if got := status.Code(gameErrorStatus(team_qr_pdf.ErrInvalidWiFi, "save failed")); got != codes.InvalidArgument {
|
|
t.Fatalf("code = %v", got)
|
|
}
|
|
}
|