Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 82c12e14 authored by Patrick Lang's avatar Patrick Lang Committed by GitHub
Browse files

Marked fun updateRelatedTo() as deprecated, deleted tests (#35)

parent 05859b83
Loading
Loading
Loading
Loading
+0 −140
Original line number Diff line number Diff line
@@ -92,146 +92,6 @@ class JtxCollectionTest {
        assertEquals(1, icalobjects.size)
    }

    @Test
    fun updateRelatedTo_check_update_of_linkedId_CHILD_to_PARENT_is_present() {
        JtxCollection.create(testAccount, client, cv)
        val collections = JtxCollection.find(testAccount, client, context, TestJtxCollection.Factory, null, null)

        // insert 2 icalobjects
        val parentCV = ContentValues().apply {
            put(JtxContract.JtxICalObject.SUMMARY, "summary")
            put(JtxContract.JtxICalObject.COMPONENT, JtxContract.JtxICalObject.Component.VJOURNAL.name)
            put(JtxContract.JtxICalObject.UID, "AAA")
            put(JtxContract.JtxICalObject.ICALOBJECT_COLLECTIONID, collections[0].id)
        }
        val parentUri = client.insert(JtxContract.JtxICalObject.CONTENT_URI.asSyncAdapter(testAccount), parentCV)
        val childCV = ContentValues().apply {
            put(JtxContract.JtxICalObject.SUMMARY, "summary")
            put(JtxContract.JtxICalObject.COMPONENT, JtxContract.JtxICalObject.Component.VJOURNAL.name)
            put(JtxContract.JtxICalObject.UID, "BBB")
            put(JtxContract.JtxICalObject.ICALOBJECT_COLLECTIONID, collections[0].id)
        }
        val childUri = client.insert(JtxContract.JtxICalObject.CONTENT_URI.asSyncAdapter(testAccount), childCV)

        val icalobjects = collections[0].queryICalObjects(null, null)
        assertEquals(2, icalobjects.size)

        // link one of them to the other with PARENT reltype
        val parentRelCV = ContentValues().apply {
            put(JtxContract.JtxRelatedto.ICALOBJECT_ID, childUri?.lastPathSegment)
            put(JtxContract.JtxRelatedto.TEXT, "AAA")
            put(JtxContract.JtxRelatedto.RELTYPE, JtxContract.JtxRelatedto.Reltype.PARENT.name)
        }
        client.insert(JtxContract.JtxRelatedto.CONTENT_URI.asSyncAdapter(testAccount), parentRelCV)

        // update related to and check
        collections[0].updateRelatedTo()

        // check child to parent
        client.query(
            JtxContract.JtxRelatedto.CONTENT_URI.asSyncAdapter(testAccount),
            arrayOf(JtxContract.JtxRelatedto.ICALOBJECT_ID, JtxContract.JtxRelatedto.LINKEDICALOBJECT_ID, JtxContract.JtxRelatedto.TEXT, JtxContract.JtxRelatedto.RELTYPE),
            "${JtxContract.JtxRelatedto.ICALOBJECT_ID} = ?",
            arrayOf(childUri?.lastPathSegment),
            null
        ).use {
            assertNotNull(it)
            assertEquals(1, it?.count)
            it?.moveToFirst()
            assertEquals(childUri?.lastPathSegment?.toLong(), it?.getLong(0))   // ICALOBJECT_ID
            assertEquals(parentUri?.lastPathSegment?.toLong(), it?.getLong(1))   // LINKEDICALOBJECT_ID
            assertEquals("AAA", it?.getString(2))   // TEXT (UID)
            assertEquals(JtxContract.JtxRelatedto.Reltype.PARENT.name, it?.getString(3))
        }

        // check parent to child
        client.query(
            JtxContract.JtxRelatedto.CONTENT_URI.asSyncAdapter(testAccount),
            arrayOf(JtxContract.JtxRelatedto.ICALOBJECT_ID, JtxContract.JtxRelatedto.LINKEDICALOBJECT_ID, JtxContract.JtxRelatedto.TEXT, JtxContract.JtxRelatedto.RELTYPE),
            "${JtxContract.JtxRelatedto.ICALOBJECT_ID} = ?",
            arrayOf(parentUri?.lastPathSegment),
            null
        ).use {
            assertNotNull(it)
            assertEquals(1, it?.count)
            it?.moveToFirst()
            assertEquals(parentUri?.lastPathSegment?.toLong(), it?.getLong(0))   // ICALOBJECT_ID
            assertEquals(childUri?.lastPathSegment?.toLong(), it?.getLong(1))   // LINKEDICALOBJECT_ID
            assertEquals("BBB", it?.getString(2))   // TEXT (UID)
            assertEquals(JtxContract.JtxRelatedto.Reltype.CHILD.name, it?.getString(3))
        }
    }

    @Test
    fun updateRelatedTo_check_update_of_linkedId_PARENT_TO_CHILD_is_present() {
        JtxCollection.create(testAccount, client, cv)
        val collections = JtxCollection.find(testAccount, client, context, TestJtxCollection.Factory, null, null)

        // insert 2 icalobjects
        val parentCV = ContentValues().apply {
            put(JtxContract.JtxICalObject.SUMMARY, "summary")
            put(JtxContract.JtxICalObject.COMPONENT, JtxContract.JtxICalObject.Component.VJOURNAL.name)
            put(JtxContract.JtxICalObject.UID, "AAA")
            put(JtxContract.JtxICalObject.ICALOBJECT_COLLECTIONID, collections[0].id)
        }
        val parentUri = client.insert(JtxContract.JtxICalObject.CONTENT_URI.asSyncAdapter(testAccount), parentCV)
        val childCV = ContentValues().apply {
            put(JtxContract.JtxICalObject.SUMMARY, "summary")
            put(JtxContract.JtxICalObject.COMPONENT, JtxContract.JtxICalObject.Component.VJOURNAL.name)
            put(JtxContract.JtxICalObject.UID, "BBB")
            put(JtxContract.JtxICalObject.ICALOBJECT_COLLECTIONID, collections[0].id)
        }
        val childUri = client.insert(JtxContract.JtxICalObject.CONTENT_URI.asSyncAdapter(testAccount), childCV)

        val icalobjects = collections[0].queryICalObjects(null, null)
        assertEquals(2, icalobjects.size)

        // link one of them to the other with PARENT reltype
        val parent2childRelCV = ContentValues().apply {
            put(JtxContract.JtxRelatedto.ICALOBJECT_ID, parentUri?.lastPathSegment)
            put(JtxContract.JtxRelatedto.TEXT, "BBB")
            put(JtxContract.JtxRelatedto.RELTYPE, JtxContract.JtxRelatedto.Reltype.CHILD.name)
        }
        client.insert(JtxContract.JtxRelatedto.CONTENT_URI.asSyncAdapter(testAccount), parent2childRelCV)

        // update related to and check
        collections[0].updateRelatedTo()

        // check child to parent
        client.query(
            JtxContract.JtxRelatedto.CONTENT_URI.asSyncAdapter(testAccount),
            arrayOf(JtxContract.JtxRelatedto.ICALOBJECT_ID, JtxContract.JtxRelatedto.LINKEDICALOBJECT_ID, JtxContract.JtxRelatedto.TEXT, JtxContract.JtxRelatedto.RELTYPE),
            "${JtxContract.JtxRelatedto.ICALOBJECT_ID} = ?",
            arrayOf(parentUri?.lastPathSegment),
            null
        ).use {
            assertNotNull(it)
            assertEquals(1, it?.count)
            it?.moveToFirst()
            assertEquals(parentUri?.lastPathSegment?.toLong(), it?.getLong(0))   // ICALOBJECT_ID
            assertEquals(childUri?.lastPathSegment?.toLong(), it?.getLong(1))   // LINKEDICALOBJECT_ID
            assertEquals("BBB", it?.getString(2))   // TEXT (UID)
            assertEquals(JtxContract.JtxRelatedto.Reltype.CHILD.name, it?.getString(3))
        }

        // check parent to child
        client.query(
            JtxContract.JtxRelatedto.CONTENT_URI.asSyncAdapter(testAccount),
            arrayOf(JtxContract.JtxRelatedto.ICALOBJECT_ID, JtxContract.JtxRelatedto.LINKEDICALOBJECT_ID, JtxContract.JtxRelatedto.TEXT, JtxContract.JtxRelatedto.RELTYPE),
            "${JtxContract.JtxRelatedto.ICALOBJECT_ID} = ?",
            arrayOf(childUri?.lastPathSegment),
            null
        ).use {
            assertNotNull(it)
            assertEquals(1, it?.count)
            it?.moveToFirst()
            assertEquals(childUri?.lastPathSegment?.toLong(), it?.getLong(0))   // ICALOBJECT_ID
            assertEquals(parentUri?.lastPathSegment?.toLong(), it?.getLong(1))   // LINKEDICALOBJECT_ID
            assertEquals("AAA", it?.getString(2))   // TEXT (UID)
            assertEquals(JtxContract.JtxRelatedto.Reltype.PARENT.name, it?.getString(3))
        }
    }

    @Test
    fun getICSForCollection_test() {
        val collectionUri = JtxCollection.create(testAccount, client, cv)
+1 −0
Original line number Diff line number Diff line
@@ -185,6 +185,7 @@ open class JtxCollection<out T: JtxICalObject>(val account: Account,
     * STEP 2/3: jtx Board saves the relations in both directions, the Parent has an entry for his Child, the Child has an entry for his Parent. Step 2 and Step 3 make sure, that the Child-Parent pair is
     *         present in both directions.
     */
    @Deprecated("Moved to jtx Board content provider (function updateRelatedTo()). This function here will be deleted in one of the next versions.")
    fun updateRelatedTo() {
        // STEP 1: first find entries to update (all entries with 0 in related-to)
        client.query(JtxContract.JtxRelatedto.CONTENT_URI.asSyncAdapter(account), arrayOf(JtxContract.JtxRelatedto.TEXT), "${JtxContract.JtxRelatedto.LINKEDICALOBJECT_ID} = ?", arrayOf("0"), null).use {