-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kotlin: Add test for query param encoding
- Loading branch information
Showing
5 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.svix.kotlin | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer | ||
import com.github.tomakehurst.wiremock.client.WireMock | ||
import com.github.tomakehurst.wiremock.client.WireMock.* | ||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration.options | ||
import com.svix.kotlin.models.Ordering | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.jupiter.api.* | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
class WiremockTests { | ||
|
||
private val wireMockServer = WireMockServer(options().port(0).withRootDirectory("lib/src/test/resources")) | ||
|
||
@BeforeAll | ||
fun beforeAll() { | ||
wireMockServer.start() | ||
} | ||
|
||
@AfterAll | ||
fun afterAll() { | ||
wireMockServer.stop() | ||
} | ||
|
||
@BeforeEach | ||
fun beforeEach() { | ||
wireMockServer.resetAll() | ||
} | ||
|
||
private fun testClient(): Svix { | ||
return Svix("testtk_asd12.eu", SvixOptions(this.wireMockServer.baseUrl())) | ||
} | ||
|
||
@Test | ||
fun testEnumQueryParamEncodedCorrectly() { | ||
val svx = testClient() | ||
wireMockServer.stubFor( | ||
WireMock.get(urlMatching("/api/v1/app?.*")) | ||
.willReturn(WireMock.ok().withBodyFile("ListResponseApplicationOut.json")) | ||
) | ||
runBlocking { | ||
svx.application.list( | ||
ApplicationListOptions( | ||
limit = 5UL, | ||
order = Ordering.ASCENDING, | ||
iterator = "cool-string-!@#$%^", | ||
) | ||
) | ||
} | ||
wireMockServer.verify( | ||
1, | ||
getRequestedFor( | ||
urlEqualTo( | ||
"/api/v1/app?limit=5&iterator=cool-string-%21%40%23%24%25%5E&order=ascending" | ||
) | ||
), | ||
) | ||
} | ||
|
||
@Test | ||
fun testSetQueryParamEncodedCorrectly() { | ||
val svx = testClient() | ||
wireMockServer.stubFor( | ||
WireMock.get(urlMatching("/api/v1/app/app_asd123/msg.*")) | ||
.willReturn(WireMock.ok().withBodyFile("ListResponseMessageOut.json")) | ||
) | ||
runBlocking { | ||
svx.message.list( | ||
"app_asd123", | ||
MessageListOptions(eventTypes = setOf("key3", "key4", "key1")), | ||
) | ||
} | ||
wireMockServer.verify( | ||
1, | ||
getRequestedFor(urlEqualTo("/api/v1/app/app_asd123/msg?event_types=key1%2Ckey3%2Ckey4")), | ||
) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
kotlin/lib/src/test/resources/__files/ListResponseApplicationOut.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"data":[{"uid":"unique-identifier","name":"My first application","rateLimit":0,"id":"app_1srOrx2ZWZBpBUvZwXKQmoEYga2","createdAt":"2019-08-24T14:15:22Z","updatedAt":"2019-08-24T14:15:22Z","metadata":{"property1":"string","property2":"string"}}],"iterator":"iterator","prevIterator":"-iterator","done":true} |
1 change: 1 addition & 0 deletions
1
kotlin/lib/src/test/resources/__files/ListResponseMessageOut.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"data":[{"eventId":"unique-identifier","eventType":"user.signup","payload":{"email":"[email protected]","type":"user.created","username":"test_user"},"channels":["project_123","group_2"],"id":"msg_1srOrx2ZWZBpBUvZwXKQmoEYga2","timestamp":"2019-08-24T14:15:22Z","tags":["project_1337"]}],"iterator":"iterator","prevIterator":"-iterator","done":true} |