Template support for input parameters #4
@ -30,11 +30,7 @@ struct FileServiceTests {
|
||||
[URL.someNewFile, .someNewFolder]))
|
||||
func copyFile(from source: URL, to destination: URL) async throws {
|
||||
// GIVEN
|
||||
let service = FileServiceMock(
|
||||
currentFolder: .someCurrentFolder,
|
||||
action: .copyFile(source, destination),
|
||||
spy: spy
|
||||
)
|
||||
let service = service(action: .copyFile(source, destination))
|
||||
|
||||
// WHEN
|
||||
try await service.copyFile(from: source, to: destination)
|
||||
@ -50,11 +46,7 @@ struct FileServiceTests {
|
||||
@Test(arguments: [FileServiceError.itemAlreadyExists, .itemEmptyData, .itemNotCopied])
|
||||
func copyItem(throws error: FileServiceError) async throws {
|
||||
// GIVEN
|
||||
let service = FileServiceMock(
|
||||
currentFolder: .someCurrentFolder,
|
||||
action: .error(error),
|
||||
spy: spy
|
||||
)
|
||||
let service = service(action: .error(error))
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
@ -68,11 +60,7 @@ struct FileServiceTests {
|
||||
@Test(arguments: [URL.someNewFolder, .someNewFile])
|
||||
func createFolder(with location: URL) async throws {
|
||||
// GIVEN
|
||||
let service = FileServiceMock(
|
||||
currentFolder: .someCurrentFolder,
|
||||
action: .createFolder(location),
|
||||
spy: spy
|
||||
)
|
||||
let service = service(action: .createFolder(location))
|
||||
|
||||
// WHEN
|
||||
try await service.createFolder(at: location)
|
||||
@ -92,11 +80,7 @@ struct FileServiceTests {
|
||||
throws error: FileServiceError
|
||||
) async throws {
|
||||
// GIVEN
|
||||
let service = FileServiceMock(
|
||||
currentFolder: .someCurrentFolder,
|
||||
action: .error(error),
|
||||
spy: spy
|
||||
)
|
||||
let service = service(action: .error(error))
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
@ -110,11 +94,7 @@ struct FileServiceTests {
|
||||
@Test(arguments: [URL.someNewFolder, .someNewFile])
|
||||
func deleteItem(with location: URL) async throws {
|
||||
// GIVEN
|
||||
let service = FileServiceMock(
|
||||
currentFolder: .someCurrentFolder,
|
||||
action: .deleteItem(location),
|
||||
spy: spy
|
||||
)
|
||||
let service = service(action: .deleteItem(location))
|
||||
|
||||
// WHEN
|
||||
try await service.deleteItem(at: location)
|
||||
@ -134,11 +114,7 @@ struct FileServiceTests {
|
||||
throws error: FileServiceError
|
||||
) async throws {
|
||||
// GIVEN
|
||||
let service = FileServiceMock(
|
||||
currentFolder: .someCurrentFolder,
|
||||
action: .error(error),
|
||||
spy: spy
|
||||
)
|
||||
let service = service(action: .error(error))
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
@ -156,11 +132,7 @@ struct FileServiceTests {
|
||||
expects outcome: Bool
|
||||
) async throws {
|
||||
// GIVEN
|
||||
let service = FileServiceMock(
|
||||
currentFolder: .someCurrentFolder,
|
||||
action: .isItemExists(location, outcome),
|
||||
spy: spy
|
||||
)
|
||||
let service = service(action: .isItemExists(location, outcome))
|
||||
|
||||
// WHEN
|
||||
let result = try await service.isItemExists(at: location)
|
||||
@ -179,11 +151,7 @@ struct FileServiceTests {
|
||||
throws error: FileServiceError
|
||||
) async throws {
|
||||
// GIVEN
|
||||
let service = FileServiceMock(
|
||||
currentFolder: .someCurrentFolder,
|
||||
action: .error(error),
|
||||
spy: spy
|
||||
)
|
||||
let service = service(action: .error(error))
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
@ -195,3 +163,19 @@ struct FileServiceTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private extension FileServiceTests {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
func service(action: FileServiceMock.Action) -> FileServiceMock {
|
||||
.init(
|
||||
currentFolder: .someCurrentFolder,
|
||||
action: action,
|
||||
spy: spy
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user