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

fix #59 removed video description nullability #134

Merged
merged 8 commits into from
Nov 9, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ class VideoSectionDocumentToVideoSectionMapper @Inject constructor(
val jsonMap = document.data

val videoTitle = localizedMapReader.get(key = "title", jsonMap = jsonMap)
val videoDescription = localizedMapReader.get(key = "description", jsonMap = jsonMap)
val youtubeId = document.get("youtubeId") as? String
return if (videoTitle != null && youtubeId != null) {
return if (videoTitle != null && youtubeId != null && videoDescription != null) {
Video(
title = videoTitle,
description = localizedMapReader.get(key = "description", jsonMap = jsonMap),
description = videoDescription,
orderIndex = document.get("orderIndex") as? Int ?: 0,
youtubeId = youtubeId
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class VideoSectionDocumentToVideoSectionMapperTest {
private val mapper = VideoSectionDocumentToVideoSectionMapper(localizedMapReader)

@Test
fun `it should return null if title or description is missing`() = runTest {
fun `it should return null if title and description is missing`() = runTest {
// given
val document: DocumentSnapshot = mockk()
every { document.data } returns null
Expand All @@ -29,6 +29,21 @@ class VideoSectionDocumentToVideoSectionMapperTest {
assertThat(result).isNull()
}

@Test
fun `it should return null if description is missing`() = runTest {
// given
val document: DocumentSnapshot = mockk()
every { document.data } returns null
every { localizedMapReader.get("title", null) } returns "title"
every { localizedMapReader.get("description", null) } returns null

// when
val result = mapper.map(document)

// then
assertThat(result).isNull()
}

@Test
fun `it should return null if no videos found`() = runTest {
// given
Expand Down Expand Up @@ -101,7 +116,12 @@ class VideoSectionDocumentToVideoSectionMapperTest {
}
}
every { localizedMapReader.get("title", videoSectionJsonMap) } returns "Test Title"
every { localizedMapReader.get("description", videoSectionJsonMap) } returns "Test Description"
every {
localizedMapReader.get(
"description",
videoSectionJsonMap
)
} returns "Test Description"

// when
val result = requireNotNull(mapper.map(document))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,13 @@ fun VideoScreen(
.testIdentifier(VideoScreenTestIdentifier.VIDEO_PLAYER)
)

video.description?.let {
Text(
text = it,
style = TextStyles.bodyMedium,
modifier = Modifier
.padding(Spacings.medium)
.testIdentifier(VideoScreenTestIdentifier.VIDEO_DESCRIPTION)
)
}
Text(
text = video.description,
style = TextStyles.bodyMedium,
modifier = Modifier
.padding(Spacings.medium)
.testIdentifier(VideoScreenTestIdentifier.VIDEO_DESCRIPTION)
)
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data class VideoSection(
@Serializable
data class Video(
val title: String,
val description: String? = null,
val description: String,
val orderIndex: Int = 0,
val youtubeId: String,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class EducationViewModelTest {
Video(
youtubeId = youtubeId,
title = title,
description = "description",
)
)
)
Expand All @@ -65,7 +66,8 @@ class EducationViewModelTest {
Action.VideoSectionClicked(
video = Video(
youtubeId = youtubeId,
title = title
title = title,
description = "description",
)
)
)
Expand All @@ -76,7 +78,8 @@ class EducationViewModelTest {
EducationNavigationEvent.VideoSectionClicked(
video = Video(
youtubeId = youtubeId,
title = title
title = title,
description = "description",
)
)
)
Expand Down
Loading