Seven admin controllers in a "Studia BM" navigation group, guarded by jz.bm.access_courses, jz.bm.access_schedule and jz.bm.access_materials, with Polish and English labels. Date and time fields are checked by the models before a save and answered as 422 on the field.
36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
package controllers
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/cabana"
|
|
"git.golem15.com/jakub/sm-bm-plugin/models"
|
|
)
|
|
|
|
func TestTemporalHooksAnswerOnTheField(t *testing.T) {
|
|
var hooks temporalHooks
|
|
bad := &models.ClassSession{StartsAt: "2026-10-03 08:00", EndsAt: "wtorek"}
|
|
for name, fn := range map[string]func(context.Context, any) error{
|
|
"create": hooks.FormBeforeCreate,
|
|
"update": hooks.FormBeforeUpdate,
|
|
} {
|
|
err := fn(context.Background(), bad)
|
|
var ve *cabana.ValidationError
|
|
if !errors.As(err, &ve) {
|
|
t.Fatalf("%s: err = %v, want a cabana.ValidationError", name, err)
|
|
}
|
|
if _, ok := ve.Details["ends_at"]; !ok {
|
|
t.Errorf("%s: details %v name no ends_at", name, ve.Details)
|
|
}
|
|
}
|
|
good := &models.ClassSession{StartsAt: "2026-10-03 08:00", EndsAt: "2026-10-03 09:30"}
|
|
if err := hooks.FormBeforeCreate(context.Background(), good); err != nil {
|
|
t.Errorf("valid session: %v", err)
|
|
}
|
|
if err := hooks.FormBeforeUpdate(context.Background(), &models.Tag{}); err != nil {
|
|
t.Errorf("model without dates: %v", err)
|
|
}
|
|
}
|