aboutsummaryrefslogtreecommitdiffstats
path: root/internal/web/web_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/web/web_test.go')
-rw-r--r--internal/web/web_test.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/internal/web/web_test.go b/internal/web/web_test.go
index e2bd335..9520953 100644
--- a/internal/web/web_test.go
+++ b/internal/web/web_test.go
@@ -1,6 +1,7 @@
package web
import (
+ "encoding/json"
"io/fs"
"net/http"
"net/http/httptest"
@@ -444,6 +445,24 @@ func TestFileMarkdown(t *testing.T) {
}
}
+func TestPreviewRendersMarkdown(t *testing.T) {
+ s := NewServer(&config.Config{BaseDomain: "example.com", JWTSecret: []byte("x")}, nil)
+ req := httptest.NewRequest("POST", "/b/www/preview", strings.NewReader("body=**x**+<script>1</script>"))
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ rec := httptest.NewRecorder()
+ s.handlePreview(rec, req)
+ if ct := rec.Header().Get("Content-Type"); ct != "application/json" {
+ t.Errorf("content type %q", ct)
+ }
+ var out map[string]string
+ if err := json.Unmarshal(rec.Body.Bytes(), &out); err != nil {
+ t.Fatal(err)
+ }
+ if h := out["html"]; !strings.Contains(h, "<strong>x</strong>") || strings.Contains(h, "<script>") {
+ t.Errorf("unexpected preview %q", h)
+ }
+}
+
func TestNormalizeSection(t *testing.T) {
sec := &store.Section{Placement: "footer", Style: "<script>"}
normalizeSection(sec)