2025-01-13 00:33:13 +01:00
|
|
|
import Foundation
|
|
|
|
import Testing
|
|
|
|
|
|
|
|
@testable import ColibriLibrary
|
|
|
|
|
|
|
|
struct CreateFoldersTaskTests {
|
|
|
|
|
|
|
|
// MARK: Properties
|
|
|
|
|
|
|
|
private let spy = FileServiceSpy()
|
|
|
|
|
|
|
|
// MARK: Functions tests
|
|
|
|
|
|
|
|
@Test(arguments: [URL.someCurrentFolder, .someDotFolder, .someTildeFolder])
|
|
|
|
func createFolders(with rootFolder: URL) async throws {
|
|
|
|
// GIVEN
|
2025-01-18 11:38:01 +01:00
|
|
|
let folders = Folder.allCases.map { rootFolder.appendingPath($0.path) }
|
2025-01-18 04:25:01 +01:00
|
|
|
let actions = folders.map { FileServiceMock.Action.createFolder($0) }
|
2025-01-16 01:45:41 +01:00
|
|
|
|
2025-01-18 04:25:01 +01:00
|
|
|
let createFolders = task(actions: actions)
|
2025-01-13 00:33:13 +01:00
|
|
|
|
|
|
|
// WHEN
|
|
|
|
try await createFolders(at: rootFolder)
|
|
|
|
|
|
|
|
// THEN
|
2025-01-18 04:25:01 +01:00
|
|
|
#expect(spy.actions.count == actions.count)
|
|
|
|
|
2025-01-16 01:45:41 +01:00
|
|
|
for index in actions.indices {
|
|
|
|
#expect(spy.actions[index] == .folderCreated(folders[index]))
|
|
|
|
}
|
2025-01-13 00:33:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2025-01-18 04:25:01 +01:00
|
|
|
|
|
|
|
// MARK: - Helpers
|
|
|
|
|
|
|
|
private extension CreateFoldersTaskTests {
|
|
|
|
|
|
|
|
// MARK: Functions
|
|
|
|
|
|
|
|
func task(actions: [FileServiceMock.Action]) -> CreateFoldersTask {
|
|
|
|
.init(fileService: FileServiceMock(
|
|
|
|
currentFolder: .someCurrentFolder,
|
|
|
|
actions: actions,
|
|
|
|
spy: spy
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|