Add more tests

This commit is contained in:
Wieland Schöbl
2021-05-29 12:36:41 +02:00
parent 68ed19db7a
commit 163b201828
7 changed files with 176 additions and 41 deletions

View File

@@ -41,7 +41,7 @@ class EmbedBuilderBuilder {
fun title(builder: TitleBuilderBuilder.() -> Unit) =
TitleBuilderBuilder().apply { builder() }.let {
_embed.setTitle(it.title, it.url)
_embed.setTitle(it.value, it.url)
}
fun footer(builder: FooterBuilderBuilder.() -> Unit) =
@@ -57,7 +57,7 @@ class FieldBuilderBuilder {
}
class TitleBuilderBuilder {
var title: String? = null
var value: String? = null
var url: String? = null
}

View File

@@ -15,7 +15,7 @@ data class BlogPostPreview(
) {
fun toMessageEmbed() = embed {
title {
title = this@BlogPostPreview.title
value = this@BlogPostPreview.title
url = fullPostUrl
}
description = this@BlogPostPreview.description

View File

@@ -2,8 +2,7 @@ package org.hmcore.model
import org.hmcore.extensions.hex2Rgb
import kotlinx.serialization.Serializable
import net.dv8tion.jda.api.EmbedBuilder
import net.dv8tion.jda.api.entities.MessageEmbed
import org.hmcore.extensions.embed
@Serializable
data class JobListingPreview(
@@ -12,12 +11,16 @@ data class JobListingPreview(
val location: String,
val fullListingUrl: String
) {
fun toMessageEmbed(): MessageEmbed {
return EmbedBuilder()
.setTitle(this.title, this.fullListingUrl)
.setDescription(this.department)
.setAuthor(this.location)
.setColor(hex2Rgb("#337fb0"))
.build()
fun toMessageEmbed() = embed {
title {
value = this@JobListingPreview.title
url = fullListingUrl
}
description = department
color = hex2Rgb("#337fb0")
author {
name = location
}
}
}

View File

@@ -10,7 +10,7 @@ class EmbedTest {
fun `Embed Title DSL should work`() {
val dslEmbed = embed {
title {
title = "Title"
value = "Title"
url = "https://a.b.c"
}
}

View File

@@ -0,0 +1,34 @@
package org.hmcore.model
import org.hmcore.extensions.hex2Rgb
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
class BlogPostPreviewTest {
@Test
fun `Blog post should be correctly parsed to Embed`() {
val embed = BlogPostPreview(
title = "Title",
description = "Description",
date = "01.01.2000",
author = "Nobody",
imgUrl = "https://a.b.c",
fullPostUrl = "https://d.e.f"
).toMessageEmbed()
assertEquals("Title", embed.title)
assertEquals("https://d.e.f", embed.url)
assertEquals("Description", embed.description)
assertEquals(hex2Rgb("#337FB0"), embed.color)
assertNotNull(embed.thumbnail)
assertEquals("https://a.b.c", embed.thumbnail!!.url)
assertNotNull(embed.footer)
assertEquals("01.01.2000", embed.footer!!.text)
assertEquals("https://www.hytale.com/static/images/logo-h.png", embed.footer!!.iconUrl)
assertNotNull(embed.author)
assertEquals(embed.author!!.name, "Nobody")
}
}

View File

@@ -0,0 +1,26 @@
package org.hmcore.model
import org.hmcore.extensions.hex2Rgb
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
class JobListingPreviewTest {
@Test
fun `Job listings should be correctly parsed to Embed`() {
val embed = JobListingPreview(
title = "Title",
department = "Department",
location = "Null Island",
fullListingUrl = "https://d.e.f"
).toMessageEmbed()
assertEquals("Title", embed.title)
assertEquals("https://d.e.f", embed.url)
assertEquals("Department", embed.description)
assertEquals(hex2Rgb("#337FB0"), embed.color)
assertNotNull(embed.author)
assertEquals(embed.author!!.name, "Null Island")
}
}