-
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.
- Loading branch information
Showing
1 changed file
with
19 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,11 @@ import io.sakurasou.exception.service.album.AlbumUpdateFailedException | |
import io.sakurasou.model.DatabaseSingleton | ||
import io.sakurasou.model.dao.album.AlbumDao | ||
import io.sakurasou.model.dao.image.ImageDao | ||
import io.sakurasou.model.dao.user.UserDao | ||
import io.sakurasou.model.dto.AlbumInsertDTO | ||
import io.sakurasou.model.dto.AlbumUpdateDTO | ||
import io.sakurasou.model.entity.Album | ||
import io.sakurasou.model.entity.User | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.datetime.* | ||
import kotlin.test.BeforeTest | ||
|
@@ -26,6 +28,7 @@ import kotlin.test.assertFailsWith | |
* 2024/9/13 21:47 | ||
*/ | ||
class AlbumServiceTest { | ||
private lateinit var userDao: UserDao | ||
private lateinit var albumDao: AlbumDao | ||
private lateinit var imageDao: ImageDao | ||
private lateinit var albumService: AlbumServiceImpl | ||
|
@@ -36,9 +39,10 @@ class AlbumServiceTest { | |
fun setUp() { | ||
mockkObject(DatabaseSingleton) | ||
mockkObject(Clock.System) | ||
userDao = mockk() | ||
albumDao = mockk() | ||
imageDao = mockk() | ||
albumService = AlbumServiceImpl(albumDao, imageDao) | ||
albumService = AlbumServiceImpl(userDao, albumDao, imageDao) | ||
instant = Clock.System.now() | ||
every { Clock.System.now() } returns instant | ||
now = instant.toLocalDateTime(TimeZone.currentSystemDefault()) | ||
|
@@ -205,18 +209,32 @@ class AlbumServiceTest { | |
isUncategorized = false, | ||
createTime = now | ||
) | ||
val user = User( | ||
id = userId, | ||
name = "testUser", | ||
password = "testPassword", | ||
email = "[email protected]", | ||
groupId = 1, | ||
isDefaultImagePrivate = true, | ||
defaultAlbumId = albumId, | ||
isBanned = false, | ||
createTime = now, | ||
updateTime = now | ||
) | ||
val expected = AlbumVO( | ||
id = albumId, | ||
name = "My Album", | ||
description = "Test Album", | ||
imageCount = 0, | ||
isUncategorized = false, | ||
isDefault = true, | ||
createTime = album.createTime | ||
) | ||
|
||
coEvery { DatabaseSingleton.dbQuery<AlbumVO>(any()) } coAnswers { | ||
this.arg<suspend () -> AlbumVO>(0).invoke() | ||
} | ||
every { userDao.findUserById(userId) } returns user | ||
every { albumDao.findAlbumById(albumId) } returns album | ||
every { imageDao.countImageByAlbumId(albumId) } returns 0 | ||
|
||
|