Skip to content

Commit 46a9f5b

Browse files
committed
refactor: (#962) EventHandler 테스트에서 publishMessage 관련 테스트 제거
1 parent 2599c2b commit 46a9f5b

File tree

2 files changed

+2
-139
lines changed

2 files changed

+2
-139
lines changed

dms-main/main-infrastructure/src/test/kotlin/team/aliens/dms/event/handler/DeviceTokenEventHandlerTest.kt

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package team.aliens.dms.event.handler
33
import com.fasterxml.jackson.databind.ObjectMapper
44
import io.kotest.core.spec.IsolationMode
55
import io.kotest.core.spec.style.DescribeSpec
6-
import io.mockk.Runs
76
import io.mockk.every
8-
import io.mockk.just
97
import io.mockk.mockk
108
import io.mockk.verify
119
import team.aliens.dms.common.dto.OutboxData
@@ -14,17 +12,15 @@ import team.aliens.dms.common.spi.OutboxPort
1412
import team.aliens.dms.contract.model.notification.DeviceTokenInfo
1513
import team.aliens.dms.contract.remote.rabbitmq.SaveDeviceTokenMessage
1614
import team.aliens.dms.event.SaveDeviceTokenEvent
17-
import team.aliens.dms.thirdparty.messagebroker.NotificationProducer
1815
import java.util.UUID
1916

2017
class DeviceTokenEventHandlerTest : DescribeSpec({
2118

2219
isolationMode = IsolationMode.InstancePerLeaf
2320

2421
val outboxPort = mockk<OutboxPort>()
25-
val notificationProducer = mockk<NotificationProducer>()
2622
val objectMapper = ObjectMapper()
27-
val deviceTokenEventHandler = DeviceTokenEventHandler(outboxPort, notificationProducer, objectMapper)
23+
val deviceTokenEventHandler = DeviceTokenEventHandler(outboxPort, objectMapper)
2824

2925
describe("saveOutbox") {
3026
context("SaveDeviceTokenEvent가 발생하면") {
@@ -61,68 +57,4 @@ class DeviceTokenEventHandlerTest : DescribeSpec({
6157
}
6258
}
6359
}
64-
65-
describe("publishMessage") {
66-
context("메시지 전송에 성공하면") {
67-
val userId = UUID.randomUUID()
68-
val deviceTokenInfo = DeviceTokenInfo(
69-
userId = userId,
70-
schoolId = UUID.randomUUID(),
71-
token = "test-fcm-token"
72-
)
73-
val event = SaveDeviceTokenEvent(deviceTokenInfo = deviceTokenInfo)
74-
val outboxId = UUID.randomUUID()
75-
val savedOutbox = OutboxData(
76-
id = outboxId,
77-
aggregateType = "device_token",
78-
79-
eventType = "SaveDeviceTokenMessage",
80-
payload = objectMapper.writeValueAsString(SaveDeviceTokenMessage(deviceTokenInfo)),
81-
status = OutboxStatus.PENDING,
82-
retryCount = 0
83-
)
84-
85-
every { outboxPort.save(any()) } returns savedOutbox
86-
every { notificationProducer.sendMessage(any()) } just Runs
87-
every { outboxPort.deleteById(outboxId) } just Runs
88-
89-
it("메시지를 전송하고 Outbox를 삭제한다") {
90-
deviceTokenEventHandler.saveOutbox(event)
91-
deviceTokenEventHandler.publishMessage(event)
92-
93-
verify { notificationProducer.sendMessage(any()) }
94-
verify { outboxPort.deleteById(outboxId) }
95-
}
96-
}
97-
98-
context("메시지 전송에 실패하면") {
99-
val userId = UUID.randomUUID()
100-
val deviceTokenInfo = DeviceTokenInfo(
101-
userId = userId,
102-
schoolId = UUID.randomUUID(),
103-
token = "test-fcm-token"
104-
)
105-
val event = SaveDeviceTokenEvent(deviceTokenInfo = deviceTokenInfo)
106-
val outboxId = UUID.randomUUID()
107-
val savedOutbox = OutboxData(
108-
id = outboxId,
109-
aggregateType = "device_token",
110-
eventType = "SaveDeviceTokenMessage",
111-
payload = objectMapper.writeValueAsString(SaveDeviceTokenMessage(deviceTokenInfo)),
112-
status = OutboxStatus.PENDING,
113-
retryCount = 0
114-
)
115-
116-
every { outboxPort.save(any()) } returns savedOutbox
117-
every { notificationProducer.sendMessage(any()) } throws RuntimeException("Send failed")
118-
119-
it("Outbox를 삭제하지 않고 스케줄러가 재시도하도록 남겨둔다") {
120-
deviceTokenEventHandler.saveOutbox(event)
121-
deviceTokenEventHandler.publishMessage(event)
122-
123-
verify { notificationProducer.sendMessage(any()) }
124-
verify(exactly = 0) { outboxPort.deleteById(any()) }
125-
}
126-
}
127-
}
12860
})

dms-main/main-infrastructure/src/test/kotlin/team/aliens/dms/event/handler/NotificationEventHandlerTest.kt

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
44
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
55
import io.kotest.core.spec.IsolationMode
66
import io.kotest.core.spec.style.DescribeSpec
7-
import io.mockk.Runs
87
import io.mockk.every
9-
import io.mockk.just
108
import io.mockk.mockk
119
import io.mockk.verify
1210
import team.aliens.dms.common.dto.OutboxData
@@ -15,17 +13,15 @@ import team.aliens.dms.common.spi.OutboxPort
1513
import team.aliens.dms.contract.model.notification.NotificationInfo
1614
import team.aliens.dms.contract.remote.rabbitmq.SingleNotificationMessage
1715
import team.aliens.dms.event.SingleNotificationEvent
18-
import team.aliens.dms.thirdparty.messagebroker.NotificationProducer
1916
import java.util.UUID
2017

2118
class NotificationEventHandlerTest : DescribeSpec({
2219

2320
isolationMode = IsolationMode.InstancePerLeaf
2421

2522
val outboxPort = mockk<OutboxPort>()
26-
val notificationProducer = mockk<NotificationProducer>()
2723
val objectMapper = ObjectMapper().registerModule(JavaTimeModule())
28-
val notificationEventHandler = NotificationEventHandler(outboxPort, notificationProducer, objectMapper)
24+
val notificationEventHandler = NotificationEventHandler(outboxPort, objectMapper)
2925

3026
describe("saveOutbox") {
3127
context("SingleNotificationEvent가 발생하면") {
@@ -63,69 +59,4 @@ class NotificationEventHandlerTest : DescribeSpec({
6359
}
6460
}
6561
}
66-
67-
describe("publishMessage") {
68-
context("메시지 전송에 성공하면") {
69-
val userId = UUID.randomUUID()
70-
val notificationInfo = mockk<NotificationInfo>(relaxed = true)
71-
val event = SingleNotificationEvent(
72-
userId = userId,
73-
notificationInfo = notificationInfo
74-
)
75-
val outboxId = UUID.randomUUID()
76-
val savedOutbox = OutboxData(
77-
id = outboxId,
78-
aggregateType = "notification",
79-
eventType = SingleNotificationMessage.TYPE,
80-
payload = objectMapper.writeValueAsString(
81-
SingleNotificationMessage(userId, notificationInfo)
82-
),
83-
status = OutboxStatus.PENDING,
84-
retryCount = 0
85-
)
86-
87-
every { outboxPort.save(any()) } returns savedOutbox
88-
every { notificationProducer.sendMessage(any()) } just Runs
89-
every { outboxPort.deleteById(outboxId) } just Runs
90-
91-
it("메시지를 전송하고 Outbox를 삭제한다") {
92-
notificationEventHandler.saveOutbox(event)
93-
notificationEventHandler.publishMessage(event)
94-
95-
verify { notificationProducer.sendMessage(any()) }
96-
verify { outboxPort.deleteById(outboxId) }
97-
}
98-
}
99-
100-
context("메시지 전송에 실패하면") {
101-
val userId = UUID.randomUUID()
102-
val notificationInfo = mockk<NotificationInfo>(relaxed = true)
103-
val event = SingleNotificationEvent(
104-
userId = userId,
105-
notificationInfo = notificationInfo
106-
)
107-
val outboxId = UUID.randomUUID()
108-
val savedOutbox = OutboxData(
109-
id = outboxId,
110-
aggregateType = "notification",
111-
eventType = SingleNotificationMessage.TYPE,
112-
payload = objectMapper.writeValueAsString(
113-
SingleNotificationMessage(userId, notificationInfo)
114-
),
115-
status = OutboxStatus.PENDING,
116-
retryCount = 0
117-
)
118-
119-
every { outboxPort.save(any()) } returns savedOutbox
120-
every { notificationProducer.sendMessage(any()) } throws RuntimeException("Send failed")
121-
122-
it("Outbox를 삭제하지 않고 스케줄러가 재시도하도록 남겨둔다") {
123-
notificationEventHandler.saveOutbox(event)
124-
notificationEventHandler.publishMessage(event)
125-
126-
verify { notificationProducer.sendMessage(any()) }
127-
verify(exactly = 0) { outboxPort.deleteById(any()) }
128-
}
129-
}
130-
}
13162
})

0 commit comments

Comments
 (0)