mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-12-06 01:53:42 +01:00
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/phishingclub/phishingclub/model"
|
|
"github.com/phishingclub/phishingclub/vo"
|
|
)
|
|
|
|
// TestProgramCalendarUsesStartedAt checks a started program shows from its
|
|
// first enrollment, a scheduled one from its planned start
|
|
func TestProgramCalendarUsesStartedAt(t *testing.T) {
|
|
db := newProgramTestDB(t)
|
|
ctx := context.Background()
|
|
r := &Program{DB: db}
|
|
now := time.Now().UTC().Truncate(time.Second)
|
|
planned, started, future := now.Add(-48*time.Hour), now.Add(-47*time.Hour), now.Add(24*time.Hour)
|
|
running := statusProgram(t, db, "running", &planned, &started, nil, nil)
|
|
scheduled := statusProgram(t, db, "scheduled", &future, nil, nil, nil)
|
|
statusProgram(t, db, "draft", nil, nil, nil, nil)
|
|
got, err := r.GetCalendarEntries(ctx, nil, now.Add(-72*time.Hour), now.Add(72*time.Hour), &ProgramOption{QueryArgs: &vo.QueryArgs{}})
|
|
if err != nil {
|
|
t.Fatalf("calendar: %v", err)
|
|
}
|
|
if len(got.Rows) != 2 {
|
|
t.Fatalf("expected two entries, got %d", len(got.Rows))
|
|
}
|
|
for _, e := range got.Rows {
|
|
e.SetStatus(now)
|
|
switch e.ID {
|
|
case *running:
|
|
if !e.StartAt.Equal(started) || e.Status != model.ProgramStatusActive {
|
|
t.Fatalf("running entry: %+v", e)
|
|
}
|
|
case *scheduled:
|
|
if !e.StartAt.Equal(future) || e.Status != model.ProgramStatusScheduled {
|
|
t.Fatalf("scheduled entry: %+v", e)
|
|
}
|
|
}
|
|
}
|
|
}
|