Add private CardDAV synchronization and contact revision recovery
This commit is contained in:
1 parent
433169c7e7
commit
19e12f96a8
32 files changed
+1855
-47
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -8,6 +9,48 @@ import (
|
||||
"pageswiki/internal/db"
|
||||
)
|
||||
|
||||
func TestContactDAVUpgradePreservesRowsAndTracksChanges(t *testing.T) {
|
||||
st := newSchemaTestStore(t)
|
||||
ctx := context.Background()
|
||||
if e := db.ApplySQLiteMigrations(ctx, st.DB, "contacts", contactMigrations[:1]); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e := st.DB.Exec(`INSERT INTO organizer_contacts VALUES('d','u','c','uid',1,'Name','name','{"name":"Name"}','hash',0)`); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for range 2 {
|
||||
if e := st.ensureSchemaComponent("contacts"); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
var name, data string
|
||||
var before, after int64
|
||||
var count int
|
||||
if e := st.DB.QueryRow(`SELECT name FROM organizer_contact_names WHERE uuid='c'`).Scan(&name); e != nil || name != "c.vcf" {
|
||||
t.Fatal(name, e)
|
||||
}
|
||||
if e := st.DB.QueryRow(`SELECT data FROM organizer_contacts WHERE uuid='c'`).Scan(&data); e != nil || data != `{"name":"Name"}` {
|
||||
t.Fatal(data, e)
|
||||
}
|
||||
if e := st.DB.QueryRow(`SELECT sequence FROM organizer_contact_changes WHERE uuid='c'`).Scan(&before); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for range 3 {
|
||||
if _, e := st.DB.Exec(`UPDATE organizer_contacts SET deleted=1 WHERE uuid='c'`); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
if e := st.DB.QueryRow(`SELECT count(*),max(sequence) FROM organizer_contact_changes WHERE uuid='c'`).Scan(&count, &after); e != nil || count != 1 || after <= before {
|
||||
t.Fatal(count, before, after, e)
|
||||
}
|
||||
if _, e := st.DB.Exec(`INSERT INTO organizer_dav_credentials VALUES('credential'); INSERT INTO organizer_contact_credentials VALUES('credential'); DELETE FROM organizer_dav_credentials WHERE id='credential'`); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e := st.DB.QueryRow(`SELECT count(*) FROM organizer_contact_credentials`).Scan(&count); e != nil || count != 0 {
|
||||
t.Fatal(count, e)
|
||||
}
|
||||
}
|
||||
|
||||
func newSchemaTestStore(t *testing.T) *Store {
|
||||
t.Helper()
|
||||
database, err := db.Open(filepath.Join(t.TempDir(), "schema.db"))
|
||||
@@ -20,6 +63,9 @@ func newSchemaTestStore(t *testing.T) *Store {
|
||||
if _, err = database.Exec(`CREATE TABLE organizer_items(domain_uuid TEXT,owner_uuid TEXT,uuid TEXT,kind TEXT,data TEXT)`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = database.Exec(`CREATE TABLE organizer_dav_credentials(id TEXT PRIMARY KEY)`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return &Store{DB: database}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user