TestSendNotes tests that notes are put to correct 'buckets' by running a test server and recording the uuid from the incoming data.
(t *testing.T)
| 2285 | // TestSendNotes tests that notes are put to correct 'buckets' by running a test server and recording the |
| 2286 | // uuid from the incoming data. |
| 2287 | func TestSendNotes(t *testing.T) { |
| 2288 | // set up |
| 2289 | ctx := context.InitTestCtx(t) |
| 2290 | testutils.Login(t, &ctx) |
| 2291 | |
| 2292 | db := ctx.DB |
| 2293 | |
| 2294 | database.MustExec(t, "inserting last max usn", db, "INSERT INTO system (key, value) VALUES (?, ?)", consts.SystemLastMaxUSN, 0) |
| 2295 | |
| 2296 | b1UUID := "b1-uuid" |
| 2297 | database.MustExec(t, "inserting b1", db, "INSERT INTO books (uuid, label, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?)", b1UUID, "b1-label", 1, false, false) |
| 2298 | |
| 2299 | // should be ignored |
| 2300 | database.MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n1-uuid", b1UUID, 10, "n1-body", 1541108743, false, false) |
| 2301 | // should be created |
| 2302 | database.MustExec(t, "inserting n2", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n2-uuid", b1UUID, 0, "n2-body", 1541108743, false, true) |
| 2303 | // should be updated |
| 2304 | database.MustExec(t, "inserting n3", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n3-uuid", b1UUID, 11, "n3-body", 1541108743, false, true) |
| 2305 | // should be only expunged locally without syncing to server |
| 2306 | database.MustExec(t, "inserting n4", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n4-uuid", b1UUID, 0, "n4-body", 1541108743, true, true) |
| 2307 | // should be deleted |
| 2308 | database.MustExec(t, "inserting n5", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n5-uuid", b1UUID, 17, "n5-body", 1541108743, true, true) |
| 2309 | // should be created |
| 2310 | database.MustExec(t, "inserting n6", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n6-uuid", b1UUID, 0, "n6-body", 1541108743, false, true) |
| 2311 | // should be ignored |
| 2312 | database.MustExec(t, "inserting n7", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n7-uuid", b1UUID, 12, "n7-body", 1541108743, false, false) |
| 2313 | // should be updated |
| 2314 | database.MustExec(t, "inserting n8", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n8-uuid", b1UUID, 17, "n8-body", 1541108743, false, true) |
| 2315 | // should be deleted |
| 2316 | database.MustExec(t, "inserting n9", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n9-uuid", b1UUID, 17, "n9-body", 1541108743, true, true) |
| 2317 | // should be created |
| 2318 | database.MustExec(t, "inserting n10", db, "INSERT INTO notes (uuid, book_uuid, usn, body, added_on, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?)", "n10-uuid", b1UUID, 0, "n10-body", 1541108743, false, true) |
| 2319 | |
| 2320 | var createdBodys []string |
| 2321 | var updatedUUIDs []string |
| 2322 | var deletedUUIDs []string |
| 2323 | |
| 2324 | // fire up a test server |
| 2325 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 2326 | if r.URL.String() == "/v3/notes" && r.Method == "POST" { |
| 2327 | var payload client.CreateNotePayload |
| 2328 | |
| 2329 | err := json.NewDecoder(r.Body).Decode(&payload) |
| 2330 | if err != nil { |
| 2331 | t.Fatal(errors.Wrap(err, "decoding payload in the test server").Error()) |
| 2332 | return |
| 2333 | } |
| 2334 | |
| 2335 | createdBodys = append(createdBodys, payload.Body) |
| 2336 | |
| 2337 | resp := client.CreateNoteResp{ |
| 2338 | Result: client.RespNote{ |
| 2339 | UUID: fmt.Sprintf("server-%s-uuid", payload.Body), |
| 2340 | }, |
| 2341 | } |
| 2342 | |
| 2343 | w.Header().Set("Content-Type", "application/json") |
| 2344 | if err := json.NewEncoder(w).Encode(resp); err != nil { |
nothing calls this directly
no test coverage detected