Fix tests

This commit is contained in:
William Brawner 2023-09-28 20:03:44 -06:00
parent 92a00456c3
commit c3a8df46d1
Signed by: wbrawner
GPG key ID: 8FF12381C6C90D35
3 changed files with 21 additions and 3 deletions

View file

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17_PREVIEW" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">

View file

@ -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()

View file

@ -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)
}
}