-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_test.go
More file actions
61 lines (49 loc) · 1.46 KB
/
basic_test.go
File metadata and controls
61 lines (49 loc) · 1.46 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
56
57
58
59
60
61
package basic_test
import (
"testing"
"github.com/mhiro2/seedling"
"github.com/mhiro2/seedling/examples/basic"
)
func setup(t *testing.T) *seedling.Registry {
t.Helper()
reg := seedling.NewRegistry()
basic.RegisterBlueprints(reg)
return reg
}
func TestInsertOne_Company(t *testing.T) {
reg := setup(t)
company := seedling.NewSession[basic.Company](reg).InsertOne(t, nil)
if company.Root().ID == 0 {
t.Fatal("expected company ID to be set")
}
if company.Root().Name != "test-company" {
t.Fatalf("expected Name = %q, got %q", "test-company", company.Root().Name)
}
}
func TestInsertOne_User(t *testing.T) {
reg := setup(t)
// InsertOne[User] automatically creates a parent Company.
user := seedling.NewSession[basic.User](reg).InsertOne(t, nil)
if user.Root().ID == 0 {
t.Fatal("expected user ID to be set")
}
if user.Root().CompanyID == 0 {
t.Fatal("expected CompanyID to be auto-populated")
}
if user.Root().Name != "test-user" {
t.Fatalf("expected Name = %q, got %q", "test-user", user.Root().Name)
}
}
func TestInsertOne_UserWithSet(t *testing.T) {
reg := setup(t)
user := seedling.NewSession[basic.User](reg).InsertOne(t, nil,
seedling.Set("Name", "alice"),
seedling.Set("Email", "alice@example.com"),
)
if user.Root().Name != "alice" {
t.Fatalf("expected Name = %q, got %q", "alice", user.Root().Name)
}
if user.Root().Email != "alice@example.com" {
t.Fatalf("expected Email = %q, got %q", "alice@example.com", user.Root().Email)
}
}