-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
1 deletion.
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
56 changes: 56 additions & 0 deletions
56
TopsortAnalytics/src/test/java/com/topsort/analytics/banners/runTest.kt
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,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) | ||
} | ||
} |