@@ -2151,6 +2151,43 @@ final class AuthClientTests: XCTestCase {
2151
2151
)
2152
2152
}
2153
2153
2154
+ func testRemoveSessionAndSignoutIfSessionNotFoundErrorReturned( ) async throws {
2155
+ let sut = makeSUT ( )
2156
+
2157
+ Mock (
2158
+ url: clientURL. appendingPathComponent ( " user " ) ,
2159
+ statusCode: 403 ,
2160
+ data: [
2161
+ . get: Data (
2162
+ """
2163
+ {
2164
+ " error_code " : " session_not_found " ,
2165
+ " message " : " Session not found "
2166
+ }
2167
+ """ . utf8
2168
+ )
2169
+ ]
2170
+ )
2171
+ . register ( )
2172
+
2173
+ Dependencies [ sut. clientID] . sessionStorage. store ( . validSession)
2174
+
2175
+ try await assertAuthStateChanges (
2176
+ sut: sut,
2177
+ action: {
2178
+ do {
2179
+ _ = try await sut. user ( )
2180
+ XCTFail ( " Expected failure " )
2181
+ } catch {
2182
+ XCTAssertEqual ( error as? AuthError , . sessionMissing)
2183
+ }
2184
+ } ,
2185
+ expectedEvents: [ . initialSession, . signedOut]
2186
+ )
2187
+
2188
+ XCTAssertNil ( Dependencies [ sut. clientID] . sessionStorage. get ( ) )
2189
+ }
2190
+
2154
2191
private func makeSUT( flowType: AuthFlowType = . pkce) -> AuthClient {
2155
2192
let sessionConfiguration = URLSessionConfiguration . default
2156
2193
sessionConfiguration. protocolClasses = [ MockingURLProtocol . self]
@@ -2198,6 +2235,7 @@ final class AuthClientTests: XCTestCase {
2198
2235
action: ( ) async throws -> T ,
2199
2236
expectedEvents: [ AuthChangeEvent ] ,
2200
2237
expectedSessions: [ Session ? ] ? = nil ,
2238
+ timeout: TimeInterval = 2 ,
2201
2239
fileID: StaticString = #fileID,
2202
2240
filePath: StaticString = #filePath,
2203
2241
line: UInt = #line,
@@ -2211,14 +2249,30 @@ final class AuthClientTests: XCTestCase {
2211
2249
2212
2250
let result = try await action ( )
2213
2251
2214
- let authStateChanges = await eventsTask. value
2252
+ let authStateChanges = try await withTimeout ( interval: timeout) {
2253
+ await eventsTask. value
2254
+ }
2215
2255
let events = authStateChanges. map ( \. event)
2216
2256
let sessions = authStateChanges. map ( \. session)
2217
2257
2218
- expectNoDifference ( events, expectedEvents, fileID: fileID, filePath: filePath, line: line, column: column)
2258
+ expectNoDifference (
2259
+ events,
2260
+ expectedEvents,
2261
+ fileID: fileID,
2262
+ filePath: filePath,
2263
+ line: line,
2264
+ column: column
2265
+ )
2219
2266
2220
2267
if let expectedSessions = expectedSessions {
2221
- expectNoDifference ( sessions, expectedSessions, fileID: fileID, filePath: filePath, line: line, column: column)
2268
+ expectNoDifference (
2269
+ sessions,
2270
+ expectedSessions,
2271
+ fileID: fileID,
2272
+ filePath: filePath,
2273
+ line: line,
2274
+ column: column
2275
+ )
2222
2276
}
2223
2277
2224
2278
return result
0 commit comments