Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -585,7 +585,7 @@ internal class DomainMapping(
authorName = author_name,
authorLink = author_link,
fallback = fallback,
fileSize = file_size,
fileSize = file_size ?: 0,
image = image,
imageUrl = image_url,
mimeType = mime_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal data class AttachmentDto(
val author_name: String?,
val author_link: String?,
val fallback: String?,
val file_size: Int = 0,
val file_size: Int?,
val image: String?,
val image_url: String?,
val mime_type: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ internal object Mother {
authorName: String? = randomString(),
authorLink: String? = randomString(),
fallback: String? = randomString(),
fileSize: Int = positiveRandomInt(),
fileSize: Int? = positiveRandomInt(),
image: String? = randomString(),
imageUrl: String? = randomString(),
mimeType: String? = randomString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ internal class DomainMappingTest {
authorName = attachmentDto.author_name,
authorLink = attachmentDto.author_link,
fallback = attachmentDto.fallback,
fileSize = attachmentDto.file_size,
fileSize = attachmentDto.file_size ?: 0,
Comment thread
andremion marked this conversation as resolved.
image = attachmentDto.image,
imageUrl = attachmentDto.image_url,
mimeType = attachmentDto.mime_type,
Expand All @@ -576,6 +576,16 @@ internal class DomainMappingTest {
assertEquals(expected, attachment)
}

@Test
fun `AttachmentDto with null file_size falls back to 0`() {
val attachmentDto = randomAttachmentDto(fileSize = null)
val sut = Fixture().get()
val attachment = with(sut) {
attachmentDto.toDomain()
}
assertEquals(0, attachment.fileSize)
}

@Test
fun `BannedUserResponse is correctly mapped to BannedUser`() {
val bannedUserResponse = randomBannedUserResponse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ internal class AttachmentDtoAdapterTest {
val jsonString = parser.toJson(AttachmentDtoTestData.attachmentWithoutExtraData)
jsonString.shouldEqualJson(AttachmentDtoTestData.jsonWithoutExtraData)
}

@Test
fun `Deserialize JSON attachment with null file_size`() {
val attachment = parser.fromJson(AttachmentDtoTestData.jsonWithNullFileSize, AttachmentDto::class.java)
attachment shouldBeEqualTo AttachmentDtoTestData.attachmentWithNullFileSize
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,33 @@ internal object AttachmentDtoTestData {
extraData = mapOf("draft" to true),
)

@Language("JSON")
val jsonWithNullFileSize =
"""{
"file_size": null
}
""".withoutWhitespace()
val attachmentWithNullFileSize = AttachmentDto(
asset_url = null,
author_name = null,
author_link = null,
fallback = null,
file_size = null,
image = null,
image_url = null,
mime_type = null,
name = null,
og_scrape_url = null,
text = null,
thumb_url = null,
title = null,
title_link = null,
type = null,
original_width = null,
original_height = null,
extraData = emptyMap(),
)

@Language("JSON")
val jsonWithoutExtraData =
"""{
Expand Down
Loading