feat(cabana): code editor, colour and mail image fields, mail branding and the image library
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -440,6 +440,36 @@ func conformCases() []conformCase {
|
||||
{"POST /markdown/preview", 200, "cabana.Envelope-cabana_AdminMarkdownPreviewResult", func(t *testing.T, e *conformEnv) *httptest.ResponseRecorder {
|
||||
return e.send(t, http.MethodPost, "/markdown/preview", map[string]string{"markdown": "# Conform"}, true)
|
||||
}, into[cabana.Envelope[cabana.AdminMarkdownPreviewResult]](), nil},
|
||||
{"GET /mail/images", 200, "cabana.AdminMailImagesResponse", func(t *testing.T, e *conformEnv) *httptest.ResponseRecorder {
|
||||
return e.send(t, http.MethodGet, "/mail/images", nil, true)
|
||||
}, into[cabana.AdminMailImagesResponse](), nil},
|
||||
{"POST /mail/images", 201, "cabana.Envelope-cabana_AdminMailImage", func(t *testing.T, e *conformEnv) *httptest.ResponseRecorder {
|
||||
var buf bytes.Buffer
|
||||
mw := multipart.NewWriter(&buf)
|
||||
part, err := mw.CreateFormFile("file", "mail-badge.png")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := part.Write(conformPNG(t)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := mw.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rec := e.sendWith(t, http.MethodPost, "/mail/images", buf.Bytes(), mw.FormDataContentType(), map[string]string{"X-Requested-With": "XMLHttpRequest"})
|
||||
var body cabana.Envelope[cabana.AdminMailImage]
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
||||
t.Fatalf("mail image upload: %v body=%s", err, rec.Body.String())
|
||||
}
|
||||
e.mailImageID = body.Data.ID
|
||||
return rec
|
||||
}, into[cabana.Envelope[cabana.AdminMailImage]](), nil},
|
||||
{"GET /mail/images/{id}", 200, "cabana.Envelope-cabana_AdminMailImage", func(t *testing.T, e *conformEnv) *httptest.ResponseRecorder {
|
||||
if e.mailImageID == 0 {
|
||||
t.Fatal("mail image id unset; POST /mail/images must run first")
|
||||
}
|
||||
return e.send(t, http.MethodGet, fmt.Sprintf("/mail/images/%d", e.mailImageID), nil, true)
|
||||
}, into[cabana.Envelope[cabana.AdminMailImage]](), nil},
|
||||
{"GET /{vendor}/{plugin}/{controller}/schema/list", 200, "cabana.Envelope-cabana_ListSchema", func(t *testing.T, e *conformEnv) *httptest.ResponseRecorder {
|
||||
rec := e.send(t, http.MethodGet, "/acme/conform/gadgets/schema/list", nil, true)
|
||||
var body cabana.Envelope[cabana.ListSchema]
|
||||
@@ -833,22 +863,23 @@ func conformSpec(t *testing.T) conformSpecDoc {
|
||||
}
|
||||
|
||||
type conformEnv struct {
|
||||
h http.Handler
|
||||
db *gorm.DB
|
||||
bucket *blob.Bucket
|
||||
login string
|
||||
token string
|
||||
stamp string
|
||||
sessionKey string
|
||||
photoID uint
|
||||
manualID uint
|
||||
groupID uint
|
||||
memberID uint
|
||||
gadgetID uint
|
||||
partID uint
|
||||
partFileID uint
|
||||
childKey string
|
||||
tokenID uint
|
||||
h http.Handler
|
||||
db *gorm.DB
|
||||
bucket *blob.Bucket
|
||||
login string
|
||||
token string
|
||||
stamp string
|
||||
sessionKey string
|
||||
photoID uint
|
||||
manualID uint
|
||||
groupID uint
|
||||
memberID uint
|
||||
gadgetID uint
|
||||
partID uint
|
||||
partFileID uint
|
||||
childKey string
|
||||
tokenID uint
|
||||
mailImageID uint
|
||||
}
|
||||
|
||||
// sendWith sends a raw body with extra headers through the assembled router.
|
||||
@@ -1039,7 +1070,9 @@ func newConformEnv(t *testing.T) *conformEnv {
|
||||
login := "conform-" + stamp
|
||||
insertAdmin(t, gdb, login, login+"@example.test", adminTestPassword, true, false)
|
||||
// The Plugins screen needs backend.view_plugins, which no role holds.
|
||||
if err := gdb.Exec(`UPDATE backend_users SET permissions = ? WHERE login = ?`, `{"backend.view_plugins":1}`, login).Error; err != nil {
|
||||
// Mail image routes need either mail permission (conform is not a superuser).
|
||||
if err := gdb.Exec(`UPDATE backend_users SET permissions = ? WHERE login = ?`,
|
||||
`{"backend.view_plugins":1,"system.manage_mail_templates":1,"system.manage_mail_layouts":1}`, login).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -1052,7 +1085,12 @@ func newConformEnv(t *testing.T) *conformEnv {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// plugins.registry_url "" keeps GET /plugins from calling a registry.
|
||||
for key, value := range map[string]any{"http.body_limits.default_bytes": 1048576, "http.body_limits.upload_bytes": 1048576, "plugins.registry_url": ""} {
|
||||
for key, value := range map[string]any{
|
||||
"http.body_limits.default_bytes": 1048576,
|
||||
"http.body_limits.upload_bytes": 1048576,
|
||||
"plugins.registry_url": "",
|
||||
"app.url": "https://conform.example.test",
|
||||
} {
|
||||
if err := cfg.Set(key, value); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -1061,6 +1099,9 @@ func newConformEnv(t *testing.T) *conformEnv {
|
||||
if err := lagoon.Publish(app, adminSQL, gdb); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := gdb.AutoMigrate(&cabana.MailImageLibrary{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bucket := memblob.OpenBucket(nil)
|
||||
t.Cleanup(func() { _ = bucket.Close() })
|
||||
if err := attach.Publish(app, bucket); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user