Restructured the folder structure of the test target.

This commit is contained in:
2025-01-17 23:23:10 +01:00
parent 04bd2a1160
commit 640683063e
9 changed files with 4 additions and 2 deletions
@@ -0,0 +1,43 @@
import Foundation
import Testing
@testable import ColibriLibrary
struct CopyFilesTaskTests {
// MARK: Properties
private let spy = FileServiceSpy()
// MARK: Functions tests
@Test(arguments: zip([URL.someExistingFolder], [URL.someNewFolder]))
func copyFiles(from source: URL, to destination: URL) async throws {
// GIVEN
let filesToCopy = CopyFilesTask.filesToCopy
let destinations = filesToCopy.map { destination.appendingPath($0) }
let sources = filesToCopy.map { source.appendingPath($0) }
let actions = filesToCopy.indices.map { index -> FileServiceMock.Action in
.copyItem(sources[index], destinations[index])
}
let service = FileServiceMock(
currentFolder: .someCurrentFolder,
actions: actions,
spy: spy
)
let copyFiles = CopyFilesTask(fileService: service)
// WHEN
try await copyFiles(to: destination)
// THEN
#expect(spy.actions.count == actions.count)
for index in actions.indices {
#expect(spy.actions[index] == .itemCopied(sources[index], destinations[index]))
}
}
}
@@ -0,0 +1,37 @@
import Foundation
import Testing
@testable import ColibriLibrary
struct CreateFoldersTaskTests {
// MARK: Properties
private let spy = FileServiceSpy()
// MARK: Functions tests
@Test(arguments: [URL.someCurrentFolder, .someDotFolder, .someTildeFolder])
func createFolders(with rootFolder: URL) async throws {
// GIVEN
let folders = CreateFoldersTask.foldersToCreate.map { rootFolder.appendingPath($0) }
let actions: [FileServiceMock.Action] = folders.map { .createFolder($0) }
let service = FileServiceMock(
currentFolder: .someCurrentFolder,
actions: actions,
spy: spy
)
let createFolders = CreateFoldersTask(fileService: service)
// WHEN
try await createFolders(at: rootFolder)
// THEN
for index in actions.indices {
#expect(spy.actions[index] == .folderCreated(folders[index]))
}
}
}
@@ -0,0 +1,92 @@
import Foundation
import Testing
@testable import ColibriLibrary
struct CreateRootFolderTaskTests {
// MARK: Functions tests
@Test(arguments: [String.someProjectName], [URL.someCurrentProjectFolder, .someNewProjectFolder, .someDotProjectFolder, .someTildeProjectFolder])
func task(
name: String,
expects folder: URL
) async throws {
// GIVEN
let location: URL? = switch folder {
case .someNewProjectFolder: .someNewFolder
case .someDotProjectFolder: .someDotFolder
case .someTildeProjectFolder: .someTildeFolder
default: nil
}
let fileService = FileServiceMock(
currentFolder: .someCurrentFolder,
action: .createFolder(folder)
)
let task = CreateRootFolderTask(fileService: fileService)
// WHEN
let result = try await task(name: name,
at: location)
// THEN
#expect(result == folder)
#expect(result.isFileURL == true)
}
@Test(arguments: [String.someProjectName], [FileServiceError.itemAlreadyExists])
func task(
name: String,
throws error: FileServiceError
) async throws {
// GIVEN
let fileService = FileServiceMock(
currentFolder: .someCurrentFolder,
action: .error(error)
)
let task = CreateRootFolderTask(fileService: fileService)
// WHEN
// THEN
await #expect(throws: error) {
try await task(name: name)
}
}
@Test(arguments: [String.someEmptyName], [CreateRootFolderError.nameIsEmpty])
func task(
name: String,
throws error: CreateRootFolderError
) async throws {
// GIVEN
let fileService = FileServiceMock(currentFolder: .someCurrentFolder)
let task = CreateRootFolderTask(fileService: fileService)
// WHEN
// THEN
await #expect(throws: error) {
try await task(name: name)
}
}
}
// MARK: - String+Constants
private extension String {
static let someEmptyName = ""
static let someProjectName = "SomeProjectName"
}
// MARK: - URL+Constants
private extension URL {
static let someCurrentProjectFolder = URL.someCurrentFolder.appendingPath(.someProjectName)
static let someDotProjectFolder = URL.someDotFolder.appendingPath(.someProjectName)
static let someNewProjectFolder = URL.someNewFolder.appendingPath(.someProjectName)
static let someTildeProjectFolder = URL.someTildeFolder.appendingPath(.someProjectName)
}