@@ -368,4 +368,49 @@ class OAuthClientTests: XCTestCase {
368
368
369
369
waitForExpectations ( timeout: 5 , handler: nil )
370
370
}
371
+
372
+ func testLogoutWorksCorrectly( ) throws {
373
+ let expect = expectation ( description: " Token is deleted " )
374
+
375
+ let jsonData = TestStrings . oAuthTokenResponse. data ( using: . utf8)
376
+
377
+ let tokenToStore = try JSONDecoder ( ) . decode ( OAuthAccessToken . self, from: jsonData!)
378
+
379
+ try keychain. add ( tokenToStore, withKey: " password " )
380
+
381
+ // Verify the token is infact stored
382
+ client. fetchStoredToken ( type: . password( " " , " " ) ) { [ weak self] result in
383
+ guard let self = self else {
384
+ XCTFail ( )
385
+ return
386
+ }
387
+
388
+ switch result {
389
+ case . success( let returnedToken) :
390
+ XCTAssertEqual ( returnedToken. accessToken, tokenToStore. accessToken)
391
+ // Perform the logout
392
+ self . client. logout ( )
393
+
394
+ // Verify we can no longer fetch a stored password token
395
+ self . client. fetchStoredToken ( type: . password( " " , " " ) ) { secondResult in
396
+ switch secondResult {
397
+ case . success( _) :
398
+ XCTFail ( " Token was still retreived " )
399
+ case . failure( let returnedError) :
400
+ let decodedError = returnedError as! OAuthClientError
401
+ switch decodedError {
402
+ case . errorReadingTokenFromStorage( _) :
403
+ expect. fulfill ( )
404
+ default :
405
+ XCTFail ( " Wrong error type " )
406
+ }
407
+ }
408
+ }
409
+ case . failure( _) :
410
+ XCTFail ( " Token not stored " )
411
+ }
412
+ }
413
+
414
+ waitForExpectations ( timeout: 5 , handler: nil )
415
+ }
371
416
}
0 commit comments