Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
Tests for filter builder
Browse files Browse the repository at this point in the history
  • Loading branch information
kevcodez committed Feb 1, 2021
1 parent 43ef2db commit 0f565c7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ open class PostgrestBuilder<T : Any> {
this.body = body
}

fun getSearchParams(): Map<String, String> {
return searchParams
}

fun execute(): PostgrestHttpResponse {
checkNotNull(method) { "Method cannot be null" }

Expand Down
Original file line number Diff line number Diff line change
@@ -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<PostgrestBuilder<Any>>()
private var filterBuilder: PostgrestFilterBuilder<Any>? = 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)
}
}

0 comments on commit 0f565c7

Please sign in to comment.