forked from pocketbase/pocketbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_model_test.go
70 lines (51 loc) · 1.47 KB
/
db_model_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
70
package core_test
import (
"testing"
"github.com/pocketbase/pocketbase/core"
)
func TestBaseModel(t *testing.T) {
id := "test_id"
m := core.BaseModel{Id: id}
if m.PK() != id {
t.Fatalf("[before PostScan] Expected PK %q, got %q", "", m.PK())
}
if m.LastSavedPK() != "" {
t.Fatalf("[before PostScan] Expected LastSavedPK %q, got %q", "", m.LastSavedPK())
}
if !m.IsNew() {
t.Fatalf("[before PostScan] Expected IsNew %v, got %v", true, m.IsNew())
}
if err := m.PostScan(); err != nil {
t.Fatal(err)
}
if m.PK() != id {
t.Fatalf("[after PostScan] Expected PK %q, got %q", "", m.PK())
}
if m.LastSavedPK() != id {
t.Fatalf("[after PostScan] Expected LastSavedPK %q, got %q", id, m.LastSavedPK())
}
if m.IsNew() {
t.Fatalf("[after PostScan] Expected IsNew %v, got %v", false, m.IsNew())
}
m.MarkAsNew()
if m.PK() != id {
t.Fatalf("[after MarkAsNew] Expected PK %q, got %q", id, m.PK())
}
if m.LastSavedPK() != "" {
t.Fatalf("[after MarkAsNew] Expected LastSavedPK %q, got %q", "", m.LastSavedPK())
}
if !m.IsNew() {
t.Fatalf("[after MarkAsNew] Expected IsNew %v, got %v", true, m.IsNew())
}
// mark as not new without id
m.MarkAsNotNew()
if m.PK() != id {
t.Fatalf("[after MarkAsNotNew] Expected PK %q, got %q", id, m.PK())
}
if m.LastSavedPK() != id {
t.Fatalf("[after MarkAsNotNew] Expected LastSavedPK %q, got %q", id, m.LastSavedPK())
}
if m.IsNew() {
t.Fatalf("[after MarkAsNotNew] Expected IsNew %v, got %v", false, m.IsNew())
}
}