Skip to content

Commit

Permalink
test: Endpoint tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DadiBit committed Jun 3, 2023
1 parent 7e3868b commit a426532
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions lib/src/test/kotlin/com/openmeteo/api/common/query/QueryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,54 @@ package com.openmeteo.api.common.query
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlin.test.Test
import kotlin.test.assertEquals

class QueryTest {

data class Pet(
@Serializable
class Pet(
val name: String,
val age: Float,
) : Query

@Test
fun plain() {
assert(Pet("Bob", 3f)
.asString() == "?age=3.0&name=Bob")
val pet = Pet("Bob", 3f)
assertEquals("?name=Bob&age=3.0", Query.asString(pet))
}

interface ProgrammingLanguages {
@SerialName("languages")
val programmingLanguages: List<String>
}

data class Programmer(
@Serializable
class Programmer(
val name: String,
val surname: String,
override val programmingLanguages: List<String>,
) : Query, ProgrammingLanguages
@Serializable(with = ListAsString::class)
@SerialName("languages")
val programmingLanguages: List<String>,
) : Query

@Test
fun `with arrays`() {
fun lists() {
val programmer = Programmer("John", "Doe", listOf(
"Kotlin",
"Java",
"JavaScript",
"HTML",
"CSS",
))
assert(programmer.asString() == "?name=John&languages=Kotlin,Java,JavaScript,HTML,CSS&surname=Doe")
// Do not worry, %2C is the URL encoded comma: it gets decoded properly before splitting
//assertEquals("?name=John&languages=Kotlin,Java,JavaScript,HTML,CSS&surname=Doe",
assertEquals("?name=John&surname=Doe&languages=Kotlin%2CJava%2CJavaScript%2CHTML%2CCSS",
Query.asString(programmer))
}
@Serializable
class Timezone(
override val timezone: com.openmeteo.api.common.time.Timezone?
) : Query.Timezone

@Test
fun timezone_auto() {
val timezone = Timezone(com.openmeteo.api.common.time.Timezone.auto)
assertEquals("?timezone=auto", Query.asString(timezone))
}

}

0 comments on commit a426532

Please sign in to comment.