Implemented the "copyItem(from: to: )" function for the FileService service in the library target.

This commit is contained in:
2025-01-14 23:52:33 +01:00
parent 26fde119ef
commit 489cf3d780
5 changed files with 73 additions and 0 deletions
@@ -26,6 +26,45 @@ struct FileServiceTests {
// MARK: Functions tests
@Test(arguments: zip([URL.someExistingFile, .someExistingFolder],
[URL.someNewFile, .someNewFolder]))
func copyItem(from source: URL, to destination: URL) async throws {
// GIVEN
let service = FileServiceMock(
currentFolder: .someCurrentFolder,
action: .copyItem(source, destination),
spy: spy
)
// WHEN
try await service.copyItem(from: source, to: destination)
// THENn
#expect(spy.actions.count == 1)
let action = try #require(spy.actions.last)
#expect(action == .itemCopied(source, destination))
}
@Test(arguments: [FileServiceError.itemNotExists, .itemAlreadyExists, .itemNotCopied])
func copyItem(throws error: FileServiceError) async throws {
// GIVEN
let service = FileServiceMock(
currentFolder: .someCurrentFolder,
action: .error(error),
spy: spy
)
// WHEN
// THEN
await #expect(throws: error) {
try await service.copyItem(from: .someExistingFile, to: .someNewFile)
}
#expect(spy.actions.isEmpty == true)
}
@Test(arguments: [URL.someNewFolder, .someNewFile])
func createFolder(with location: URL) async throws {
// GIVEN