diff --git a/Sources/Library/Tasks/CreateFoldersTask.swift b/Sources/Library/Tasks/CreateFoldersTask.swift index 4a512f2..a0a3531 100644 --- a/Sources/Library/Tasks/CreateFoldersTask.swift +++ b/Sources/Library/Tasks/CreateFoldersTask.swift @@ -15,19 +15,30 @@ public struct CreateFoldersTask { // MARK: Functions public func callAsFunction(at rootFolder: URL) async throws { - let folderApp = rootFolder.appendingPath(.folderApp) - let folderAppInfrastructure = rootFolder.appendingPath(.folderAppInfrastructure) - let folderAppTestCases = rootFolder.appendingPath(.folderAppTestCases) - let folderAppTestSources = rootFolder.appendingPath(.folderAppTestSources) - - try await fileService.createFolder(at: folderApp) - try await fileService.createFolder(at: folderAppInfrastructure) - try await fileService.createFolder(at: folderAppTestCases) - try await fileService.createFolder(at: folderAppTestSources) + let folders = Self.foldersToCreate.map { rootFolder.appendingPath($0) } + + for folder in folders { + try await fileService.createFolder(at: folder) + } } } +// MARK: - Helpers + +extension CreateFoldersTask { + + // MARK: Constants + + static let foldersToCreate: [String] = [ + .folderApp, + .folderAppInfrastructure, + .folderAppTestCases, + .folderAppTestSources + ] + +} + // MARK: - String+Constants private extension String { diff --git a/Tests/Library/Cases/Tasks/CreateFoldersTaskTests.swift b/Tests/Library/Cases/Tasks/CreateFoldersTaskTests.swift index 137f6c1..396ac89 100644 --- a/Tests/Library/Cases/Tasks/CreateFoldersTaskTests.swift +++ b/Tests/Library/Cases/Tasks/CreateFoldersTaskTests.swift @@ -14,19 +14,12 @@ struct CreateFoldersTaskTests { @Test(arguments: [URL.someCurrentFolder, .someDotFolder, .someTildeFolder]) func createFolders(with rootFolder: URL) async throws { // GIVEN - let folderApp = rootFolder.appendingPath("Sources/App") - let folderAppInfrastructure = rootFolder.appendingPath("Sources/AppInfrastructure") - let folderTestSources = rootFolder.appendingPath("Test/App/Sources") - let folderTestCases = rootFolder.appendingPath("Test/App/Cases") - + let folders = CreateFoldersTask.foldersToCreate.map { rootFolder.appendingPath($0) } + let actions: [FileServiceMock.Action] = folders.map { .createFolder($0) } + let service = FileServiceMock( currentFolder: .someCurrentFolder, - actions: [ - .createFolder(folderApp), - .createFolder(folderAppInfrastructure), - .createFolder(folderTestSources), - .createFolder(folderTestCases), - ], + actions: actions, spy: spy ) @@ -36,10 +29,9 @@ struct CreateFoldersTaskTests { try await createFolders(at: rootFolder) // THEN - #expect(spy.actions[0] == .folderCreated(folderApp)) - #expect(spy.actions[1] == .folderCreated(folderAppInfrastructure)) - #expect(spy.actions[2] == .folderCreated(folderTestSources)) - #expect(spy.actions[3] == .folderCreated(folderTestCases)) + for index in actions.indices { + #expect(spy.actions[index] == .folderCreated(folders[index])) + } } }