1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package handlers
import (
"context"
"testing"
"time"
)
func TestBuildTimeline_PopulatesChainBadgeForUnlockedTask(t *testing.T) {
s, cleanup := setupTestDB(t)
defer cleanup()
chain, err := s.CreateChain("Ham Radio Track", []string{"Study Technician", "Pass exam", "Study General"})
if err != nil {
t.Fatal(err)
}
tasks, err := s.GetChainTasks(chain.ID)
if err != nil {
t.Fatal(err)
}
now := time.Now()
items, err := BuildTimeline(context.Background(), s, now.Add(-time.Hour), now.Add(24*time.Hour))
if err != nil {
t.Fatalf("BuildTimeline: %v", err)
}
var found bool
for _, item := range items {
if item.ID == tasks[0].ID {
found = true
if item.ChainPosition != 1 || item.ChainTotal != 3 {
t.Errorf("ChainPosition/ChainTotal = %d/%d, want 1/3", item.ChainPosition, item.ChainTotal)
}
}
if item.ID == tasks[1].ID || item.ID == tasks[2].ID {
t.Errorf("locked chain task %q should not appear in the timeline", item.ID)
}
}
if !found {
t.Fatal("expected the unlocked chain task (position 0) to appear in the timeline")
}
}
|