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

Function TestSync

pkg/e2e/sync/basic_test.go:1033–3506  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1031}
1032
1033func TestSync(t *testing.T) {
1034 t.Run("client adds a book and a note", func(t *testing.T) {
1035 setup := func(t *testing.T, env testEnv, user database.User) map[string]string {
1036 clitest.RunDnoteCmd(t, env.CmdOpts, cliBinaryName, "add", "js", "-c", "js1")
1037
1038 return map[string]string{}
1039 }
1040
1041 assert := func(t *testing.T, env testEnv, user database.User, ids map[string]string) {
1042 cliDB := env.DB
1043 apiDB := env.ServerDB
1044
1045 checkState(t, env.DB, user, env.ServerDB, systemState{
1046 clientNoteCount: 1,
1047 clientBookCount: 1,
1048 clientLastMaxUSN: 2,
1049 clientLastSyncAt: serverTime.Unix(),
1050 serverNoteCount: 1,
1051 serverBookCount: 1,
1052 serverUserMaxUSN: 2,
1053 })
1054
1055 // test client
1056 // assert on bodys and labels
1057 var cliNote1JS cliDatabase.Note
1058 var cliBookJS cliDatabase.Book
1059 cliDatabase.MustScan(t, "finding cliNote1JS", cliDB.QueryRow("SELECT uuid, body, usn FROM notes WHERE body = ?", "js1"), &cliNote1JS.UUID, &cliNote1JS.Body, &cliNote1JS.USN)
1060 cliDatabase.MustScan(t, "finding cliBookJS", cliDB.QueryRow("SELECT uuid, label, usn FROM books WHERE label = ?", "js"), &cliBookJS.UUID, &cliBookJS.Label, &cliBookJS.USN)
1061 assert.Equal(t, cliNote1JS.Body, "js1", "cliNote1JS Body mismatch")
1062 assert.Equal(t, cliBookJS.Label, "js", "cliBookJS Label mismatch")
1063 // assert on deleted
1064 assert.Equal(t, cliNote1JS.Deleted, false, "cliNote1JS Deleted mismatch")
1065 assert.Equal(t, cliBookJS.Deleted, false, "cliBookJS Deleted mismatch")
1066
1067 // test server
1068 var apiNote1JS database.Note
1069 apitest.MustExec(t, apiDB.Where("user_id = ? AND uuid = ?", user.ID, cliNote1JS.UUID).First(&apiNote1JS), "finding apiNote1JS")
1070 var apiBookJS database.Book
1071 apitest.MustExec(t, apiDB.Where("user_id = ? AND uuid = ?", user.ID, cliBookJS.UUID).First(&apiBookJS), "finding apiBookJS")
1072
1073 // assert on usn
1074 assert.NotEqual(t, apiNote1JS.USN, 0, "apiNote1JS USN mismatch")
1075 assert.NotEqual(t, apiBookJS.USN, 0, "apiBookJS USN mismatch")
1076 // assert on bodys and labels
1077 assert.Equal(t, apiNote1JS.Body, "js1", "apiNote1JS Body mismatch")
1078 assert.Equal(t, apiBookJS.Label, "js", "apiBookJS Label mismatch")
1079 // assert on deleted
1080 assert.Equal(t, apiNote1JS.Deleted, false, "apiNote1JS Deleted mismatch")
1081 assert.Equal(t, apiBookJS.Deleted, false, "apiBookJS Deleted mismatch")
1082 }
1083
1084 testSyncCmd(t, false, setup, assert)
1085 testSyncCmd(t, true, setup, assert)
1086 })
1087
1088 t.Run("client deletes a book", func(t *testing.T) {
1089 setup := func(t *testing.T, env testEnv, user database.User) map[string]string {
1090 // 1. on server

Callers

nothing calls this directly

Calls 11

EqualFunction · 0.92
NotEqualFunction · 0.92
checkStateFunction · 0.85
testSyncCmdFunction · 0.85
apiCreateBookFunction · 0.85
apiCreateNoteFunction · 0.85
apiPatchBookFunction · 0.85
apiDeleteBookFunction · 0.85
apiPatchNoteFunction · 0.85
apiDeleteNoteFunction · 0.85
QueryRowMethod · 0.65

Tested by

no test coverage detected