-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: News plain text field 추가 (#80)
* Feat: Add plainTextDescription field for news entity * Feat: Add to create, and update plainTextDescription. * Feat: Change to use plainTextDescription when making newssearchdto. * Test: Test for create/update plainTextDescription.
- Loading branch information
Showing
3 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/test/kotlin/com/wafflestudio/csereal/core/notice/news/NewsServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} | ||
} | ||
} | ||
} | ||
} |