-
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.
Merge pull request #164 from KUSITMS-29th-TEAM-B/test/flight-163
test: Tag 도메인 테스트 코드 작성(#163)
- Loading branch information
Showing
8 changed files
with
193 additions
and
8 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
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
3 changes: 1 addition & 2 deletions
3
...nggang/domainmodule/domain/tag/TagTest.kt → ...ainmodule/domain/tag/aggregate/TagTest.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
43 changes: 43 additions & 0 deletions
43
...Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/tag/service/TagAppenderTest.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,43 @@ | ||
package com.bamyanggang.domainmodule.domain.tag.service | ||
|
||
import com.bamyanggang.domainmodule.domain.tag.repository.TagRepository | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import java.util.* | ||
|
||
class TagAppenderTest : BehaviorSpec({ | ||
val mockTagRepository = mockk<TagRepository>(relaxed = true) | ||
val tagAppender = TagAppender(mockTagRepository) | ||
|
||
Given("상위 태그 이름과 userId가 주어졌을 때") { | ||
val name = "상위 태그 이름" | ||
val userId = UUID.randomUUID() | ||
|
||
When("appendParentTag를 호출하면") { | ||
val newParentTag = tagAppender.appendParentTag(name, userId) | ||
|
||
Then("tagRepository.save를 호출한다.") { | ||
verify { mockTagRepository.save(newParentTag) } | ||
} | ||
} | ||
} | ||
|
||
Given("하위 태그 이름과 userId, parentTagId가 주어졌을 때") { | ||
val name = "하위 태그 이름" | ||
val userId = UUID.randomUUID() | ||
val parentTagId = UUID.randomUUID() | ||
|
||
When("appendChildTag를 호출하면") { | ||
val newChildTag = tagAppender.appendChildTag( | ||
name = name, | ||
userId = userId, | ||
parentTagId = parentTagId | ||
) | ||
|
||
Then("tagRepository.save를 호출한다.") { | ||
verify { mockTagRepository.save(newChildTag) } | ||
} | ||
} | ||
} | ||
}) |
101 changes: 101 additions & 0 deletions
101
...n-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/tag/service/TagReaderTest.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,101 @@ | ||
package com.bamyanggang.domainmodule.domain.tag.service | ||
|
||
import com.bamyanggang.domainmodule.domain.tag.repository.TagRepository | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import java.util.* | ||
|
||
class TagReaderTest : BehaviorSpec({ | ||
val mockTagRepository = mockk<TagRepository>(relaxed = true) | ||
val tagReader = TagReader(mockTagRepository) | ||
|
||
Given("tagId가 주어졌을 때") { | ||
val tagId = UUID.randomUUID() | ||
|
||
When("tagReader.readById가 호출되면") { | ||
tagReader.readById(tagId) | ||
|
||
Then("tagRepository.findById가 호촐된다.") { | ||
verify { mockTagRepository.findById(tagId) } | ||
} | ||
} | ||
} | ||
|
||
Given("tagId 배열이 주어졌을 때") { | ||
val tagIds = arrayListOf( | ||
UUID.randomUUID(), | ||
UUID.randomUUID() | ||
) | ||
|
||
When("tagReader.readByParentTagIds가 호출되면") { | ||
tagReader.readByParentTagIds(tagIds) | ||
|
||
Then("tagRepository.findByParentTagIds 호촐된다.") { | ||
verify { mockTagRepository.findByParentTagIds(tagIds) } | ||
} | ||
} | ||
} | ||
|
||
Given("userId가 주어졌을 때") { | ||
val userId = UUID.randomUUID() | ||
|
||
When("tagReader.readAllParentTagsByUserId 호출되면") { | ||
tagReader.readAllParentTagsByUserId(userId) | ||
|
||
Then("tagRepository.findAllParentTagsByUserId 호촐된다.") { | ||
verify { mockTagRepository.findAllParentTagsByUserId(userId) } | ||
} | ||
} | ||
} | ||
|
||
Given("userId, parentTagId가 주어졌을 때") { | ||
val userId = UUID.randomUUID() | ||
val parentTagId = UUID.randomUUID() | ||
When("tagReader.readAllChildTagsByUserIdAndParentTagId 호출되면") { | ||
tagReader.readAllChildTagsByUserIdAndParentTagId( | ||
userId = userId, | ||
parentTagId = parentTagId | ||
) | ||
|
||
Then("tagRepository.findAllChildTagsByUserIdAndParentTagId 호촐된다.") { | ||
verify { mockTagRepository.findAllChildTagsByUserIdAndParentTagId( | ||
userId = userId, | ||
parentTagId = parentTagId | ||
) } | ||
} | ||
} | ||
} | ||
|
||
Given("userId, search 검색 문자열이 주어졌을 때") { | ||
val userId = UUID.randomUUID() | ||
val search = "태그 이름 검색 문자열" | ||
When("tagReader.readIdsByUserIdAndNameContains 호출되면") { | ||
tagReader.readIdsByUserIdAndNameContains( | ||
userId = userId, | ||
search = search | ||
) | ||
|
||
Then("tagRepository.findAllChildTagsByUserIdAndParentTagId 호촐된다.") { | ||
verify { mockTagRepository.findByUserIdAndNameContains( | ||
userId = userId, | ||
search = search | ||
) } | ||
} | ||
} | ||
} | ||
|
||
Given("parentTagId가 주어졌을 때") { | ||
val parentTagId = UUID.randomUUID() | ||
|
||
When("tagReader.readChildTagsByParentTagId 호출되면") { | ||
tagReader.readChildTagsByParentTagId(parentTagId = parentTagId) | ||
|
||
Then("tagRepository.findAllChildTagsByParentTagId 호촐된다.") { | ||
verify { mockTagRepository.findAllChildTagsByParentTagId( | ||
parentTagId = parentTagId, | ||
) } | ||
} | ||
} | ||
} | ||
}) |
42 changes: 42 additions & 0 deletions
42
...-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/tag/service/TagRemoverTest.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,42 @@ | ||
package com.bamyanggang.domainmodule.domain.tag.service | ||
|
||
import com.bamyanggang.domainmodule.domain.tag.exception.TagException | ||
import com.bamyanggang.domainmodule.domain.tag.repository.TagRepository | ||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import java.util.* | ||
|
||
class TagRemoverTest : BehaviorSpec({ | ||
val mockTagRepository = mockk<TagRepository>(relaxed = true) | ||
val tagRemover = TagRemover(mockTagRepository) | ||
|
||
Given("삭제할 태그 Id가 주어졌을 때") { | ||
val deleteTagId = UUID.randomUUID() | ||
|
||
When("removeTag가 호출되면") { | ||
every { mockTagRepository.isExistById(deleteTagId) } returns true | ||
tagRemover.removeTag(deleteTagId) | ||
|
||
Then("tagRepository.deleteById가 호출된다.") { | ||
verify { mockTagRepository.deleteByTagId(deleteTagId) } | ||
} | ||
} | ||
} | ||
|
||
Given("존재하지 않는 태그 Id가 주어졌을 때") { | ||
val notExistTagId = UUID.randomUUID() | ||
|
||
When("removeTag가 호출되면") { | ||
val exception = shouldThrow<TagException.NotFoundTag> { | ||
tagRemover.removeTag(notExistTagId) | ||
} | ||
|
||
Then("TagException.NotFoundTag 예외가 발생한다.") { | ||
assert(exception.message == TagException.NotFoundTag().message) | ||
} | ||
} | ||
} | ||
}) |