-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
Heim/DataModule/DataModuleTests/TestDouble/MockAVPlayerManager.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,37 @@ | ||
// | ||
// MockAVPlayerManager.swift | ||
// DataModuleTests | ||
// | ||
// Created by 정지용 on 12/5/24. | ||
// | ||
|
||
import Foundation | ||
@testable import DataModule | ||
|
||
final class MockAVPlayerManager: AVPlayerManager { | ||
struct CallCount { | ||
var play = 0 | ||
var pause = 0 | ||
var setVolume = 0 | ||
var setupAudioSession = 0 | ||
} | ||
|
||
var callCount = CallCount() | ||
var isPlaying: Bool = false | ||
|
||
func play(url: URL) async { | ||
callCount.play += 1 | ||
} | ||
|
||
func pause() { | ||
callCount.pause += 1 | ||
} | ||
|
||
func setVolume(_ volume: Float) { | ||
callCount.setVolume += 1 | ||
} | ||
|
||
func setupAudioSession() throws { | ||
callCount.setupAudioSession += 1 | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
Heim/DataModule/DataModuleTests/TestDouble/MockDataStorage.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,61 @@ | ||
// | ||
// MockDataStorage.swift | ||
// DataModuleTests | ||
// | ||
// Created by 정지용 on 12/5/24. | ||
// | ||
// swiftlint:disable force_cast | ||
|
||
@testable import DataModule | ||
@testable import Domain | ||
|
||
final class MockDataStorage: DataStorage { | ||
struct CallCount { | ||
var readData = 0 | ||
var readDataWithTwoParameters = 0 | ||
var readAll = 0 | ||
var saveData = 0 | ||
var saveDataWithThreeParameters = 0 | ||
var deleteData = 0 | ||
var deleteAll = 0 | ||
} | ||
|
||
struct Return { | ||
var readData: Any! | ||
var readAll: Any! | ||
} | ||
|
||
var callCount = CallCount() | ||
var returnValue = Return() | ||
|
||
func readData<T>(directory: String, fileName: String) async throws -> T where T: Decodable { | ||
callCount.readDataWithTwoParameters += 1 | ||
return returnValue.readData as! T | ||
} | ||
|
||
func readData<T>(calendarDate: CalendarDate) async throws -> T where T: Decodable { | ||
callCount.readData += 1 | ||
return returnValue.readData as! T | ||
} | ||
|
||
func readAll<T>(directory: String) async throws -> T where T: Decodable { | ||
callCount.readAll += 1 | ||
return returnValue.readAll as! T | ||
} | ||
|
||
func saveData<T>(directory: String, fileName: String, data: T) async throws where T: Encodable { | ||
callCount.saveDataWithThreeParameters += 1 | ||
} | ||
|
||
func saveData<T>(calendarDate: CalendarDate, data: T) async throws where T: Encodable { | ||
callCount.saveData += 1 | ||
} | ||
|
||
func deleteData(calendarDate: CalendarDate) async throws { | ||
callCount.deleteData += 1 | ||
} | ||
|
||
func deleteAll() async throws { | ||
callCount.deleteAll += 1 | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Heim/DataModule/DataModuleTests/TestDouble/MockNetworkProvider.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,35 @@ | ||
// | ||
// MockNetworkProvider.swift | ||
// DataModuleTests | ||
// | ||
// Created by 정지용 on 12/5/24. | ||
// | ||
// swiftlint:disable force_cast | ||
|
||
import Foundation | ||
@testable import DataModule | ||
|
||
final class MockNetworkProvider: NetworkProvider { | ||
struct CallCount { | ||
var request = 0 | ||
var makeURL = 0 | ||
} | ||
|
||
struct Return { | ||
var request: Any! | ||
var makeURL: URL! | ||
} | ||
|
||
var callCount = CallCount() | ||
var returnValue = Return() | ||
|
||
func request<T>(target: any DataModule.RequestTarget, type: T.Type) async throws -> T where T: Decodable { | ||
callCount.request += 1 | ||
return returnValue.request as! T | ||
} | ||
|
||
func makeURL(target: any DataModule.RequestTarget) throws -> URL? { | ||
callCount.makeURL += 1 | ||
return returnValue.makeURL | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
Heim/DataModule/DataModuleTests/TestDouble/MockRequestTarget.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,34 @@ | ||
// | ||
// MockRequestTarget.swift | ||
// DataModuleTests | ||
// | ||
// Created by 정지용 on 12/5/24. | ||
// | ||
|
||
import Foundation | ||
@testable import DataModule | ||
|
||
final class MockRequestTarget: RequestTarget { | ||
var baseURL: String | ||
var path: String | ||
var method: HTTPMethod | ||
var headers: [String: String] | ||
var body: (any Encodable)? | ||
var query: [String: Any] | ||
|
||
init( | ||
baseURL: String, | ||
path: String, | ||
method: HTTPMethod, | ||
headers: [String: String], | ||
body: (any Encodable)? = nil, | ||
query: [String: Any] | ||
) { | ||
self.baseURL = baseURL | ||
self.path = path | ||
self.method = method | ||
self.headers = headers | ||
self.body = body | ||
self.query = query | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Heim/DataModule/DataModuleTests/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,43 @@ | ||
// | ||
// MockTokenManager.swift | ||
// DataModuleTests | ||
// | ||
// Created by 정지용 on 12/5/24. | ||
// | ||
|
||
@testable import DataModule | ||
|
||
final class MockTokenManager: TokenManager { | ||
struct CallCount { | ||
var isAccessTokenValid = 0 | ||
var loadAccessToken = 0 | ||
var loadRefreshToken = 0 | ||
var storeTokens = 0 | ||
} | ||
|
||
struct Return { | ||
var loadAccessToken: String! | ||
var loadRefreshToken: String! | ||
} | ||
|
||
var callCount = CallCount() | ||
var returnValue = Return() | ||
|
||
func isAccessTokenValid() throws { | ||
callCount.isAccessTokenValid += 1 | ||
} | ||
|
||
func loadAccessToken() throws -> String { | ||
callCount.loadAccessToken += 1 | ||
return returnValue.loadAccessToken | ||
} | ||
|
||
func loadRefreshToken() throws -> String { | ||
callCount.loadRefreshToken += 1 | ||
return returnValue.loadRefreshToken | ||
} | ||
|
||
func storeTokens(accessToken: String, refreshToken: String, expiresIn: Int) throws { | ||
callCount.storeTokens += 1 | ||
} | ||
} |