2026-09-19 18:20:56 +03:00
|
|
|
package meta
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"glchat/internal/config"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestNewBuildsMetaPayload(t *testing.T) {
|
|
|
|
|
cfg := config.Config{
|
|
|
|
|
Domain: "gl.mhspx.su",
|
|
|
|
|
FilesDomain: "files.gl.mhspx.su",
|
|
|
|
|
InstanceName: "glchat",
|
|
|
|
|
Version: "v0.1.0",
|
|
|
|
|
Commit: "abc1234",
|
|
|
|
|
BuildDate: "2026-09-19T00:00:00Z",
|
|
|
|
|
MaxUploadSize: 26214400,
|
2026-09-19 19:58:32 +03:00
|
|
|
TLSEnabled: true,
|
2026-09-19 18:20:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp := New(cfg)
|
|
|
|
|
if resp.APIVersion != APIVersion {
|
|
|
|
|
t.Errorf("APIVersion = %q, want %q", resp.APIVersion, APIVersion)
|
|
|
|
|
}
|
|
|
|
|
if resp.BaseURL != "https://gl.mhspx.su" {
|
|
|
|
|
t.Errorf("BaseURL = %q", resp.BaseURL)
|
|
|
|
|
}
|
|
|
|
|
if resp.FilesURL != "https://files.gl.mhspx.su" {
|
|
|
|
|
t.Errorf("FilesURL = %q", resp.FilesURL)
|
|
|
|
|
}
|
|
|
|
|
if resp.GatewayURL != "wss://gl.mhspx.su/gateway" {
|
|
|
|
|
t.Errorf("GatewayURL = %q", resp.GatewayURL)
|
|
|
|
|
}
|
|
|
|
|
if resp.RTCPath != "/rtc" {
|
|
|
|
|
t.Errorf("RTCPath = %q", resp.RTCPath)
|
|
|
|
|
}
|
|
|
|
|
if resp.Version != "v0.1.0" || resp.Commit != "abc1234" {
|
|
|
|
|
t.Errorf("version metadata lost: %+v", resp)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestJSONUsesSnakeCaseKeys(t *testing.T) {
|
|
|
|
|
raw, err := json.Marshal(New(config.Config{Domain: "example.com", FilesDomain: "files.example.com"}))
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("marshal meta: %v", err)
|
|
|
|
|
}
|
|
|
|
|
var decoded map[string]any
|
|
|
|
|
if err := json.Unmarshal(raw, &decoded); err != nil {
|
|
|
|
|
t.Fatalf("unmarshal meta: %v", err)
|
|
|
|
|
}
|
|
|
|
|
for _, key := range []string{"api_version", "base_url", "files_url", "gateway_url", "max_upload_size", "features"} {
|
|
|
|
|
if _, ok := decoded[key]; !ok {
|
|
|
|
|
t.Errorf("meta payload is missing key %q: %s", key, raw)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
features, ok := decoded["features"].(map[string]any)
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatalf("features is not an object: %s", raw)
|
|
|
|
|
}
|
|
|
|
|
for _, key := range []string{"registration_enabled", "anti_bot_enabled", "voice_enabled", "web_push_enabled", "oauth_enabled", "passkeys_enabled"} {
|
|
|
|
|
if _, ok := features[key]; !ok {
|
|
|
|
|
t.Errorf("features is missing key %q", key)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|