MCPcopy Index your code
hub / github.com/dnote/dnote / TestCreateNote

Function TestCreateNote

pkg/server/app/notes_test.go:31–127  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29)
30
31func TestCreateNote(t *testing.T) {
32 serverTime := time.Date(2017, time.March, 14, 21, 15, 0, 0, time.UTC)
33
34 ts1 := time.Date(2018, time.November, 12, 10, 11, 0, 0, time.UTC).UnixNano()
35 ts2 := time.Date(2018, time.November, 15, 0, 1, 10, 0, time.UTC).UnixNano()
36
37 testCases := []struct {
38 userUSN int
39 addedOn *int64
40 editedOn *int64
41 expectedUSN int
42 expectedAddedOn int64
43 expectedEditedOn int64
44 }{
45 {
46 userUSN: 8,
47 addedOn: nil,
48 editedOn: nil,
49 expectedUSN: 9,
50 expectedAddedOn: serverTime.UnixNano(),
51 expectedEditedOn: 0,
52 },
53 {
54 userUSN: 102229,
55 addedOn: &ts1,
56 editedOn: nil,
57 expectedUSN: 102230,
58 expectedAddedOn: ts1,
59 expectedEditedOn: 0,
60 },
61 {
62 userUSN: 8099,
63 addedOn: &ts1,
64 editedOn: &ts2,
65 expectedUSN: 8100,
66 expectedAddedOn: ts1,
67 expectedEditedOn: ts2,
68 },
69 }
70
71 for idx, tc := range testCases {
72 func() {
73 // Create a new clock for each test case to avoid race conditions in parallel tests
74 mockClock := clock.NewMock()
75 mockClock.SetNow(serverTime)
76
77 db := testutils.InitMemoryDB(t)
78
79 user := testutils.SetupUserData(db, "user@test.com", "password123")
80 testutils.MustExec(t, db.Model(&user).Update("max_usn", tc.userUSN), fmt.Sprintf("preparing user max_usn for test case %d", idx))
81 fmt.Println(user)
82
83 anotherUser := testutils.SetupUserData(db, "another@test.com", "password123")
84 testutils.MustExec(t, db.Model(&anotherUser).Update("max_usn", 55), fmt.Sprintf("preparing user max_usn for test case %d", idx))
85
86 b1 := database.Book{UserID: user.ID, Label: "js", Deleted: false}
87 testutils.MustExec(t, db.Save(&b1), fmt.Sprintf("preparing b1 for test case %d", idx))
88

Callers

nothing calls this directly

Calls 10

SetNowMethod · 0.95
NewMockFunction · 0.92
InitMemoryDBFunction · 0.92
SetupUserDataFunction · 0.92
MustExecFunction · 0.92
EqualFunction · 0.92
NotEqualFunction · 0.92
NewTestFunction · 0.85
CreateNoteMethod · 0.80
UpdateMethod · 0.45

Tested by

no test coverage detected