Refactored some test cases in the tests target.
This commit is contained in:
parent
1094bbb6c8
commit
9ee7592902
@ -30,11 +30,7 @@ struct FileServiceTests {
|
|||||||
[URL.someNewFile, .someNewFolder]))
|
[URL.someNewFile, .someNewFolder]))
|
||||||
func copyFile(from source: URL, to destination: URL) async throws {
|
func copyFile(from source: URL, to destination: URL) async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let service = FileServiceMock(
|
let service = service(action: .copyFile(source, destination))
|
||||||
currentFolder: .someCurrentFolder,
|
|
||||||
action: .copyFile(source, destination),
|
|
||||||
spy: spy
|
|
||||||
)
|
|
||||||
|
|
||||||
// WHEN
|
// WHEN
|
||||||
try await service.copyFile(from: source, to: destination)
|
try await service.copyFile(from: source, to: destination)
|
||||||
@ -50,11 +46,7 @@ struct FileServiceTests {
|
|||||||
@Test(arguments: [FileServiceError.itemAlreadyExists, .itemEmptyData, .itemNotCopied])
|
@Test(arguments: [FileServiceError.itemAlreadyExists, .itemEmptyData, .itemNotCopied])
|
||||||
func copyItem(throws error: FileServiceError) async throws {
|
func copyItem(throws error: FileServiceError) async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let service = FileServiceMock(
|
let service = service(action: .error(error))
|
||||||
currentFolder: .someCurrentFolder,
|
|
||||||
action: .error(error),
|
|
||||||
spy: spy
|
|
||||||
)
|
|
||||||
|
|
||||||
// WHEN
|
// WHEN
|
||||||
// THEN
|
// THEN
|
||||||
@ -68,11 +60,7 @@ struct FileServiceTests {
|
|||||||
@Test(arguments: [URL.someNewFolder, .someNewFile])
|
@Test(arguments: [URL.someNewFolder, .someNewFile])
|
||||||
func createFolder(with location: URL) async throws {
|
func createFolder(with location: URL) async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let service = FileServiceMock(
|
let service = service(action: .createFolder(location))
|
||||||
currentFolder: .someCurrentFolder,
|
|
||||||
action: .createFolder(location),
|
|
||||||
spy: spy
|
|
||||||
)
|
|
||||||
|
|
||||||
// WHEN
|
// WHEN
|
||||||
try await service.createFolder(at: location)
|
try await service.createFolder(at: location)
|
||||||
@ -92,11 +80,7 @@ struct FileServiceTests {
|
|||||||
throws error: FileServiceError
|
throws error: FileServiceError
|
||||||
) async throws {
|
) async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let service = FileServiceMock(
|
let service = service(action: .error(error))
|
||||||
currentFolder: .someCurrentFolder,
|
|
||||||
action: .error(error),
|
|
||||||
spy: spy
|
|
||||||
)
|
|
||||||
|
|
||||||
// WHEN
|
// WHEN
|
||||||
// THEN
|
// THEN
|
||||||
@ -110,11 +94,7 @@ struct FileServiceTests {
|
|||||||
@Test(arguments: [URL.someNewFolder, .someNewFile])
|
@Test(arguments: [URL.someNewFolder, .someNewFile])
|
||||||
func deleteItem(with location: URL) async throws {
|
func deleteItem(with location: URL) async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let service = FileServiceMock(
|
let service = service(action: .deleteItem(location))
|
||||||
currentFolder: .someCurrentFolder,
|
|
||||||
action: .deleteItem(location),
|
|
||||||
spy: spy
|
|
||||||
)
|
|
||||||
|
|
||||||
// WHEN
|
// WHEN
|
||||||
try await service.deleteItem(at: location)
|
try await service.deleteItem(at: location)
|
||||||
@ -134,11 +114,7 @@ struct FileServiceTests {
|
|||||||
throws error: FileServiceError
|
throws error: FileServiceError
|
||||||
) async throws {
|
) async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let service = FileServiceMock(
|
let service = service(action: .error(error))
|
||||||
currentFolder: .someCurrentFolder,
|
|
||||||
action: .error(error),
|
|
||||||
spy: spy
|
|
||||||
)
|
|
||||||
|
|
||||||
// WHEN
|
// WHEN
|
||||||
// THEN
|
// THEN
|
||||||
@ -156,11 +132,7 @@ struct FileServiceTests {
|
|||||||
expects outcome: Bool
|
expects outcome: Bool
|
||||||
) async throws {
|
) async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let service = FileServiceMock(
|
let service = service(action: .isItemExists(location, outcome))
|
||||||
currentFolder: .someCurrentFolder,
|
|
||||||
action: .isItemExists(location, outcome),
|
|
||||||
spy: spy
|
|
||||||
)
|
|
||||||
|
|
||||||
// WHEN
|
// WHEN
|
||||||
let result = try await service.isItemExists(at: location)
|
let result = try await service.isItemExists(at: location)
|
||||||
@ -179,11 +151,7 @@ struct FileServiceTests {
|
|||||||
throws error: FileServiceError
|
throws error: FileServiceError
|
||||||
) async throws {
|
) async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let service = FileServiceMock(
|
let service = service(action: .error(error))
|
||||||
currentFolder: .someCurrentFolder,
|
|
||||||
action: .error(error),
|
|
||||||
spy: spy
|
|
||||||
)
|
|
||||||
|
|
||||||
// WHEN
|
// WHEN
|
||||||
// THEN
|
// 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 files = files(of: ResourceFile.allCases)
|
||||||
let actions = files.map { FileServiceMock.Action.copyFile($0.source, $0.destination) }
|
let actions = files.map { FileServiceMock.Action.copyFile($0.source, $0.destination) }
|
||||||
|
|
||||||
let copyFiles = CopyFilesTask(fileService: FileServiceMock(
|
let copyFiles = task(actions: actions)
|
||||||
currentFolder: .someCurrentFolder,
|
|
||||||
actions: actions,
|
|
||||||
spy: spy
|
|
||||||
))
|
|
||||||
|
|
||||||
// WHEN
|
// WHEN
|
||||||
try await copyFiles(to: rootFolder)
|
try await copyFiles(to: rootFolder)
|
||||||
@ -42,11 +38,7 @@ struct CopyFilesTaskTests {
|
|||||||
let files = files(of: Array(ResourceFile.allCases[0...2]))
|
let files = files(of: Array(ResourceFile.allCases[0...2]))
|
||||||
let actions = files.map { FileServiceMock.Action.copyFile($0.source, $0.destination) }
|
let actions = files.map { FileServiceMock.Action.copyFile($0.source, $0.destination) }
|
||||||
|
|
||||||
let copyFiles = CopyFilesTask(fileService: FileServiceMock(
|
let copyFiles = task(actions: actions + [.error(error)])
|
||||||
currentFolder: .someCurrentFolder,
|
|
||||||
actions: actions + [.error(error)],
|
|
||||||
spy: spy
|
|
||||||
))
|
|
||||||
|
|
||||||
// WHEN
|
// WHEN
|
||||||
// THEN
|
// THEN
|
||||||
@ -77,4 +69,12 @@ private extension CopyFilesTaskTests {
|
|||||||
resourceFiles.map { (resourceFolder.appendingPath($0.rawValue), rootFolder.appendingPath($0.fileName)) }
|
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
|
default: nil
|
||||||
}
|
}
|
||||||
|
|
||||||
let fileService = FileServiceMock(
|
let task = CreateRootFolderTask(fileService: FileServiceMock(
|
||||||
currentFolder: .someCurrentFolder,
|
currentFolder: .someCurrentFolder,
|
||||||
action: .createFolder(folder)
|
action: .createFolder(folder)
|
||||||
)
|
))
|
||||||
|
|
||||||
let task = CreateRootFolderTask(fileService: fileService)
|
|
||||||
|
|
||||||
// WHEN
|
// WHEN
|
||||||
let result = try await task(name: name,
|
let result = try await task(name: name,
|
||||||
@ -42,12 +40,10 @@ struct CreateRootFolderTaskTests {
|
|||||||
throws error: FileServiceError
|
throws error: FileServiceError
|
||||||
) async throws {
|
) async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let fileService = FileServiceMock(
|
let task = CreateRootFolderTask(fileService: FileServiceMock(
|
||||||
currentFolder: .someCurrentFolder,
|
currentFolder: .someCurrentFolder,
|
||||||
action: .error(error)
|
action: .error(error)
|
||||||
)
|
))
|
||||||
|
|
||||||
let task = CreateRootFolderTask(fileService: fileService)
|
|
||||||
|
|
||||||
// WHEN
|
// WHEN
|
||||||
// THEN
|
// THEN
|
||||||
@ -62,9 +58,9 @@ struct CreateRootFolderTaskTests {
|
|||||||
throws error: CreateRootFolderError
|
throws error: CreateRootFolderError
|
||||||
) async throws {
|
) async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let fileService = FileServiceMock(currentFolder: .someCurrentFolder)
|
let task = CreateRootFolderTask(fileService: FileServiceMock(
|
||||||
|
currentFolder: .someCurrentFolder
|
||||||
let task = CreateRootFolderTask(fileService: fileService)
|
))
|
||||||
|
|
||||||
// WHEN
|
// WHEN
|
||||||
// THEN
|
// THEN
|
||||||
|
Loading…
x
Reference in New Issue
Block a user