MCPcopy
hub / github.com/dnote/dnote / TestSendNotes_addedOn

Function TestSendNotes_addedOn

pkg/cli/cmd/sync/sync_test.go:2439–2492  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2437}
2438
2439func TestSendNotes_addedOn(t *testing.T) {
2440 // set up
2441 ctx := context.InitTestCtx(t)
2442 testutils.Login(t, &ctx)
2443
2444 db := ctx.DB
2445
2446 database.MustExec(t, "inserting last max usn", db, "INSERT INTO system (key, value) VALUES (?, ?)", consts.SystemLastMaxUSN, 0)
2447
2448 // should be created
2449 b1UUID := "b1-uuid"
2450 database.MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n1-uuid", b1UUID, 0, "n1-body", 1541108743, false, true)
2451
2452 // fire up a test server
2453 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2454 if r.URL.String() == "/v3/notes" && r.Method == "POST" {
2455 resp := client.CreateNoteResp{
2456 Result: client.RespNote{
2457 UUID: testutils.MustGenerateUUID(t),
2458 },
2459 }
2460
2461 w.Header().Set("Content-Type", "application/json")
2462 if err := json.NewEncoder(w).Encode(resp); err != nil {
2463 http.Error(w, err.Error(), http.StatusInternalServerError)
2464 return
2465 }
2466 return
2467 }
2468
2469 t.Fatalf("unrecognized endpoint reached Method: %s Path: %s", r.Method, r.URL.Path)
2470 }))
2471 defer ts.Close()
2472
2473 ctx.APIEndpoint = ts.URL
2474
2475 // execute
2476 tx, err := db.Begin()
2477 if err != nil {
2478 t.Fatal(errors.Wrap(err, "beginning a transaction").Error())
2479 }
2480
2481 if _, err := sendNotes(ctx, tx); err != nil {
2482 tx.Rollback()
2483 t.Fatal(errors.Wrap(err, "executing").Error())
2484 }
2485
2486 tx.Commit()
2487
2488 // test
2489 var n1 database.Note
2490 database.MustScan(t, "getting n1", db.QueryRow("SELECT uuid, added_on, dirty FROM notes WHERE body = ?", "n1-body"), &n1.UUID, &n1.AddedOn, &n1.Dirty)
2491 assert.Equal(t, n1.AddedOn, int64(1541108743), "n1 AddedOn mismatch")
2492}
2493
2494func TestSendNotes_isBehind(t *testing.T) {
2495 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 13

InitTestCtxFunction · 0.92
LoginFunction · 0.92
MustExecFunction · 0.92
MustGenerateUUIDFunction · 0.92
MustScanFunction · 0.92
EqualFunction · 0.92
sendNotesFunction · 0.85
CloseMethod · 0.65
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65
QueryRowMethod · 0.65

Tested by

no test coverage detected