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
@@ -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
)
}
}