-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack_test.go
37 lines (34 loc) · 1.28 KB
/
pack_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
package main
import (
"testing"
"time"
"github.com/asvins/common_db/postgres"
. "github.com/smartystreets/goconvey/convey"
)
func TestGetPacks(t *testing.T) {
p1 := &Pack{Owner: "[email protected]", Supervisor: "[email protected]", From: time.Now().AddDate(0, 1, 0), To: time.Now().AddDate(0, 0, -15), TrackingCode: "A29CDE", Status: PackStatusDelivered, PackType: "medication", PackHash: "ccf3b89a"}
p2 := &Pack{Owner: "[email protected]", Supervisor: "[email protected]", From: time.Now(), To: time.Now().AddDate(0, 0, 14), TrackingCode: "A29CDE", Status: PackStatusShipped, PackType: "medication", PackHash: "ccf3b89a"}
db := postgres.GetDatabase(DatabaseConfig)
p1.Create(db)
p2.Create(db)
Convey("When getting packs", t, func() {
Convey("We can get them by owner", func() {
var p []Pack
GetPacksByOwner("[email protected]", &p, db)
So(len(p), ShouldEqual, 2)
})
Convey("We can get them by status", func() {
var p []Pack
GetPacksByStatus(PackStatusDelivered, &p, db)
So(len(p), ShouldEqual, 1)
GetPacksByStatusString("shipped", &p, db)
So(len(p), ShouldEqual, 1)
})
Convey("We can get active packs", func() {
var p []Pack
GetActivePacks("[email protected]", &p, db)
So(len(p), ShouldEqual, 1)
})
})
db.Exec("TRUNCATE TABLE packs")
}