diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-10-10 12:56:26 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-10-10 12:56:26 +0200 |
| commit | a0793dd37030f7213ecb07a018b11e6a8adf9238 (patch) | |
| tree | 5de1046eae9b3747ac97a81652590fb6af99622b /packages/meshbay-android/app/src/test | |
| parent | 044c585f73cfd548e300859e89eaf5dcb40d3d3c (diff) | |
| download | meshbay-a0793dd37030f7213ecb07a018b11e6a8adf9238.tar.gz | |
feat(android): back the phone's contacts up to a group of one's own
A Contacts backup section on the Android Sync page sends a dated .vcf into
<folder>/<account>-contacts once a day when the address book changed, only
to a group the account is alone in, checked again at every run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-android/app/src/test')
| -rw-r--r-- | packages/meshbay-android/app/src/test/kotlin/org/meshbay/client/DocSyncTest.kt | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/packages/meshbay-android/app/src/test/kotlin/org/meshbay/client/DocSyncTest.kt b/packages/meshbay-android/app/src/test/kotlin/org/meshbay/client/DocSyncTest.kt new file mode 100644 index 0000000..276f1fd --- /dev/null +++ b/packages/meshbay-android/app/src/test/kotlin/org/meshbay/client/DocSyncTest.kt @@ -0,0 +1,55 @@ +package org.meshbay.client + +import org.json.JSONObject +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotEquals +import org.junit.Assert.assertNull +import org.junit.Assert.assertThrows +import org.junit.Test +import org.meshbay.client.phonesync.DocConfig +import org.meshbay.client.phonesync.DocPlan +import java.util.TimeZone + +class DocSyncTest { + private val utc = TimeZone.getTimeZone("UTC") + // 2026-10-09 12:00:00 UTC + private val oct9 = 1791547200000L + + private fun settings(account: String = "bob", folder: String = "Backups") = JSONObject() + .put("account", account).put("groupId", "g1").put("groupName", "Mine").put("owner", "bob") + .put("folder", folder) + + @Test fun `each kind goes into a folder of its own named for the account`() { + val c = DocConfig.fromJson(settings(folder = "/Backups/Phone/")) + assertEquals("Backups/Phone/bob-contacts", DocPlan.dirFor(c, "contacts")) + assertEquals("Backups/Phone/bob-messages", DocPlan.dirFor(c, "messages")) + } + + @Test fun `a file is named for when it was taken, in the phone's time`() { + assertEquals("contacts-2026-10-09-1200.vcf", DocPlan.nameFor("contacts", "vcf", oct9, utc)) + assertEquals("contacts-2026-10-09-1400.vcf", + DocPlan.nameFor("contacts", "vcf", oct9, TimeZone.getTimeZone("Europe/Paris"))) + } + + @Test fun `a folder that climbs out or an account that is not a name is refused`() { + for (bad in listOf("../etc", "Backups/../x", "Backups//x", "./x", "")) { + assertThrows(bad, IllegalArgumentException::class.java) { DocConfig.fromJson(settings(folder = bad)) } + } + for (bad in listOf("../bob", "bob/x", "", "-bob")) { + assertThrows(bad, IllegalArgumentException::class.java) { DocConfig.fromJson(settings(account = bad)) } + } + } + + @Test fun `settings survive being stored`() { + val c = DocConfig.fromJson(settings()) + assertEquals(c, DocConfig.parse(c.toJson().toString())) + assertNull(DocConfig.parse("{not json")) + } + + @Test fun `another group or folder is another backup`() { + val a = DocConfig.fromJson(settings()) + assertNotEquals(a.ledgerKey, DocConfig.fromJson(settings(folder = "Other")).ledgerKey) + assertNotEquals(a.ledgerKey, DocConfig.fromJson(settings().put("groupId", "g2")).ledgerKey) + assertEquals(a.ledgerKey, DocConfig.fromJson(settings().put("groupName", "Renamed")).ledgerKey) + } +} |