Implemented the "actions" property for the FileServiceSpy spy in the tests target to support tracking multiple actions.

This commit is contained in:
2025-01-12 23:28:20 +01:00
parent a1ad391baa
commit 12151deea0
2 changed files with 35 additions and 27 deletions
@@ -39,8 +39,11 @@ struct FileServiceTests {
try await service.createFolder(at: url)
// THEN
#expect(spy.isCreateFolderCalled == true)
#expect(spy.urlCalled == url)
#expect(spy.actions.count == 1)
let action = try #require(spy.actions.last)
#expect(action == .folderCreated(url))
}
@Test(arguments: zip([URL.someExistingFolder, .someExistingFile, .someRandomURL],
@@ -61,9 +64,8 @@ struct FileServiceTests {
await #expect(throws: error) {
try await service.createFolder(at: url)
}
#expect(spy.isCreateFolderCalled == false)
#expect(spy.urlCalled == nil)
#expect(spy.actions.isEmpty == true)
}
@Test(arguments: [URL.someNewFolder, .someNewFile])
@@ -79,8 +81,11 @@ struct FileServiceTests {
try await service.delete(at: url)
// THEN
#expect(spy.isDeleteCalled == true)
#expect(spy.urlCalled == url)
#expect(spy.actions.count == 1)
let action = try #require(spy.actions.last)
#expect(action == .itemDeleted(url))
}
@Test(arguments: zip([URL.someNewFolder, .someNewFile, .someRandomURL],
@@ -102,8 +107,7 @@ struct FileServiceTests {
try await service.delete(at: url)
}
#expect(spy.isDeleteCalled == false)
#expect(spy.urlCalled == nil)
#expect(spy.actions.isEmpty == true)
}
@Test(arguments: zip([URL.someExistingFolder, .someExistingFile, .someNewFolder, .someNewFile],
@@ -125,8 +129,9 @@ struct FileServiceTests {
// THEN
#expect(result == outcome)
#expect(spy.isExistsAtCalled == true)
#expect(spy.urlCalled == url)
let action = try #require(spy.actions.last)
#expect(action == .itemExists(url))
}
@Test(arguments: zip([URL.someRandomURL], [FileServiceError.urlNotFileURL]))
@@ -147,8 +152,7 @@ struct FileServiceTests {
try await service.exists(at: url)
}
#expect(spy.isExistsAtCalled == false)
#expect(spy.urlCalled == nil)
#expect(spy.actions.isEmpty == true)
}
}