Skip to content

Commit

Permalink
Test: Test for create/update plainTextDescription.
Browse files Browse the repository at this point in the history
  • Loading branch information
huGgW committed Sep 8, 2023
1 parent 3b23113 commit ae0d7e1
Showing 1 changed file with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.wafflestudio.csereal.core.notice.news

import com.wafflestudio.csereal.core.news.database.NewsEntity
import com.wafflestudio.csereal.core.news.database.NewsRepository
import com.wafflestudio.csereal.core.news.dto.NewsDto
import com.wafflestudio.csereal.core.news.service.NewsService
import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.data.repository.findByIdOrNull

@SpringBootTest
class NewsServiceTest(
private val newsService: NewsService,
private val newsRepository: NewsRepository,
) : BehaviorSpec() {
init {

afterSpec {
newsRepository.deleteAll()
}

Given("뉴스를 생성하려고 할 때 간단한 뉴스가 주어지면") {
val newsDTO = NewsDto(
id = -1,
title = "title",
description = """
<h1>Hello, World!</h1>
<p>This is news description.</p>
<h3>Goodbye, World!</h3>
""".trimIndent(),
tags = emptyList(),
createdAt = null,
modifiedAt = null,
isPublic = false,
isSlide = false,
isImportant = false,
prevId = null,
prevTitle = null,
nextId = null,
nextTitle = null,
imageURL = null,
attachments = null,
)

When("DTO를 이용하여 뉴스를 생성하면") {
val createdNewsDTO = newsService.createNews(newsDTO, null, null)

Then("뉴스가 생성되어야 한다.") {
newsRepository.count() shouldBe 1
newsRepository.findByIdOrNull(createdNewsDTO.id) shouldNotBe null
}

Then("plainTextDescription이 생성되었어야 한다.") {
val createdNewsEntity = newsRepository.findByIdOrNull(createdNewsDTO.id)!!
createdNewsEntity.plainTextDescription shouldBe "Hello, World! This is news description. Goodbye, World!"
}
}
}

Given("간단한 뉴스가 저장되어 있을 때") {
val newsEntity = newsRepository.save(
NewsEntity(
title = "title",
description = """
<h1>Hello, World!</h1>
<p>This is news description.</p>
<h3>Goodbye, World!</h3>
""".trimIndent(),
plainTextDescription = "Hello, World! This is news description. Goodbye, World!",
isPublic = false,
isSlide = false,
isImportant = false,
)
)

When("저장된 뉴스의 Description을 수정하면") {
newsService.updateNews(
newsEntity.id,
NewsDto.of(newsEntity, null, emptyList(), null)
.copy(description = """
<h1>Hello, World!</h1>
<p>This is modified news description.</p>
<h3>Goodbye, World!</h3>
<p>This is additional description.</p>
""".trimIndent()
),
null,
null
)

Then("description, plainTextDescription이 수정되어야 한다.") {
val updatedNewsEntity = newsRepository.findByIdOrNull(newsEntity.id)!!
updatedNewsEntity.description shouldBe """
<h1>Hello, World!</h1>
<p>This is modified news description.</p>
<h3>Goodbye, World!</h3>
<p>This is additional description.</p>
""".trimIndent()
updatedNewsEntity.plainTextDescription shouldBe "Hello, World! This is modified news description. Goodbye, World! This is additional description."
}
}
}
}
}

0 comments on commit ae0d7e1

Please sign in to comment.