diff --git a/kotlin/build.gradle b/kotlin/build.gradle index 88f04c0e4..5cc85de25 100644 --- a/kotlin/build.gradle +++ b/kotlin/build.gradle @@ -66,4 +66,10 @@ javadoc { excludes = [ "com/svix/**/*" ] } -apply from: "deploy.gradle" \ No newline at end of file +apply from: "deploy.gradle" + +test { + testLogging { + events "passed", "skipped", "failed" + } +} \ No newline at end of file diff --git a/kotlin/lib/src/test/com/svix/kotlin/BasicTest.kt b/kotlin/lib/src/test/com/svix/kotlin/BasicTest.kt index 093aa447d..88f77e1b7 100644 --- a/kotlin/lib/src/test/com/svix/kotlin/BasicTest.kt +++ b/kotlin/lib/src/test/com/svix/kotlin/BasicTest.kt @@ -1,15 +1,33 @@ package com.svix.kotlin -import com.svix.kotlin.models.ApplicationIn -import com.svix.kotlin.models.MessageIn +import com.svix.kotlin.exceptions.ApiException +import com.svix.kotlin.models.* + + import kotlinx.coroutines.runBlocking +import java.net.URI import kotlin.test.Test import kotlin.test.assertEquals class BasicTest { + + companion object { + private val AUTH_TOKEN: String? = System.getenv("SVIX_TOKEN") + private val SERVER_URL: String? = System.getenv("SVIX_SERVER_URL") + } + + private fun getTestClient(): Svix? { + return if (AUTH_TOKEN == null || SERVER_URL == null) { + // TODO: figure out how to log a warning here to help teach about tests that skip when the env vars are unset. + null + } else { + Svix(AUTH_TOKEN, SvixOptions(SERVER_URL)) + } + } + @Test fun basicCrudTest() { - val svix = Svix(AUTH_TOKEN, SvixOptions(SERVER_URL)) + val svix = getTestClient() ?: return runBlocking { val applicationOut = svix.application.create(ApplicationIn(name = "App1")) assertEquals("App1", applicationOut.name) @@ -18,24 +36,51 @@ class BasicTest { MessageIn( eventType = "invoice.paid", payload = - mapOf( - "id" to "invoice_WF7WtCLFFtd8ubcTgboSFNql", - "status" to "paid", - "attempt" to 2, - ), + mapOf( + "id" to "invoice_WF7WtCLFFtd8ubcTgboSFNql", + "status" to "paid", + "attempt" to 2, + ), ), ) svix.application.delete(applicationOut.id) } } - companion object { - // Token for org org_00000000000LibTest000000000 - private const val AUTH_TOKEN = - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9." + - "eyJpYXQiOjE2NTc2MzQwNjcsImV4cCI6MTk3Mjk5NDA2NywibmJmIjoxNjU3NjM0MDY3LCJpc3M" + - "iOiJzdml4LXNlcnZlciIsInN1YiI6Im9yZ18wMDAwMDAwMDAwMExpYlRlc3QwMDAwMDAwMDAifQ." + - "IAy2wrnWhbGTeGHSYygKOID2LKFITaxNW8mHO7F5jWM" - private const val SERVER_URL = "http://localhost:8071" + @Test + fun kitchenSinkTest() { + val svix = getTestClient() ?: return + + runBlocking { + val appOut = svix.application.create(ApplicationIn(name = "App2")) + try { + svix.eventType.create(EventTypeIn(name = "event.started", description = "Something started")) + } catch (e: ApiException) { + assertEquals(409, e.statusCode, "conflicts are expected but other bad statuses are not") + } + try { + svix.eventType.create(EventTypeIn(name = "event.ended", description = "Something ended")) + } catch (e: ApiException) { + assertEquals(409, e.statusCode, "conflicts are expected but other bad statuses are not") + } + + val epOut = svix.endpoint.create( + appOut.id, + EndpointIn(url = URI("https://example.svix.com"), channels = setOf("ch0", "ch1")) + ) + assertEquals(setOf("ch0", "ch1"), epOut.channels, "initial ep should have 2 channels") + assertEquals(0, epOut.filterTypes?.size ?: 0, "initial ep should have 0 filter types") + val epPatched = svix.endpoint.patch( + appOut.id, + epOut.id, + EndpointPatch(filterTypes = setOf("event.started", "event.ended")) + ) + assertEquals(setOf("ch0", "ch1"), epPatched.channels, "patched ep should have 2 channels") + assertEquals( + setOf("event.started", "event.ended"), + epPatched.filterTypes, + "patched ep should have 2 filter types" + ) + } } }