(t *testing.T)
| 150 | } |
| 151 | |
| 152 | func TestUpdateNote(t *testing.T) { |
| 153 | testCases := []struct { |
| 154 | userUSN int |
| 155 | }{ |
| 156 | { |
| 157 | userUSN: 8, |
| 158 | }, |
| 159 | { |
| 160 | userUSN: 102229, |
| 161 | }, |
| 162 | { |
| 163 | userUSN: 8099, |
| 164 | }, |
| 165 | } |
| 166 | |
| 167 | for idx, tc := range testCases { |
| 168 | t.Run(fmt.Sprintf("test case %d", idx), func(t *testing.T) { |
| 169 | db := testutils.InitMemoryDB(t) |
| 170 | |
| 171 | user := testutils.SetupUserData(db, "user@test.com", "password123") |
| 172 | testutils.MustExec(t, db.Model(&user).Update("max_usn", tc.userUSN), "preparing user max_usn for test case") |
| 173 | |
| 174 | anotherUser := testutils.SetupUserData(db, "another@test.com", "password123") |
| 175 | testutils.MustExec(t, db.Model(&anotherUser).Update("max_usn", 55), "preparing user max_usn for test case") |
| 176 | |
| 177 | b1 := database.Book{UserID: user.ID, Label: "js", Deleted: false} |
| 178 | testutils.MustExec(t, db.Save(&b1), "preparing b1 for test case") |
| 179 | |
| 180 | note := database.Note{UserID: user.ID, Deleted: false, Body: "test content", BookUUID: b1.UUID} |
| 181 | testutils.MustExec(t, db.Save(¬e), "preparing note for test case") |
| 182 | |
| 183 | // Assert FTS table has original content |
| 184 | var ftsBodyBefore string |
| 185 | testutils.MustExec(t, db.Raw("SELECT body FROM notes_fts WHERE rowid = ?", note.ID).Scan(&ftsBodyBefore), "querying notes_fts before update") |
| 186 | assert.Equal(t, ftsBodyBefore, "test content", "FTS body mismatch before update") |
| 187 | |
| 188 | c := clock.NewMock() |
| 189 | content := "updated test content" |
| 190 | |
| 191 | a := NewTest() |
| 192 | a.DB = db |
| 193 | a.Clock = c |
| 194 | |
| 195 | tx := db.Begin() |
| 196 | if _, err := a.UpdateNote(tx, user, note, &UpdateNoteParams{ |
| 197 | Content: &content, |
| 198 | }); err != nil { |
| 199 | tx.Rollback() |
| 200 | t.Fatal(errors.Wrap(err, "updating note")) |
| 201 | } |
| 202 | tx.Commit() |
| 203 | |
| 204 | var bookCount, noteCount int64 |
| 205 | var noteRecord database.Note |
| 206 | var userRecord database.User |
| 207 | |
| 208 | testutils.MustExec(t, db.Model(&database.Book{}).Count(&bookCount), "counting book for test case") |
| 209 | testutils.MustExec(t, db.Model(&database.Note{}).Count(¬eCount), "counting notes for test case") |
nothing calls this directly
no test coverage detected