-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient_test.go
More file actions
55 lines (50 loc) · 1.29 KB
/
client_test.go
File metadata and controls
55 lines (50 loc) · 1.29 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
package opal
import (
"strings"
"testing"
)
func TestEverything(t *testing.T) {
if !testing.Verbose() {
t.Skip("-v not passed; not running TestEverything")
}
c, err := NewClient(FileAuthStore(DefaultAuthFile))
if err != nil {
t.Fatalf("NewClient: %v", err)
}
defer func() {
if err := c.WriteConfig(); err != nil {
t.Errorf("c.WriteConfig: %v", err)
}
}()
o, err := c.Overview()
if err != nil {
t.Fatalf("c.Overview: %v", err)
}
for _, card := range o.Cards {
t.Logf("Card %s: $%.2f", card.Name, float64(card.Balance)/100)
}
if len(o.Cards) == 0 {
return
}
const lastPage = 0 // switch to 1 to see more data
for page := 0; page <= lastPage; page++ {
req := ActivityRequest{CardIndex: 0, Offset: page}
a, err := c.Activity(req)
if err != nil {
t.Fatalf("c.Activity(%+v): %v", req, err)
}
if n1, n2 := a.CardName, o.Cards[0].Name; n1 != n2 {
t.Errorf("Card name from c.Activity = %q, different from c.Overview = %q", n1, n2)
}
var prevWeek int
for i, tr := range a.Transactions {
_, week := tr.When.ISOWeek()
if i > 0 && week != prevWeek {
t.Logf(strings.Repeat("-", 50))
}
prevWeek = week
ts := tr.When.Format("2006-01-02 15:04")
t.Logf("%v\tJ%02d (%5s) %s [$%.2f]", ts, tr.JourneyNumber, tr.Mode, tr.Details, float64(-tr.Amount)/100)
}
}
}