Improved upon the implementation of the "callAsFunction(at: )" function for the CreateFoldersTask task in the library target.
This commit is contained in:
parent
72230c5337
commit
fbb5d2d2a4
@ -15,19 +15,30 @@ public struct CreateFoldersTask {
|
|||||||
// MARK: Functions
|
// MARK: Functions
|
||||||
|
|
||||||
public func callAsFunction(at rootFolder: URL) async throws {
|
public func callAsFunction(at rootFolder: URL) async throws {
|
||||||
let folderApp = rootFolder.appendingPath(.folderApp)
|
let folders = Self.foldersToCreate.map { rootFolder.appendingPath($0) }
|
||||||
let folderAppInfrastructure = rootFolder.appendingPath(.folderAppInfrastructure)
|
|
||||||
let folderAppTestCases = rootFolder.appendingPath(.folderAppTestCases)
|
for folder in folders {
|
||||||
let folderAppTestSources = rootFolder.appendingPath(.folderAppTestSources)
|
try await fileService.createFolder(at: folder)
|
||||||
|
}
|
||||||
try await fileService.createFolder(at: folderApp)
|
|
||||||
try await fileService.createFolder(at: folderAppInfrastructure)
|
|
||||||
try await fileService.createFolder(at: folderAppTestCases)
|
|
||||||
try await fileService.createFolder(at: folderAppTestSources)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Helpers
|
||||||
|
|
||||||
|
extension CreateFoldersTask {
|
||||||
|
|
||||||
|
// MARK: Constants
|
||||||
|
|
||||||
|
static let foldersToCreate: [String] = [
|
||||||
|
.folderApp,
|
||||||
|
.folderAppInfrastructure,
|
||||||
|
.folderAppTestCases,
|
||||||
|
.folderAppTestSources
|
||||||
|
]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - String+Constants
|
// MARK: - String+Constants
|
||||||
|
|
||||||
private extension String {
|
private extension String {
|
||||||
|
@ -14,19 +14,12 @@ struct CreateFoldersTaskTests {
|
|||||||
@Test(arguments: [URL.someCurrentFolder, .someDotFolder, .someTildeFolder])
|
@Test(arguments: [URL.someCurrentFolder, .someDotFolder, .someTildeFolder])
|
||||||
func createFolders(with rootFolder: URL) async throws {
|
func createFolders(with rootFolder: URL) async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let folderApp = rootFolder.appendingPath("Sources/App")
|
let folders = CreateFoldersTask.foldersToCreate.map { rootFolder.appendingPath($0) }
|
||||||
let folderAppInfrastructure = rootFolder.appendingPath("Sources/AppInfrastructure")
|
let actions: [FileServiceMock.Action] = folders.map { .createFolder($0) }
|
||||||
let folderTestSources = rootFolder.appendingPath("Test/App/Sources")
|
|
||||||
let folderTestCases = rootFolder.appendingPath("Test/App/Cases")
|
|
||||||
|
|
||||||
let service = FileServiceMock(
|
let service = FileServiceMock(
|
||||||
currentFolder: .someCurrentFolder,
|
currentFolder: .someCurrentFolder,
|
||||||
actions: [
|
actions: actions,
|
||||||
.createFolder(folderApp),
|
|
||||||
.createFolder(folderAppInfrastructure),
|
|
||||||
.createFolder(folderTestSources),
|
|
||||||
.createFolder(folderTestCases),
|
|
||||||
],
|
|
||||||
spy: spy
|
spy: spy
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,10 +29,9 @@ struct CreateFoldersTaskTests {
|
|||||||
try await createFolders(at: rootFolder)
|
try await createFolders(at: rootFolder)
|
||||||
|
|
||||||
// THEN
|
// THEN
|
||||||
#expect(spy.actions[0] == .folderCreated(folderApp))
|
for index in actions.indices {
|
||||||
#expect(spy.actions[1] == .folderCreated(folderAppInfrastructure))
|
#expect(spy.actions[index] == .folderCreated(folders[index]))
|
||||||
#expect(spy.actions[2] == .folderCreated(folderTestSources))
|
}
|
||||||
#expect(spy.actions[3] == .folderCreated(folderTestCases))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user