-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Test] - #176 MockingTokenManager 구현
- Loading branch information
1 parent
492a4b9
commit 42af85f
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
Heim/NetworkModule/NetworkModuleTests/TestDouble/MockTokenManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// MockTokenManager.swift | ||
// NetworkModule | ||
// | ||
// Created by 김미래 on 12/5/24. | ||
// | ||
|
||
@testable import DataModule | ||
@testable import Domain | ||
@testable import NetworkModule | ||
|
||
final class MockTokenManager: TokenManager { | ||
struct CallCount { | ||
var isAccessTokenValid = 0 | ||
var loadAccessToken = 0 | ||
var loadRefreshToken = 0 | ||
var storeToken = 0 | ||
} | ||
|
||
var accessToken: String! | ||
var refreshToken: String! | ||
var callCount = CallCount() | ||
|
||
func isAccessTokenValid() throws { | ||
callCount.isAccessTokenValid += 1 | ||
} | ||
|
||
func loadAccessToken() throws -> String { | ||
callCount.loadAccessToken += 1 | ||
|
||
guard let accessToken = accessToken else { | ||
throw TokenError.accessTokenExpired | ||
} | ||
return accessToken | ||
} | ||
|
||
func loadRefreshToken() throws -> String { | ||
callCount.loadRefreshToken += 1 | ||
|
||
guard let refreshToken = refreshToken else { | ||
throw TokenError.refreshTokenExpired | ||
} | ||
return refreshToken | ||
} | ||
|
||
func storeTokens(accessToken: String, refreshToken: String, expiresIn: Int) throws { | ||
callCount.storeToken += 1 | ||
} | ||
} |