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

Update unit tests in pillarbox-analytics #411

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ dependencyAnalysis {
}
}

// Required because of https://github.com/autonomousapps/dependency-analysis-gradle-plugin/issues/892
structure {
bundle("kotlin-test") {
includeDependency(libs.kotlin.test)
}
}

project(":pillarbox-core-business") {
onUnusedDependencies {
// This dependency is not used directly, but required to be able to compile `CommandersActStreaming`
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ comscore = "6.10.0"
dependency-analysis-gradle-plugin = "1.29.0"
detekt = "1.23.4"
guava = "31.1-android"
json = "20231013"
junit = "4.13.2"
kotlin = "1.9.22"
kotlinx-coroutines = "1.7.3"
Expand Down Expand Up @@ -57,7 +58,9 @@ androidx-test-runner = { module = "androidx.test:runner", version.ref = "android
androidx-tv-foundation = { module = "androidx.tv:tv-foundation", version.ref = "androidx-tv" }
androidx-tv-material = { module = "androidx.tv:tv-material", version.ref = "androidx-tv" }
coil = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil" }
json = { module = "org.json:json", version.ref = "json" }
MGaetan89 marked this conversation as resolved.
Show resolved Hide resolved
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinx-serialization" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
Expand Down
6 changes: 4 additions & 2 deletions pillarbox-analytics/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ dependencies {
implementation(libs.tagcommander.core)
api(libs.tagcommander.serverside)

testImplementation(libs.json)
testImplementation(libs.junit)
testImplementation(libs.kotlinx.coroutines.core)
testImplementation(libs.kotlinx.coroutines.test)
testImplementation(libs.kotlin.test)
testImplementation(libs.mockk)
testImplementation(libs.mockk.dsl)

androidTestImplementation(libs.androidx.test.monitor)
androidTestRuntimeOnly(libs.androidx.test.runner)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.analytics

import ch.srgssr.pillarbox.analytics.commandersact.CommandersAct
import ch.srgssr.pillarbox.analytics.commandersact.CommandersActEvent
import ch.srgssr.pillarbox.analytics.commandersact.CommandersActPageView
import ch.srgssr.pillarbox.analytics.comscore.ComScore
import ch.srgssr.pillarbox.analytics.comscore.ComScorePageView
import io.mockk.Called
import io.mockk.mockk
import io.mockk.verify
import io.mockk.verifySequence
import kotlin.test.BeforeTest
import kotlin.test.Test

class SRGAnalyticsTest {
private lateinit var comScore: ComScore
private lateinit var commandersAct: CommandersAct
private lateinit var analytics: SRGAnalytics.Analytics

@BeforeTest
fun setup() {
comScore = mockk(relaxed = true)
commandersAct = mockk(relaxed = true)
analytics = SRGAnalytics.Analytics(
comScore = comScore,
commandersAct = commandersAct,
)
}

@Test
fun `sendPageView invokes comScore and commandersAct`() {
val commandersActPageView = CommandersActPageView(
name = "Title",
type = "Type",
levels = listOf("level1", "level2"),
)
val comScorePageView = ComScorePageView("Title")

analytics.sendPageView(
commandersAct = commandersActPageView,
comScore = comScorePageView,
)

verifySequence {
commandersAct.sendPageView(commandersActPageView)
comScore.sendPageView(comScorePageView)
}
}

@Test
fun `sendEvent invokes only commandersAct`() {
val commandersActEvent = CommandersActEvent(name = "name")

analytics.sendEvent(commandersActEvent)

verifySequence {
commandersAct.sendEvent(commandersActEvent)
}
verify(exactly = 0) {
comScore wasNot Called
}
}

@Test
fun `putPersistentLabels invokes comScore and commandersAct`() {
val commandersActLabels = mapOf("key1" to "value1")
val comScoreLabels = mapOf("key2" to "value2")

analytics.putPersistentLabels(
commandersActLabels = commandersActLabels,
comScoreLabels = comScoreLabels,
)

verifySequence {
comScore.putPersistentLabels(comScoreLabels)
commandersAct.putPermanentData(commandersActLabels)
}
}

@Test
fun `removePersistentLabel invokes comScore and commandersAct`() {
val label = "label"

analytics.removePersistentLabel(label = label)

verifySequence {
comScore.removePersistentLabel(label)
commandersAct.removePermanentData(label)
}
}

@Test
fun `getComScorePersistentLabel invokes comScore`() {
val label = "label"

analytics.getComScorePersistentLabel(label = label)

verifySequence {
comScore.getPersistentLabel(label)
}
verify(exactly = 0) {
commandersAct wasNot Called
}
}

@Test
fun `getCommandersActPermanentData invokes commandersAct`() {
val label = "label"

analytics.getCommandersActPermanentData(label = label)

verifySequence {
commandersAct.getPermanentDataLabel(label)
}
verify(exactly = 0) {
comScore wasNot Called
}
}

@Test
fun `setUserConsent invokes comScore and commandersAct`() {
val userConsent = UserConsent()

analytics.setUserConsent(userConsent)

verifySequence {
comScore.setUserConsent(userConsent.comScore)
commandersAct.setConsentServices(userConsent.commandersActConsentServices)
}
}
}
Loading