From c3a8df46d1e55a4edd6a1ea93f79b34f7b73eb98 Mon Sep 17 00:00:00 2001 From: William Brawner Date: Thu, 28 Sep 2023 20:03:44 -0600 Subject: [PATCH] Fix tests --- .idea/misc.xml | 1 - .../NetworkFirstPlausibleClientTest.kt | 21 ++++++++++++++++++- .../plausible/android/PlausibleTest.kt | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d673ade..28cf02f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/plausible/src/test/java/com/wbrawner/plausible/android/NetworkFirstPlausibleClientTest.kt b/plausible/src/test/java/com/wbrawner/plausible/android/NetworkFirstPlausibleClientTest.kt index 1fb01b9..547eef1 100644 --- a/plausible/src/test/java/com/wbrawner/plausible/android/NetworkFirstPlausibleClientTest.kt +++ b/plausible/src/test/java/com/wbrawner/plausible/android/NetworkFirstPlausibleClientTest.kt @@ -1,6 +1,7 @@ package com.wbrawner.plausible.android import kotlinx.coroutines.runBlocking +import org.junit.Assert.assertFalse import org.junit.Before import org.junit.Ignore import org.junit.Test @@ -22,7 +23,7 @@ internal class NetworkFirstPlausibleClientTest { eventDir.delete() eventDir.mkdir() config = ThreadSafePlausibleConfig(eventDir, SCREEN_WIDTH) - TODO("Set up a mock web server and validate the requests received are correct") + // TODO("Set up a mock web server and validate the requests received are correct") } @Ignore("Not yet implemented") @@ -38,6 +39,24 @@ internal class NetworkFirstPlausibleClientTest { ) } + @Test + fun `invalid persisted events are deleted`() { + val invalidEvent = File(eventDir, "invalid-event.json") + invalidEvent.createNewFile() + invalidEvent.writeText("invalid jsopn") + networkFirstClientTest { + client.event( + domain = "test.example.com", + name = "eventUrl", + url = "referrer", + referrer = "referrer", + screenWidth = SCREEN_WIDTH, + props = mapOf("prop1" to "propVal") + ) + } + assertFalse(invalidEvent.exists()) + } + private fun networkFirstClientTest(test: suspend () -> Unit) = runBlocking { client = NetworkFirstPlausibleClient(config, coroutineContext) test() diff --git a/plausible/src/test/java/com/wbrawner/plausible/android/PlausibleTest.kt b/plausible/src/test/java/com/wbrawner/plausible/android/PlausibleTest.kt index 62b4c56..2b4723d 100644 --- a/plausible/src/test/java/com/wbrawner/plausible/android/PlausibleTest.kt +++ b/plausible/src/test/java/com/wbrawner/plausible/android/PlausibleTest.kt @@ -52,6 +52,6 @@ internal class PlausibleTest { assertEquals("app://localhost/eventUrl", event.url) assertEquals(SCREEN_WIDTH, event.screenWidth) assertEquals("referrer", event.referrer) - assertEquals("{\"prop1\":\"propVal\"}", event.props) + assertEquals(mapOf("prop1" to "propVal"), event.props) } } \ No newline at end of file