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

Function TestSync_EmptyServer

pkg/e2e/sync/empty_server_test.go:36–728  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

34)
35
36func TestSync_EmptyServer(t *testing.T) {
37 t.Run("sync to empty server after syncing to non-empty server", func(t *testing.T) {
38 // Test server data loss/wipe scenario (disaster recovery):
39 // Verify empty server detection works when the server loses all its data
40
41 env := setupTestEnv(t)
42
43 user := setupUserAndLogin(t, env)
44
45 // Step 1: Create local data and sync to server
46 clitest.RunDnoteCmd(t, env.CmdOpts, cliBinaryName, "add", "js", "-c", "js1")
47 clitest.RunDnoteCmd(t, env.CmdOpts, cliBinaryName, "add", "css", "-c", "css1")
48 clitest.RunDnoteCmd(t, env.CmdOpts, cliBinaryName, "sync")
49
50 // Verify sync succeeded
51 checkState(t, env.DB, user, env.ServerDB, systemState{
52 clientNoteCount: 2,
53 clientBookCount: 2,
54 clientLastMaxUSN: 4,
55 clientLastSyncAt: serverTime.Unix(),
56 serverNoteCount: 2,
57 serverBookCount: 2,
58 serverUserMaxUSN: 4,
59 })
60
61 // Step 2: Switch to a completely new empty server
62 switchToEmptyServer(t, &env)
63
64 // Recreate user and session on new server
65 user = setupUserAndLogin(t, env)
66
67 // Step 3: Sync again - should detect empty server and prompt user
68 // User confirms with "y"
69 clitest.MustWaitDnoteCmd(t, env.CmdOpts, clitest.UserConfirmEmptyServerSync, cliBinaryName, "sync")
70
71 // Step 4: Verify data was uploaded to the empty server
72 checkState(t, env.DB, user, env.ServerDB, systemState{
73 clientNoteCount: 2,
74 clientBookCount: 2,
75 clientLastMaxUSN: 4,
76 clientLastSyncAt: serverTime.Unix(),
77 serverNoteCount: 2,
78 serverBookCount: 2,
79 serverUserMaxUSN: 4,
80 })
81
82 // Verify the content is correct on both client and server
83 var cliNote1JS, cliNote1CSS cliDatabase.Note
84 var cliBookJS, cliBookCSS cliDatabase.Book
85 cliDatabase.MustScan(t, "finding cliNote1JS", env.DB.QueryRow("SELECT uuid, body FROM notes WHERE body = ?", "js1"), &cliNote1JS.UUID, &cliNote1JS.Body)
86 cliDatabase.MustScan(t, "finding cliNote1CSS", env.DB.QueryRow("SELECT uuid, body FROM notes WHERE body = ?", "css1"), &cliNote1CSS.UUID, &cliNote1CSS.Body)
87 cliDatabase.MustScan(t, "finding cliBookJS", env.DB.QueryRow("SELECT uuid, label FROM books WHERE label = ?", "js"), &cliBookJS.UUID, &cliBookJS.Label)
88 cliDatabase.MustScan(t, "finding cliBookCSS", env.DB.QueryRow("SELECT uuid, label FROM books WHERE label = ?", "css"), &cliBookCSS.UUID, &cliBookCSS.Label)
89
90 assert.Equal(t, cliNote1JS.Body, "js1", "js note body mismatch")
91 assert.Equal(t, cliNote1CSS.Body, "css1", "css note body mismatch")
92 assert.Equal(t, cliBookJS.Label, "js", "js book label mismatch")
93 assert.Equal(t, cliBookCSS.Label, "css", "css book label mismatch")

Callers

nothing calls this directly

Calls 14

EqualFunction · 0.92
NotEqualFunction · 0.92
setupUserAndLoginFunction · 0.85
checkStateFunction · 0.85
switchToEmptyServerFunction · 0.85
apiCreateBookFunction · 0.85
apiCreateNoteFunction · 0.85
setupTestServerFunction · 0.85
updateConfigAPIEndpointFunction · 0.85
loginFunction · 0.85
OpenMethod · 0.80
setupTestEnvFunction · 0.70

Tested by

no test coverage detected