forked from pocketbase/pocketbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_test.go
43 lines (35 loc) · 1.04 KB
/
user_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
package models_test
import (
"encoding/json"
"testing"
"github.com/pocketbase/pocketbase/models"
"github.com/pocketbase/pocketbase/tools/types"
)
func TestUserTableName(t *testing.T) {
m := models.User{}
if m.TableName() != "_users" {
t.Fatalf("Unexpected table name, got %q", m.TableName())
}
}
func TestUserAsMap(t *testing.T) {
date, _ := types.ParseDateTime("2022-01-01 01:12:23.456")
m := models.User{}
m.Id = "210a896c-1e32-4c94-ae06-90c25fcf6791"
m.Email = "[email protected]"
m.PasswordHash = "test"
m.LastResetSentAt = date
m.Updated = date
m.RefreshTokenKey()
result, err := m.AsMap()
if err != nil {
t.Fatal(err)
}
encoded, err := json.Marshal(result)
if err != nil {
t.Fatal(err)
}
expected := `{"created":"","email":"[email protected]","id":"210a896c-1e32-4c94-ae06-90c25fcf6791","lastResetSentAt":"2022-01-01 01:12:23.456","lastVerificationSentAt":"","profile":null,"updated":"2022-01-01 01:12:23.456","verified":false}`
if string(encoded) != expected {
t.Errorf("Expected %s, got %s", expected, string(encoded))
}
}