2025-01-11 11:27:39 +01:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
@testable import ColibriLibrary
|
|
|
|
|
|
|
|
final class FileServiceSpy {
|
|
|
|
|
|
|
|
// MARK: Properties
|
|
|
|
|
2025-01-12 23:28:20 +01:00
|
|
|
private(set) var actions: [Action] = []
|
2025-01-11 11:27:39 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - FileServicing
|
|
|
|
|
|
|
|
extension FileServiceSpy: FileServicing {
|
2025-01-13 23:27:50 +01:00
|
|
|
|
2025-01-11 11:27:39 +01:00
|
|
|
var currentFolder: URL {
|
|
|
|
get async { .someCurrentFolder }
|
|
|
|
}
|
|
|
|
|
2025-01-18 01:07:52 +01:00
|
|
|
func copyFile(from source: URL, to destination: URL) async throws (FileServiceError) {
|
|
|
|
actions.append(.fileCopied(source, destination))
|
2025-01-11 11:27:39 +01:00
|
|
|
}
|
|
|
|
|
2025-01-13 23:27:50 +01:00
|
|
|
func createFolder(at location: URL) async throws (FileServiceError) {
|
|
|
|
actions.append(.folderCreated(location))
|
|
|
|
}
|
|
|
|
|
|
|
|
func deleteItem(at location: URL) async throws (FileServiceError) {
|
|
|
|
actions.append(.itemDeleted(location))
|
2025-01-11 11:27:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@discardableResult
|
2025-01-13 23:27:50 +01:00
|
|
|
func isItemExists(at location: URL) async throws (FileServiceError) -> Bool {
|
|
|
|
actions.append(.itemExists(location))
|
2025-01-12 23:28:20 +01:00
|
|
|
|
2025-01-11 11:27:39 +01:00
|
|
|
return .random()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2025-01-12 23:28:20 +01:00
|
|
|
|
|
|
|
// MARK: - Action
|
|
|
|
|
|
|
|
extension FileServiceSpy {
|
|
|
|
enum Action: Equatable {
|
2025-01-18 01:07:52 +01:00
|
|
|
case fileCopied(_ source: URL, _ destination: URL)
|
2025-01-13 23:27:50 +01:00
|
|
|
case folderCreated(_ location: URL)
|
|
|
|
case itemDeleted(_ location: URL)
|
|
|
|
case itemExists(_ location: URL)
|
2025-01-12 23:28:20 +01:00
|
|
|
}
|
|
|
|
}
|