Implemented the "actions" property for the FileServiceSpy spy in the tests target to support tracking multiple actions.

This commit is contained in:
2025-01-12 23:28:20 +01:00
parent a1ad391baa
commit 12151deea0
2 changed files with 35 additions and 27 deletions
@@ -6,10 +6,7 @@ final class FileServiceSpy {
// MARK: Properties
private(set) var isCreateFolderCalled: Bool = false
private(set) var isDeleteCalled: Bool = false
private(set) var isExistsAtCalled: Bool = false
private(set) var urlCalled: URL?
private(set) var actions: [Action] = []
}
@@ -20,22 +17,29 @@ extension FileServiceSpy: FileServicing {
get async { .someCurrentFolder }
}
func createFolder(at url: URL) async throws(FileServiceError) {
isCreateFolderCalled = true
urlCalled = url
func createFolder(at url: URL) async throws (FileServiceError) {
actions.append(.folderCreated(url))
}
func delete(at url: URL) async throws(FileServiceError) {
isDeleteCalled = true
urlCalled = url
func delete(at url: URL) async throws (FileServiceError) {
actions.append(.itemDeleted(url))
}
@discardableResult
func exists(at url: URL) async throws(FileServiceError) -> Bool {
isExistsAtCalled = true
urlCalled = url
func exists(at url: URL) async throws (FileServiceError) -> Bool {
actions.append(.itemExists(url))
return .random()
}
}
// MARK: - Action
extension FileServiceSpy {
enum Action: Equatable {
case folderCreated(_ url: URL)
case itemDeleted(_ url: URL)
case itemExists(_ url: URL)
}
}