(t *testing.T)
| 51 | } |
| 52 | |
| 53 | func TestSync_oneway(t *testing.T) { |
| 54 | t.Run("cli to api only", func(t *testing.T) { |
| 55 | setup := func(t *testing.T, env testEnv, user database.User) { |
| 56 | apitest.MustExec(t, env.ServerDB.Model(&user).Update("max_usn", 0), "updating user max_usn") |
| 57 | |
| 58 | clitest.RunDnoteCmd(t, env.CmdOpts, cliBinaryName, "add", "js", "-c", "js1") |
| 59 | clitest.RunDnoteCmd(t, env.CmdOpts, cliBinaryName, "add", "css", "-c", "css1") |
| 60 | clitest.RunDnoteCmd(t, env.CmdOpts, cliBinaryName, "add", "js", "-c", "js2") |
| 61 | } |
| 62 | |
| 63 | assert := func(t *testing.T, env testEnv, user database.User) { |
| 64 | cliDB := env.DB |
| 65 | |
| 66 | // test client |
| 67 | checkState(t, env.DB, user, env.ServerDB, systemState{ |
| 68 | clientNoteCount: 3, |
| 69 | clientBookCount: 2, |
| 70 | clientLastMaxUSN: 5, |
| 71 | clientLastSyncAt: serverTime.Unix(), |
| 72 | serverNoteCount: 3, |
| 73 | serverBookCount: 2, |
| 74 | serverUserMaxUSN: 5, |
| 75 | }) |
| 76 | |
| 77 | var cliBookJS, cliBookCSS cliDatabase.Book |
| 78 | var cliNote1JS, cliNote2JS, cliNote1CSS cliDatabase.Note |
| 79 | cliDatabase.MustScan(t, "finding cli book js", cliDB.QueryRow("SELECT uuid, label, usn FROM books WHERE label = ?", "js"), &cliBookJS.UUID, &cliBookJS.Label, &cliBookJS.USN) |
| 80 | cliDatabase.MustScan(t, "finding cli book css", cliDB.QueryRow("SELECT uuid, label, usn FROM books WHERE label = ?", "css"), &cliBookCSS.UUID, &cliBookCSS.Label, &cliBookCSS.USN) |
| 81 | cliDatabase.MustScan(t, "finding cliNote1JS", cliDB.QueryRow("SELECT uuid, body, usn FROM notes WHERE body = ?", "js1"), &cliNote1JS.UUID, &cliNote1JS.Body, &cliNote1JS.USN) |
| 82 | cliDatabase.MustScan(t, "finding cliNote2JS", cliDB.QueryRow("SELECT uuid, body, usn FROM notes WHERE body = ?", "js2"), &cliNote2JS.UUID, &cliNote2JS.Body, &cliNote2JS.USN) |
| 83 | cliDatabase.MustScan(t, "finding cliNote1CSS", cliDB.QueryRow("SELECT uuid, body, usn FROM notes WHERE body = ?", "css1"), &cliNote1CSS.UUID, &cliNote1CSS.Body, &cliNote1CSS.USN) |
| 84 | |
| 85 | // assert on usn |
| 86 | assert.NotEqual(t, cliNote1JS.USN, 0, "cliNote1JS USN mismatch") |
| 87 | assert.NotEqual(t, cliNote2JS.USN, 0, "cliNote2JS USN mismatch") |
| 88 | assert.NotEqual(t, cliNote1CSS.USN, 0, "cliNote1CSS USN mismatch") |
| 89 | assert.NotEqual(t, cliBookJS.USN, 0, "cliBookJS USN mismatch") |
| 90 | assert.NotEqual(t, cliBookCSS.USN, 0, "cliBookCSS USN mismatch") |
| 91 | // assert on bodys and labels |
| 92 | assert.Equal(t, cliNote1JS.Body, "js1", "cliNote1JS Body mismatch") |
| 93 | assert.Equal(t, cliNote2JS.Body, "js2", "cliNote2JS Body mismatch") |
| 94 | assert.Equal(t, cliNote1CSS.Body, "css1", "cliNote1CSS Body mismatch") |
| 95 | assert.Equal(t, cliBookJS.Label, "js", "cliBookJS Label mismatch") |
| 96 | assert.Equal(t, cliBookCSS.Label, "css", "cliBookCSS Label mismatch") |
| 97 | // assert on deleted |
| 98 | assert.Equal(t, cliNote1JS.Deleted, false, "cliNote1JS Deleted mismatch") |
| 99 | assert.Equal(t, cliNote2JS.Deleted, false, "cliNote2JS Deleted mismatch") |
| 100 | assert.Equal(t, cliNote1CSS.Deleted, false, "cliNote1CSS Deleted mismatch") |
| 101 | assert.Equal(t, cliBookJS.Deleted, false, "cliBookJS Deleted mismatch") |
| 102 | assert.Equal(t, cliBookCSS.Deleted, false, "cliBookCSS Deleted mismatch") |
| 103 | |
| 104 | // test server |
| 105 | var apiBookJS, apiBookCSS database.Book |
| 106 | var apiNote1JS, apiNote2JS, apiNote1CSS database.Note |
| 107 | apitest.MustExec(t, env.ServerDB.Model(&database.Note{}).Where("uuid = ?", cliNote1JS.UUID).First(&apiNote1JS), "getting js1 note") |
| 108 | apitest.MustExec(t, env.ServerDB.Model(&database.Note{}).Where("uuid = ?", cliNote2JS.UUID).First(&apiNote2JS), "getting js2 note") |
| 109 | apitest.MustExec(t, env.ServerDB.Model(&database.Note{}).Where("uuid = ?", cliNote1CSS.UUID).First(&apiNote1CSS), "getting css1 note") |
| 110 | apitest.MustExec(t, env.ServerDB.Model(&database.Book{}).Where("uuid = ?", cliBookJS.UUID).First(&apiBookJS), "getting js book") |
nothing calls this directly
no test coverage detected