This repository was archived by the owner on Jul 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageCommandServiceTest.kt
More file actions
94 lines (88 loc) · 3.48 KB
/
ImageCommandServiceTest.kt
File metadata and controls
94 lines (88 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.asap.application.image.service
import com.asap.application.image.port.`in`.UploadImageUsecase
import com.asap.application.image.port.out.ImageManagementPort
import com.asap.application.image.vo.UploadedImage
import com.asap.application.user.port.out.UserManagementPort
import com.asap.common.file.FileMetaData
import com.asap.domain.UserFixture
import io.kotest.core.spec.IsolationMode
import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.matchers.nulls.shouldNotBeNull
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import java.io.InputStream
class ImageCommandServiceTest :
BehaviorSpec({
isolationMode = IsolationMode.InstancePerLeaf
val mockImageManagementPort = mockk<ImageManagementPort>(relaxed = true)
val mockUserManagementPort = mockk<UserManagementPort>(relaxed = true)
val imageCommandService =
ImageCommandService(
mockImageManagementPort,
mockUserManagementPort,
)
given("이미지 업로드 요청이 들어올 때") {
val mockUser = UserFixture.createUser()
val command =
UploadImageUsecase.Command(
userId = mockUser.id.value,
image =
FileMetaData(
name = "name",
contentType = "contentType",
size = 1L,
inputStream = InputStream.nullInputStream(),
),
)
every {
mockUserManagementPort.getUserNotNull(any())
} returns mockUser
every {
mockImageManagementPort.save(any())
} returns
UploadedImage(
imageUrl = "imageUrl",
)
`when`("이미지 업로드 요청을 처리하면") {
val response = imageCommandService.upload(command)
then("이미지가 저장되어야 한다") {
response.imageUrl shouldNotBeNull {
this.isNotBlank()
this.isNotEmpty()
}
}
}
}
given("userId가 null인 이미지 업로드 요청이 들어올 때") {
val command =
UploadImageUsecase.Command(
userId = null,
image =
FileMetaData(
name = "name",
contentType = "contentType",
size = 1L,
inputStream = InputStream.nullInputStream(),
),
)
every {
mockImageManagementPort.save(any())
} returns
UploadedImage(
imageUrl = "imageUrl",
)
`when`("이미지 업로드 요청을 처리하면") {
val response = imageCommandService.upload(command)
then("getUserNotNull 메서드가 호출되지 않아야 한다") {
verify(exactly = 0) { mockUserManagementPort.getUserNotNull(any()) }
}
then("이미지가 저장되어야 한다") {
response.imageUrl shouldNotBeNull {
this.isNotBlank()
this.isNotEmpty()
}
}
}
}
})