Improved the implementation for the CreateFolderTask task in the library target.

This commit is contained in:
2025-01-18 04:25:01 +01:00
parent 9ee7592902
commit 026251ad6d
3 changed files with 34 additions and 25 deletions
@@ -14,24 +14,36 @@ struct CreateFoldersTaskTests {
@Test(arguments: [URL.someCurrentFolder, .someDotFolder, .someTildeFolder])
func createFolders(with rootFolder: URL) async throws {
// GIVEN
let folders = CreateFoldersTask.foldersToCreate.map { rootFolder.appendingPath($0) }
let actions: [FileServiceMock.Action] = folders.map { .createFolder($0) }
let folders = Folder.allCases.map { rootFolder.appendingPath($0.rawValue) }
let actions = folders.map { FileServiceMock.Action.createFolder($0) }
let service = FileServiceMock(
currentFolder: .someCurrentFolder,
actions: actions,
spy: spy
)
let createFolders = CreateFoldersTask(fileService: service)
let createFolders = task(actions: actions)
// WHEN
try await createFolders(at: rootFolder)
// THEN
#expect(spy.actions.count == actions.count)
for index in actions.indices {
#expect(spy.actions[index] == .folderCreated(folders[index]))
}
}
}
// MARK: - Helpers
private extension CreateFoldersTaskTests {
// MARK: Functions
func task(actions: [FileServiceMock.Action]) -> CreateFoldersTask {
.init(fileService: FileServiceMock(
currentFolder: .someCurrentFolder,
actions: actions,
spy: spy
))
}
}