Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change BidResponse.ext to be a JsonElement #155

Merged
merged 5 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class BidResponse(
@JvmField @SerialName("duration") public val duration: Int = 0,
@JvmField @SerialName("exp") public val exp: Int = -1,
@JvmField @SerialName("external_notifications") public val external_notifications: Map<String, String> = emptyMap(),
@JvmField @SerialName("ext") public val ext: Map<String, String> = emptyMap(),
@JvmField @SerialName("ext") public val ext: Extension = Extension(),
) {
/** Urls to fire a request to when an impression is registered */
public val impression_trackers: Array<String>? get() = trackers["impression_trackers"]
Expand All @@ -66,9 +66,6 @@ public class BidResponse(
/** Url to fire a request to when this bid loses an auction */
public val loss_response: String? get() = external_notifications["loss_response"]

public val useNewRenderer: Boolean
get() = ext["use_new_renderer"].toBoolean()

public companion object {
/** Decodes a BidResponse from a Json string using the built in serializer */
@JvmStatic @JvmOverloads
Expand All @@ -84,4 +81,9 @@ public class BidResponse(
jsonSerializer: Json = BidRequest.lenientSerializer,
): String = jsonSerializer.encodeToString(serializer(), response)
}

@Serializable
public class Extension(
@JvmField @SerialName("use_new_renderer") public val use_new_renderer: Boolean = false,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldStartWith

const val testJson = """
private fun testJson(ext: String = "") = """
{
"type": "native",
"auction_id": "d07668d6-35ba-4870-a3cd-02b18fec1a12",
Expand All @@ -33,12 +33,13 @@ const val testJson = """
"win_response": "https://test.adsbynimbus.com/win_response/",
"loss_response": "https://test.adsbynimbus.com/loss_response/auctionPrice=[AUCTION_PRICE]&auctionMinToWin=[AUCTION_MIN_TO_WIN]&winningSource=[WINNING_SOURCE]"
}
$ext
}
"""

class DeserializationTest : StringSpec({

val response = BidResponse.fromJson(testJson)
val response = BidResponse.fromJson(testJson())

"BidResponse fromJson deserializes the type field" {
response.type shouldBe "native"
Expand Down Expand Up @@ -104,6 +105,20 @@ class DeserializationTest : StringSpec({
response.win_response shouldBe "https://test.adsbynimbus.com/win_response/"
}

"BidResponse fromJson deserializes use_new_renderer" {
response.ext.use_new_renderer shouldBe false
BidResponse.fromJson(testJson("""
,"ext": {
"use_new_renderer": true
}
""".trimIndent())).ext.use_new_renderer shouldBe true
BidResponse.fromJson(testJson("""
,"ext": {
"use_new_renderer": false
}
""".trimIndent())).ext.use_new_renderer shouldBe false
}

"BidResponse fromJson deserializes loss urls" {
response.loss_response shouldStartWith "https://test.adsbynimbus.com/loss_response/"
response.loss_response shouldContain "auctionPrice=[AUCTION_PRICE]"
Expand Down
Loading