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

Function TestUpdateNote_SameContent

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

Source from the content-addressed store, hash-verified

231}
232
233func TestUpdateNote_SameContent(t *testing.T) {
234 db := testutils.InitMemoryDB(t)
235
236 user := testutils.SetupUserData(db, "user@test.com", "password123")
237 b1 := database.Book{UserID: user.ID, Label: "testBook"}
238 testutils.MustExec(t, db.Save(&b1), "preparing book")
239
240 note := database.Note{UserID: user.ID, Deleted: false, Body: "test content", BookUUID: b1.UUID}
241 testutils.MustExec(t, db.Save(&note), "preparing note")
242
243 a := NewTest()
244 a.DB = db
245 a.Clock = clock.NewMock()
246
247 // Update note with same content
248 sameContent := "test content"
249 tx := db.Begin()
250 _, err := a.UpdateNote(tx, user, note, &UpdateNoteParams{
251 Content: &sameContent,
252 })
253 if err != nil {
254 tx.Rollback()
255 t.Fatal(errors.Wrap(err, "updating note with same content"))
256 }
257 tx.Commit()
258
259 // Assert FTS still has the same content
260 var ftsBody string
261 testutils.MustExec(t, db.Raw("SELECT body FROM notes_fts WHERE rowid = ?", note.ID).Scan(&ftsBody), "querying notes_fts after update")
262 assert.Equal(t, ftsBody, "test content", "FTS body should still be 'test content'")
263
264 // Assert it's still searchable
265 var searchCount int64
266 testutils.MustExec(t, db.Raw("SELECT COUNT(*) FROM notes_fts WHERE notes_fts MATCH ?", "test").Scan(&searchCount), "searching notes_fts")
267 assert.Equal(t, searchCount, int64(1), "Note should still be searchable")
268}
269
270func TestDeleteNote(t *testing.T) {
271 testCases := []struct {

Callers

nothing calls this directly

Calls 10

InitMemoryDBFunction · 0.92
SetupUserDataFunction · 0.92
MustExecFunction · 0.92
NewMockFunction · 0.92
EqualFunction · 0.92
NewTestFunction · 0.85
UpdateNoteMethod · 0.80
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected