2026-08-12 09:57:56 +12:00
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
2026-08-22 18:40:50 +12:00
|
|
|
"encoding/json"
|
2026-08-12 09:57:56 +12:00
|
|
|
"net/http"
|
|
|
|
|
"net/http/httptest"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/ponzischeme89/memby/server/internal/config"
|
2026-08-22 18:40:50 +12:00
|
|
|
"github.com/ponzischeme89/memby/server/internal/store"
|
2026-08-12 09:57:56 +12:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestRemoteConfigSupportsETagRevalidationWithoutAuthentication(t *testing.T) {
|
|
|
|
|
server := &Server{cfg: config.Config{RemoteConfig: config.DefaultRemoteConfig()}}
|
|
|
|
|
first := httptest.NewRecorder()
|
|
|
|
|
server.handleRemoteConfig(first, httptest.NewRequest(http.MethodGet, "/v1/config", nil))
|
|
|
|
|
if first.Code != http.StatusOK {
|
|
|
|
|
t.Fatalf("status = %d", first.Code)
|
|
|
|
|
}
|
|
|
|
|
etag := first.Header().Get("ETag")
|
|
|
|
|
if etag == "" {
|
|
|
|
|
t.Fatal("missing ETag")
|
|
|
|
|
}
|
|
|
|
|
if got := first.Header().Get("X-Memby-Config-Version"); got != "1" {
|
|
|
|
|
t.Fatalf("version header = %q", got)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request := httptest.NewRequest(http.MethodGet, "/v1/config", nil)
|
|
|
|
|
request.Header.Set("If-None-Match", etag)
|
|
|
|
|
second := httptest.NewRecorder()
|
|
|
|
|
server.handleRemoteConfig(second, request)
|
|
|
|
|
if second.Code != http.StatusNotModified {
|
|
|
|
|
t.Fatalf("revalidation status = %d", second.Code)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-08-22 18:40:50 +12:00
|
|
|
|
|
|
|
|
func TestGlobalFontFamilyConfigurationIsDelivered(t *testing.T) {
|
|
|
|
|
document := config.DefaultRemoteConfig()
|
|
|
|
|
policy := store.DefaultFeaturePolicy()
|
|
|
|
|
policy.Values["presentation.fontFamily"] = json.RawMessage(`"inter"`)
|
|
|
|
|
|
|
|
|
|
applyGlobalConfiguration(&document, policy)
|
|
|
|
|
|
|
|
|
|
if document.Presentation.FontFamily != "inter" {
|
|
|
|
|
t.Fatalf("font family = %q, want inter", document.Presentation.FontFamily)
|
|
|
|
|
}
|
|
|
|
|
}
|