Refactored some test cases in the tests target.

This commit is contained in:
2025-01-18 04:03:07 +01:00
parent 1094bbb6c8
commit 9ee7592902
3 changed files with 41 additions and 61 deletions
@@ -19,11 +19,7 @@ struct CopyFilesTaskTests {
let files = files(of: ResourceFile.allCases)
let actions = files.map { FileServiceMock.Action.copyFile($0.source, $0.destination) }
let copyFiles = CopyFilesTask(fileService: FileServiceMock(
currentFolder: .someCurrentFolder,
actions: actions,
spy: spy
))
let copyFiles = task(actions: actions)
// WHEN
try await copyFiles(to: rootFolder)
@@ -42,11 +38,7 @@ struct CopyFilesTaskTests {
let files = files(of: Array(ResourceFile.allCases[0...2]))
let actions = files.map { FileServiceMock.Action.copyFile($0.source, $0.destination) }
let copyFiles = CopyFilesTask(fileService: FileServiceMock(
currentFolder: .someCurrentFolder,
actions: actions + [.error(error)],
spy: spy
))
let copyFiles = task(actions: actions + [.error(error)])
// WHEN
// THEN
@@ -76,5 +68,13 @@ private extension CopyFilesTaskTests {
func files(of resourceFiles: [ResourceFile]) -> [File] {
resourceFiles.map { (resourceFolder.appendingPath($0.rawValue), rootFolder.appendingPath($0.fileName)) }
}
func task(actions: [FileServiceMock.Action]) -> CopyFilesTask {
.init(fileService: FileServiceMock(
currentFolder: .someCurrentFolder,
actions: actions,
spy: spy
))
}
}
@@ -20,12 +20,10 @@ struct CreateRootFolderTaskTests {
default: nil
}
let fileService = FileServiceMock(
let task = CreateRootFolderTask(fileService: FileServiceMock(
currentFolder: .someCurrentFolder,
action: .createFolder(folder)
)
let task = CreateRootFolderTask(fileService: fileService)
))
// WHEN
let result = try await task(name: name,
@@ -42,12 +40,10 @@ struct CreateRootFolderTaskTests {
throws error: FileServiceError
) async throws {
// GIVEN
let fileService = FileServiceMock(
let task = CreateRootFolderTask(fileService: FileServiceMock(
currentFolder: .someCurrentFolder,
action: .error(error)
)
let task = CreateRootFolderTask(fileService: fileService)
))
// WHEN
// THEN
@@ -62,9 +58,9 @@ struct CreateRootFolderTaskTests {
throws error: CreateRootFolderError
) async throws {
// GIVEN
let fileService = FileServiceMock(currentFolder: .someCurrentFolder)
let task = CreateRootFolderTask(fileService: fileService)
let task = CreateRootFolderTask(fileService: FileServiceMock(
currentFolder: .someCurrentFolder
))
// WHEN
// THEN