Datepickers on native time.Time / lagoon.Date fields, file uploads on materials, readings and class sessions managed from the course form (course_id made nullable).
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
package controllers
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/cabana"
|
|
"git.golem15.com/jakub/sm-bm-plugin/models"
|
|
)
|
|
|
|
func TestTemporalHooksAnswerOnTheField(t *testing.T) {
|
|
var hooks temporalHooks
|
|
at := func(h, m int) time.Time { return time.Date(2026, 10, 3, h, m, 0, 0, models.Location) }
|
|
bad := &models.ClassSession{StartsAt: at(8, 0), EndsAt: at(7, 0)}
|
|
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: at(8, 0), EndsAt: at(9, 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)
|
|
}
|
|
}
|