@@ -10,11 +10,11 @@ import Foundation
1010import Testing
1111import DevLogCore
1212import DevLogDomain
13- @testable import DevLogData
13+ @testable @ preconcurrency import DevLogData
1414
1515struct TodoRepositoryImplTests {
16- @Test ( " Todo 변경 성공 시 위젯 동기화 이벤트를 발행한다 " )
17- func todo_변경_성공_시_위젯_동기화_이벤트를_발행한다 ( ) async throws {
16+ @Test ( " Todo 변경 성공 시 위젯 동기화와 mutation 이벤트를 발행한다 " )
17+ func todo_변경_성공_시_위젯_동기화와_mutation_이벤트를_발행한다 ( ) async throws {
1818 let fixture = makeFixture ( )
1919 let todo = makeTodo ( )
2020
@@ -24,10 +24,13 @@ struct TodoRepositoryImplTests {
2424
2525 let events = fixture. widgetSyncEventBus. events
2626 #expect( events == [ . syncRequested, . syncRequested, . syncRequested] )
27+
28+ let mutationEvents = await fixture. todoMutationEventBus. publishedEvents ( )
29+ #expect( mutationEvents == [ . updated( todo. id) , . deleted( todo. id) , . restored( todo. id) ] )
2730 }
2831
29- @Test ( " Todo 변경 실패 시 위젯 동기화 이벤트를 발행하지 않는다 " )
30- func todo_변경_실패_시_위젯_동기화_이벤트를_발행하지_않는다 ( ) async throws {
32+ @Test ( " Todo 변경 실패 시 위젯 동기화와 mutation 이벤트를 발행하지 않는다 " )
33+ func todo_변경_실패_시_위젯_동기화와_mutation_이벤트를_발행하지_않는다 ( ) async throws {
3134 let fixture = makeFixture ( )
3235 let todo = makeTodo ( )
3336
@@ -52,24 +55,30 @@ struct TodoRepositoryImplTests {
5255 #expect( error as? TodoRepositoryImplTestsError == . serviceFailed)
5356 }
5457
55- let events = fixture. widgetSyncEventBus. events
56- #expect( events. isEmpty)
58+ let syncEvents = fixture. widgetSyncEventBus. events
59+ #expect( syncEvents. isEmpty)
60+
61+ let mutationEvents = await fixture. todoMutationEventBus. publishedEvents ( )
62+ #expect( mutationEvents. isEmpty)
5763 }
5864
5965 private func makeFixture( ) -> Fixture {
6066 let todoService = TodoServiceSpy ( )
6167 let todoCategoryService = TodoCategoryServiceSpy ( )
6268 let widgetSyncEventBus = WidgetSyncEventBusSpy ( )
69+ let todoMutationEventBus = TodoMutationEventBusSpy ( )
6370 let repository = TodoRepositoryImpl (
6471 todoService: todoService,
6572 todoCategoryService: todoCategoryService,
66- widgetSyncEventBus: widgetSyncEventBus
73+ widgetSyncEventBus: widgetSyncEventBus,
74+ todoMutationEventBus: todoMutationEventBus
6775 )
6876
6977 return Fixture (
7078 repository: repository,
7179 todoService: todoService,
72- widgetSyncEventBus: widgetSyncEventBus
80+ widgetSyncEventBus: widgetSyncEventBus,
81+ todoMutationEventBus: todoMutationEventBus
7382 )
7483 }
7584
@@ -97,6 +106,7 @@ private struct Fixture {
97106 let repository : TodoRepositoryImpl
98107 let todoService : TodoServiceSpy
99108 let widgetSyncEventBus : WidgetSyncEventBusSpy
109+ let todoMutationEventBus : TodoMutationEventBusSpy
100110}
101111
102112private actor TodoServiceSpy : TodoService {
@@ -159,6 +169,24 @@ private final class WidgetSyncEventBusSpy: WidgetSyncEventBus {
159169 }
160170}
161171
172+ private actor TodoMutationEventBusSpy : TodoMutationEventBus {
173+ private var capturedEvents = [ TodoMutationEvent] ( )
174+
175+ func publish( _ event: TodoMutationEvent ) async {
176+ capturedEvents. append ( event)
177+ }
178+
179+ func publishedEvents( ) -> [ TodoMutationEvent ] {
180+ capturedEvents
181+ }
182+
183+ func events( ) async -> AsyncStream < TodoMutationEvent > {
184+ AsyncStream { continuation in
185+ continuation. finish ( )
186+ }
187+ }
188+ }
189+
162190private enum TodoRepositoryImplTestsError : Error , Equatable {
163191 case serviceFailed
164192 case unexpectedCall
0 commit comments