-
Notifications
You must be signed in to change notification settings - Fork 0
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 #58 from MEOGO-DSM/57-bookmark-test
🏄 :: (Meogo-57) bookmark test
- Loading branch information
Showing
8 changed files
with
239 additions
and
40 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.meogo | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.test.context.ActiveProfiles | ||
|
||
@SpringBootTest | ||
@ActiveProfiles("test") | ||
class MeogoBackendApplicationTests { | ||
|
||
@Test | ||
fun contextLoads() { | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
src/test/kotlin/org/meogo/domain/bookmark/service/BookmarkServiceTest.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,114 @@ | ||
package org.meogo.domain.bookmark.service | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.meogo.domain.bookmark.domain.Bookmark | ||
import org.meogo.domain.bookmark.domain.BookmarkRepository | ||
import org.meogo.domain.bookmark.exception.BookmarkNotFoundException | ||
import org.meogo.domain.user.domain.User | ||
import org.meogo.domain.user.domain.UserRole | ||
import org.meogo.domain.user.facade.UserFacade | ||
import org.mockito.InjectMocks | ||
import org.mockito.Mock | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.verify | ||
import org.mockito.kotlin.whenever | ||
import org.springframework.test.context.ActiveProfiles | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
@ActiveProfiles("test") | ||
class BookmarkServiceTest { | ||
|
||
@Mock | ||
private lateinit var bookmarkRepository: BookmarkRepository | ||
|
||
@Mock | ||
private lateinit var userFacade: UserFacade | ||
|
||
@InjectMocks | ||
private lateinit var bookmarkService: BookmarkService | ||
|
||
private lateinit var user: User | ||
private val schoolId = 123 | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
user = User( | ||
name = "test", | ||
accountId = "test", | ||
password = "password", | ||
role = UserRole.USER, | ||
profile = "default" | ||
) | ||
|
||
whenever(userFacade.currentUser()).thenReturn(user) | ||
} | ||
|
||
@Test | ||
fun `북마크 저장`() { | ||
// given & when | ||
bookmarkService.execute(schoolId) | ||
|
||
// then | ||
verify(bookmarkRepository).save(any()) | ||
} | ||
|
||
@Test | ||
fun `북마크 리스트 조회`() { | ||
// given | ||
val bookmark1 = Bookmark(schoolId = 1, user = user) | ||
val bookmark2 = Bookmark(schoolId = 2, user = user) | ||
|
||
whenever(bookmarkRepository.findAllByUser(user)).thenReturn(listOf(bookmark1, bookmark2)) | ||
|
||
// when | ||
val bookmarkedSchools = bookmarkService.queryBookmarkedSchool() | ||
|
||
// then | ||
assertEquals(2, bookmarkedSchools.size) | ||
assertEquals(1, bookmarkedSchools[0]) | ||
assertEquals(2, bookmarkedSchools[1]) | ||
} | ||
|
||
@Test | ||
fun `북마크 여부 확인`() { | ||
// given | ||
val bookmark = Bookmark(schoolId = schoolId, user = user) | ||
whenever(bookmarkRepository.existsBySchoolIdAndUser(bookmark.schoolId, bookmark.user)).thenReturn(true) | ||
|
||
// when | ||
val isBookmarked = bookmarkService.queryIsBookmarked(schoolId) | ||
|
||
// then | ||
assertEquals(true, isBookmarked) | ||
} | ||
|
||
@Test | ||
fun `북마크 삭제 성공`() { | ||
// given | ||
val bookmark = Bookmark(schoolId = schoolId, user = user) | ||
|
||
whenever(bookmarkRepository.findBySchoolIdAndUser(schoolId, user)).thenReturn(bookmark) | ||
|
||
// when | ||
bookmarkService.deleteBookmark(schoolId) | ||
|
||
// then | ||
verify(bookmarkRepository).delete(bookmark) | ||
} | ||
|
||
@Test | ||
fun `북마크 삭제 실패`() { | ||
// given | ||
whenever(bookmarkRepository.findBySchoolIdAndUser(schoolId, user)).thenReturn(null) | ||
|
||
// when & then | ||
assertThrows<BookmarkNotFoundException> { | ||
bookmarkService.deleteBookmark(schoolId) | ||
} | ||
} | ||
} |
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,56 @@ | ||
spring: | ||
config: | ||
activate: | ||
on-profile: test | ||
datasource: | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
url: ${DB_URL} | ||
username: ${DB_USERNAME} | ||
password: ${DB_PASSWORD} | ||
hikari: | ||
maxLifetime: 580000 | ||
jpa: | ||
hibernate: | ||
ddl-auto: update | ||
show-sql: true | ||
properties: | ||
hibernate: | ||
format_sql: true | ||
open-in-view: false | ||
database: mysql | ||
|
||
jackson: | ||
property-naming-strategy: SNAKE_CASE | ||
|
||
auth: | ||
jwt: | ||
secretKey: ${SECRET_KEY} | ||
accessExp: ${ACCESS_EXP} | ||
refreshExp: ${REFRESH_EXP} | ||
header: "Authorization" | ||
prefix: "Bearer " | ||
|
||
cloud: | ||
aws: | ||
credentials: | ||
access-key: ${AWS_ACCESS_KEY} | ||
secret-key: ${AWS_SECRET_KEY} | ||
s3: | ||
default-image: ${DEFAULT_IMAGE} | ||
bucket: ${S3_BUCKET} | ||
region: | ||
static: ap-northeast-2 | ||
stack: | ||
auto: false | ||
|
||
firebase: | ||
url: ${FCM_URL} | ||
|
||
url: | ||
career: ${CAREER_URL} | ||
|
||
open-feign: | ||
career-key: ${CAREER_KEY} | ||
|
||
server: | ||
port: 8989 |