Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fcs-ts committed Aug 12, 2024
1 parent 10e3966 commit 2e06e97
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fun runBannerAuction(config: BannerConfig): BannerResponse? {
}

/**
* Builds a low-leve Auction object to be run with TopsortAuctionHttpService.
* Builds a low-level Auction object to be run with TopsortAuctionHttpService.
*
* Generally, you shouldn't be calling this function yourself and you should use runBannerAuction instead.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.topsort.analytics.banners

import org.assertj.core.api.Assertions.assertThat
import org.json.JSONObject
import org.junit.Test

internal class RunTest {
@Test
fun buildLandingPageBanner() {
val slot = "slot"
val ids = listOf("id1", "id2")
val bannerConfig = BannerConfig.LandingPage(slotId = slot, ids = ids)
val bannerAuction = buildBannerAuction(bannerConfig);
val json = JSONObject.wrap(bannerAuction)!!.toString()
val expectedJson =
"{\"slots\":1,\"slotId\":\"$slot\",\"type\":\"banners\",\"device\":\"mobile\",\"products\":{\"ids\":[\"${ids[0]}\",\"${ids[1]}\"]}}"
assertThat(json).isEqualTo(expectedJson)
}

@Test
fun buildSingleCategoryBanner() {
val slot = "slot"
val category = "category"
val bannerConfig = BannerConfig.CategorySingle(slotId = slot, category = category)
val bannerAuction = buildBannerAuction(bannerConfig);
val json = JSONObject.wrap(bannerAuction)!!.toString()
val expectedJson =
"{\"slots\":1,\"slotId\":\"$slot\",\"category\":{\"id\":\"$category\"},\"type\":\"banners\",\"device\":\"mobile\"}}"
assertThat(json).isEqualTo(expectedJson)
}

@Test
fun buildMultipleCategoryBanner() {
val slot = "slot"
val categories = listOf("cat1", "cat2")
val bannerConfig = BannerConfig.CategoryMultiple(slotId = slot, categories = categories)
val bannerAuction = buildBannerAuction(bannerConfig);
val json = JSONObject.wrap(bannerAuction)!!.toString()
val expectedJson =
"{\"slots\":1,\"slotId\":\"$slot\",\"category\":{\"ids\":[\"${categories[0]}\",\"${categories[1]}\"]},\"type\":\"banners\",\"device\":\"mobile\"}}"
assertThat(json).isEqualTo(expectedJson)
}

@Test
fun buildDisjuctionsCategoryBanner() {
val slot = "slot"
val disjunctions = listOf(listOf("cat1", "cat2"), listOf("cat3"))
val bannerConfig =
BannerConfig.CategoryDisjunctions(slotId = slot, disjunctions = disjunctions)
val bannerAuction = buildBannerAuction(bannerConfig);
val json = JSONObject.wrap(bannerAuction)!!.toString()
val expectedJson =
"{\"slots\":1,\"slotId\":\"$slot\",\"category\":{\"disjunctions\":[[\"${disjunctions[0][0]}\",\"${disjunctions[0][1]}\"],[\"${disjunctions[1][0]}\"]]},\"type\":\"banners\",\"device\":\"mobile\"}}"
assertThat(json).isEqualTo(expectedJson)
}
}

0 comments on commit 2e06e97

Please sign in to comment.