-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry_test.go
69 lines (55 loc) · 1.57 KB
/
entry_test.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package db
import (
"context"
"testing"
"time"
"github.com/hhow09/simple_bank/util"
"github.com/stretchr/testify/require"
)
func createRandomEntry(t *testing.T, account Account) Entry {
arg := CreateEntryParams{
AccountID: account.ID,
Amount: util.RandomMoney(),
}
entry, err := testQueries.CreateEntry(context.Background(), arg)
require.NoError(t, err)
require.NotEmpty(t, entry)
require.Equal(t, arg.AccountID, entry.AccountID)
require.Equal(t, arg.Amount, entry.Amount)
require.NotZero(t, entry.ID)
require.NotZero(t, entry.CreatedAt)
return entry
}
func TestCreateEntry(t *testing.T) {
account := createRandomAccount(t)
createRandomEntry(t, account)
}
func TestGetEntry(t *testing.T) {
account := createRandomAccount(t)
entry1 := createRandomEntry(t, account)
entry2, err := testQueries.GetEntry(context.Background(), entry1.ID)
require.NoError(t, err)
require.NotEmpty(t, entry2)
require.Equal(t, entry1.ID, entry2.ID)
require.Equal(t, entry1.AccountID, entry2.AccountID)
require.Equal(t, entry1.Amount, entry2.Amount)
require.WithinDuration(t, entry1.CreatedAt, entry2.CreatedAt, time.Second)
}
func TestListEntries(t *testing.T) {
account := createRandomAccount(t)
for i := 0; i < 10; i++ {
createRandomEntry(t, account)
}
arg := ListEntriesParams{
AccountID: account.ID,
Limit: 5,
Offset: 5,
}
entries, err := testQueries.ListEntries(context.Background(), arg)
require.NoError(t, err)
require.Len(t, entries, 5)
for _, entry := range entries {
require.NotEmpty(t, entry)
require.Equal(t, arg.AccountID, entry.AccountID)
}
}