From 0f565c782a573765a23f2ab0073c530ec52ab029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Gr=C3=BCneberg?= Date: Mon, 1 Feb 2021 20:30:56 +0100 Subject: [PATCH] Tests for filter builder --- .../postgrest/builder/PostgrestBuilder.kt | 4 ++ .../builder/PostgrestFilterBuilderTest.kt | 59 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/test/kotlin/io/supabase/postgrest/builder/PostgrestFilterBuilderTest.kt diff --git a/src/main/kotlin/io/supabase/postgrest/builder/PostgrestBuilder.kt b/src/main/kotlin/io/supabase/postgrest/builder/PostgrestBuilder.kt index 88036ce..f6115aa 100644 --- a/src/main/kotlin/io/supabase/postgrest/builder/PostgrestBuilder.kt +++ b/src/main/kotlin/io/supabase/postgrest/builder/PostgrestBuilder.kt @@ -57,6 +57,10 @@ open class PostgrestBuilder { this.body = body } + fun getSearchParams(): Map { + return searchParams + } + fun execute(): PostgrestHttpResponse { checkNotNull(method) { "Method cannot be null" } diff --git a/src/test/kotlin/io/supabase/postgrest/builder/PostgrestFilterBuilderTest.kt b/src/test/kotlin/io/supabase/postgrest/builder/PostgrestFilterBuilderTest.kt new file mode 100644 index 0000000..42d7703 --- /dev/null +++ b/src/test/kotlin/io/supabase/postgrest/builder/PostgrestFilterBuilderTest.kt @@ -0,0 +1,59 @@ +package io.supabase.postgrest.builder + +import assertk.assertThat +import assertk.assertions.isEqualTo +import io.mockk.mockk +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test + +internal class PostgrestFilterBuilderTest { + + private val postgrestBuilderMock = mockk>() + private var filterBuilder: PostgrestFilterBuilder? = null + + @BeforeEach + fun beforeEach() { + filterBuilder = PostgrestFilterBuilder(postgrestBuilderMock) + } + + @Test + fun `not`() { + filterBuilder!!.not("columnName", FilterOperator.CD, "val") + assertSearchParam("columnName", "not.cd.val") + } + + @Test + fun `or`() { + filterBuilder!!.or("fff") + assertSearchParam("or", "(fff)") + } + + @Test + fun `eq`() { + filterBuilder!!.eq("columnName", "val") + assertSearchParam("columnName", "eq.val") + } + + @Test + fun `neq`() { + filterBuilder!!.neq("columnName", "val") + assertSearchParam("columnName", "neq.val") + } + + @Test + fun `gt`() { + filterBuilder!!.gt("columnName", "val") + assertSearchParam("columnName", "gt.val") + } + + @Test + fun `gte`() { + filterBuilder!!.gte("columnName", "val") + assertSearchParam("columnName", "gte.val") + } + + private fun assertSearchParam(name: String, value: String) { + val searchParams = filterBuilder!!.getSearchParams() + assertThat(searchParams[name]).isEqualTo(value) + } +} \ No newline at end of file