Newer
Older
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
package api
import (
"net/http"
"testing"
)
func TestTopupAddListMine(t *testing.T) {
tapi := newTestAPI(t)
defer tapi.close()
tapi.addTestMember()
tapi.addTestProducts()
topup := map[string]interface{}{
"member": testMember.Num,
"comment": "my topup",
"ammount": 20,
}
resp := tapi.do("POST", "/topup", topup, nil)
if resp.StatusCode != http.StatusCreated {
t.Fatal("Can't create topup:", resp.Status)
}
var transactions []Transaction
resp = tapi.do("GET", "/transaction/mine", nil, &transactions)
if resp.StatusCode != http.StatusOK {
t.Fatal("Can't get transactions:", resp.Status)
}
if len(transactions) != 1 {
t.Fatal("Wrong number of transactions", len(transactions), transactions)
}
if transactions[0].Total != 20 {
t.Error("Wrong total:", transactions[0].Total)
}
if transactions[0].Topup.MemberNum != testMember.Num {
t.Error("Wrong topup member:", transactions[0].Topup.MemberNum)
}
if transactions[0].Topup.Comment != "my topup" {
t.Error("Wrong topup comment:", transactions[0].Topup.Comment)
}
var member Member
resp = tapi.do("GET", "/member/10", nil, &member)
if resp.StatusCode != http.StatusOK {
t.Error("Can't find the member:", resp.Status)
}
if member.Balance != testMember.Balance+20 {
t.Error("Wrong product balance:", member.Balance)
}
}