@@ -44,17 +44,46 @@ struct AuthenticationRepositoryImplTests {
4444 ] )
4545 }
4646
47- @Test ( " Apple 로그아웃은 provider 로그아웃 뒤 위젯 데이터를 정리한다" )
48- func Apple_로그아웃은_provider_로그아웃_뒤_위젯_데이터를_정리한다 ( ) async throws {
47+ @Test ( " 로그아웃은 공통 세션 정리 후 연결된 모든 provider 세션과 위젯 데이터를 정리한다 " )
48+ func 로그아웃은_공통_세션_정리_후_연결된_모든_provider_세션과_위젯_데이터를_정리한다 ( ) async throws {
4949 let fixture = makeAuthenticationRepositoryFixture (
5050 uid: " user-id " ,
51- providerID : " apple.com "
51+ providerIDs : [ " apple.com " , " github.com " , " google.com " ]
5252 )
5353
5454 try await fixture. repository. signOut ( )
5555
5656 #expect( fixture. events. values ( ) == [
57+ " auth.clearCurrentSession " ,
5758 " apple.signOut " ,
59+ " github.signOut " ,
60+ " google.signOut " ,
61+ " widget.clear "
62+ ] )
63+ }
64+
65+ @Test ( " 공통 세션 정리 실패는 provider 세션과 위젯 데이터를 정리하지 않고 오류를 전달한다 " )
66+ func 공통_세션_정리_실패는_provider_세션과_위젯_데이터를_정리하지_않고_오류를_전달한다( ) async {
67+ let fixture = makeAuthenticationRepositoryFixture (
68+ uid: " user-id " ,
69+ providerIDs: [ " apple.com " , " github.com " , " google.com " ] ,
70+ clearCurrentSessionError: AuthenticationRepositoryTestError . clearCurrentSession
71+ )
72+
73+ await #expect( throws: AuthenticationRepositoryTestError . clearCurrentSession) {
74+ try await fixture. repository. signOut ( )
75+ }
76+ #expect( fixture. events. values ( ) == [ " auth.clearCurrentSession " ] )
77+ }
78+
79+ @Test ( " provider 목록이 없어도 공통 세션과 위젯 데이터를 정리한다 " )
80+ func provider_목록이_없어도_공통_세션과_위젯_데이터를_정리한다( ) async throws {
81+ let fixture = makeAuthenticationRepositoryFixture ( uid: " user-id " )
82+
83+ try await fixture. repository. signOut ( )
84+
85+ #expect( fixture. events. values ( ) == [
86+ " auth.clearCurrentSession " ,
5887 " widget.clear "
5988 ] )
6089 }
@@ -98,14 +127,16 @@ struct AuthenticationRepositoryImplTests {
98127 providerID: String ? = nil ,
99128 providerIDs: [ String ] = [ ] ,
100129 signInResult: Result < AuthDataResponse ? , Error > = . success( nil ) ,
101- deleteCurrentUserError: Error ? = nil
130+ deleteCurrentUserError: Error ? = nil ,
131+ clearCurrentSessionError: Error ? = nil
102132 ) -> AuthenticationRepositoryFixture {
103133 let events = AuthenticationRepositoryEventRecorder ( )
104134 let authService = AuthenticationRepositoryAuthServiceSpy (
105135 uid: uid,
106136 providerID: providerID,
107137 providerIDs: providerIDs,
108138 deleteCurrentUserError: deleteCurrentUserError,
139+ clearCurrentSessionError: clearCurrentSessionError,
109140 events: events
110141 )
111142 let appleAuthService = AuthenticationServiceSpy (
@@ -149,6 +180,7 @@ private struct AuthenticationRepositoryFixture {
149180}
150181
151182private enum AuthenticationRepositoryTestError : Error , Equatable {
183+ case clearCurrentSession
152184 case requiresRecentLogin
153185}
154186
@@ -171,6 +203,7 @@ final class AuthenticationRepositoryAuthServiceSpy: AuthService {
171203 private let subject : CurrentValueSubject < Bool , Never >
172204 private let providerID : String ?
173205 private let deleteCurrentUserError : Error ?
206+ private let clearCurrentSessionError : Error ?
174207 private let events : AuthenticationRepositoryEventRecorder
175208
176209 var uid : String ?
@@ -183,13 +216,15 @@ final class AuthenticationRepositoryAuthServiceSpy: AuthService {
183216 providerIDs: [ String ] ,
184217 providerCount: Int ? = nil ,
185218 deleteCurrentUserError: Error ? = nil ,
219+ clearCurrentSessionError: Error ? = nil ,
186220 events: AuthenticationRepositoryEventRecorder
187221 ) {
188222 self . uid = uid
189223 self . providerID = providerID
190224 self . providerIDs = providerIDs
191225 self . providerCount = providerCount ?? providerIDs. count
192226 self . deleteCurrentUserError = deleteCurrentUserError
227+ self . clearCurrentSessionError = clearCurrentSessionError
193228 self . events = events
194229 self . subject = CurrentValueSubject < Bool , Never > ( uid != nil )
195230 }
@@ -223,10 +258,13 @@ final class AuthenticationRepositoryAuthServiceSpy: AuthService {
223258
224259 func clearCurrentSession( ) async throws {
225260 events. record ( " auth.clearCurrentSession " )
261+ if let clearCurrentSessionError {
262+ throw clearCurrentSessionError
263+ }
226264 }
227265}
228266
229- actor AuthenticationServiceSpy : AuthenticationService {
267+ final class AuthenticationServiceSpy : AuthenticationService {
230268 private let provider : String
231269 private let signInResult : Result < AuthDataResponse ? , Error >
232270 private let linkResult : Result < Bool , Error >
@@ -252,7 +290,7 @@ actor AuthenticationServiceSpy: AuthenticationService {
252290 return try signInResult. get ( )
253291 }
254292
255- func signOut( _ uid : String ) async throws {
293+ func signOut( ) {
256294 events. record ( " \( provider) .signOut " )
257295 }
258296
0 commit comments