Implemented the "createFile(at: with: )" function for the FileService service in the library target.

This commit is contained in:
2025-02-07 21:50:50 +01:00
parent 3dcb110de1
commit 33ae67fc58
5 changed files with 78 additions and 9 deletions
@@ -35,7 +35,7 @@ struct FileServiceTests {
// WHEN
try await service.copyFile(from: source, to: destination)
// THENn
// THEN
#expect(spy.actions.count == 1)
let action = try #require(spy.actions.last)
@@ -57,6 +57,37 @@ struct FileServiceTests {
#expect(spy.actions.isEmpty == true)
}
@Test(arguments: zip([URL.someNewFile],
[Data("some data goes here...".utf8)]))
func createFile(with location: URL, and data: Data) async throws {
// GIVEN
let service = service(action: .createFile(location, data))
// WHEN
try await service.createFile(at: location, with: data)
// THEN
#expect(spy.actions.count == 1)
let action = try #require(spy.actions.last)
#expect(action == .fileCreated(location, data))
}
@Test(arguments: [FileServiceError.itemAlreadyExists, .fileDataIsEmpty, .fileNotCreated])
func createFile(throws error: FileServiceError) async throws {
// GIVEN
let service = service(action: .error(error))
// WHEN
// THEN
await #expect(throws: error) {
try await service.createFile(at: .someNewFile, with: .init())
}
#expect(spy.actions.isEmpty == true)
}
@Test(arguments: [URL.someNewFolder, .someNewFile])
func createFolder(with location: URL) async throws {
// GIVEN