Skip to content

Commit

Permalink
kotlin: Add instant(timestamp) tests
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-mman committed Feb 13, 2025
1 parent 2edaacb commit 6ed68f7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
49 changes: 49 additions & 0 deletions kotlin/lib/src/test/com/svix/kotlin/WiremockTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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.exceptions.ApiException
import com.svix.kotlin.models.AppUsageStatsIn
import com.svix.kotlin.models.EndpointPatch
import com.svix.kotlin.models.MessageIn
import com.svix.kotlin.models.Ordering
Expand Down Expand Up @@ -224,4 +225,52 @@ class WiremockTests {
)
}
}

@Test
fun instantSerializedCorrectly() {
val svx = testClient()
wireMockServer.stubFor(
WireMock.get(urlMatching("/api/v1/app/ap/msg/msg_asd123"))
// this file includes a string timestamp `2025-02-12T22:24:32.864755Z`
.willReturn(WireMock.ok().withBodyFile("MessageOut.json"))
)
runBlocking {
val res = svx.message.get("ap", "msg_asd123")
assertEquals(Instant.fromEpochSeconds(1739399072, 864755000), res.timestamp)
}

wireMockServer.verify(1, getRequestedFor(urlEqualTo("/api/v1/app/ap/msg/msg_asd123")))
}

@Test
fun instantDeserializedCorrectly() {
val svx = testClient()
wireMockServer.stubFor(
WireMock.post(urlMatching("/api/v1/stats/usage/app"))
.willReturn(
WireMock.ok()
.withBody(
"""{"unresolvedAppIds":["unique-identifier"],"id":"qtask_1srOrx2ZWZBpBUvZwXKQmoEYga2","status":"running","task":"endpoint.replay"}"""
)
)
)
runBlocking {
svx.statistics.aggregateAppStats(
AppUsageStatsIn(
since = Instant.fromEpochSeconds(1739399072, 864755000),
until = Instant.fromEpochSeconds(1739399072, 864755000),
)
)
}

wireMockServer.verify(
1,
getRequestedFor(urlEqualTo("/api/v1/stats/usage/app"))
.withRequestBody(
equalTo(
"""{"since":"2025-02-12T22:24:32.864755Z","until":"2025-02-12T22:24:32.864755Z"}"""
)
),
)
}
}
2 changes: 1 addition & 1 deletion kotlin/lib/src/test/resources/__files/MessageOut.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"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"] }
{"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":"2025-02-12T22:24:32.864755Z","tags":["project_1337"]}

0 comments on commit 6ed68f7

Please sign in to comment.