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

Function TestUpdateBook

pkg/server/app/books_test.go:165–245  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

163}
164
165func TestUpdateBook(t *testing.T) {
166 js := "js"
167
168 testCases := []struct {
169 usn int
170 userUSN int
171 label string
172 payloadLabel *string
173 expectedUSN int
174 expectedUserUSN int
175 expectedLabel string
176 }{
177 {
178 userUSN: 1,
179 usn: 1,
180 label: "js",
181 payloadLabel: nil,
182 expectedUSN: 2,
183 expectedUserUSN: 2,
184 expectedLabel: "js",
185 },
186 {
187 userUSN: 8,
188 usn: 3,
189 label: "css",
190 payloadLabel: &js,
191 expectedUSN: 9,
192 expectedUserUSN: 9,
193 expectedLabel: "js",
194 },
195 }
196
197 for idx, tc := range testCases {
198 func() {
199 db := testutils.InitMemoryDB(t)
200
201 user := testutils.SetupUserData(db, "user@test.com", "password123")
202 testutils.MustExec(t, db.Model(&user).Update("max_usn", tc.userUSN), fmt.Sprintf("preparing user max_usn for test case %d", idx))
203
204 anotherUser := testutils.SetupUserData(db, "another@test.com", "password123")
205 testutils.MustExec(t, db.Model(&anotherUser).Update("max_usn", 55), fmt.Sprintf("preparing user max_usn for test case %d", idx))
206
207 b := database.Book{UserID: user.ID, Deleted: false, Label: tc.expectedLabel}
208 testutils.MustExec(t, db.Save(&b), fmt.Sprintf("preparing book for test case %d", idx))
209
210 c := clock.NewMock()
211 a := NewTest()
212 a.DB = db
213 a.Clock = c
214
215 tx := db.Begin()
216 book, err := a.UpdateBook(tx, user, b, tc.payloadLabel)
217 if err != nil {
218 tx.Rollback()
219 t.Fatal(errors.Wrap(err, "updating book"))
220 }
221
222 tx.Commit()

Callers

nothing calls this directly

Calls 12

NowMethod · 0.95
InitMemoryDBFunction · 0.92
SetupUserDataFunction · 0.92
MustExecFunction · 0.92
NewMockFunction · 0.92
EqualFunction · 0.92
NewTestFunction · 0.85
UpdateBookMethod · 0.80
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65
UpdateMethod · 0.45

Tested by

no test coverage detected