Improved upon the "listArchives(_: context: )" function for the ArchiveController controller in the library target.
This commit is contained in:
@@ -11,13 +11,20 @@ struct ArchiveControllerTests {
|
||||
// MARK: Properties
|
||||
|
||||
private let decoder: JSONDecoder = .init()
|
||||
|
||||
// MARK: Controller tests
|
||||
|
||||
@Test func xxx() async throws {
|
||||
@Test(arguments: zip([[String].folderWithArchives, .folderWithNoArchives, .folderEmpty],
|
||||
[[String].listWithArchives, .listWithNoArchives, .listWithNoArchives]))
|
||||
func getArchives(
|
||||
with archivesInFolder: [String],
|
||||
expects archivesInList: [String]
|
||||
) async throws {
|
||||
// GIVEN
|
||||
let fileService = FileServiceMock(items: ["SomeArchive.doccarchive", "some-file.txt"])
|
||||
let fileService = FileServiceMock(items: archivesInFolder)
|
||||
let router = Router()
|
||||
|
||||
ArchiveController("/path/to/archives/folder", fileService: fileService)
|
||||
ArchiveController(.Path.archivesFolder, fileService: fileService)
|
||||
.register(to: router)
|
||||
|
||||
let app = Application(router: router)
|
||||
@@ -25,21 +32,26 @@ struct ArchiveControllerTests {
|
||||
// WHEN
|
||||
// THEN
|
||||
try await app.test(.router) { client in
|
||||
try await client.execute(uri: "/archives", method: .get) { response in
|
||||
try await client.execute(uri: .Path.archivesResource, method: .get) { response in
|
||||
let archiveList = try decoder.decode(ArchiveList.self, from: response.body)
|
||||
|
||||
#expect(response.status == .ok)
|
||||
#expect(archiveList.archives == ["SomeArchive.doccarchive"])
|
||||
#expect(archiveList.archives == archivesInList)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test func yyy() async throws {
|
||||
@Test(arguments: zip([FileServiceError].errorFileService,
|
||||
[HTTPResponse.Status].errorResponse))
|
||||
func getArchives(
|
||||
with errorInFolder: FileServiceError,
|
||||
expects errorResponse: HTTPResponse.Status
|
||||
) async throws {
|
||||
// GIVEN
|
||||
let fileService = FileServiceMock(error: .folderNotFound)
|
||||
let fileService = FileServiceMock(error: errorInFolder)
|
||||
let router = Router()
|
||||
|
||||
ArchiveController("/path/to/archives/folder", fileService: fileService)
|
||||
ArchiveController(.Path.archivesFolder, fileService: fileService)
|
||||
.register(to: router)
|
||||
|
||||
let app = Application(router: router)
|
||||
@@ -47,10 +59,71 @@ struct ArchiveControllerTests {
|
||||
// WHEN
|
||||
// THEN
|
||||
try await app.test(.router) { client in
|
||||
try await client.execute(uri: "/archives", method: .get) { response in
|
||||
#expect(response.status == .ok)
|
||||
try await client.execute(uri: .Path.archivesResource, method: .get) { response in
|
||||
#expect(response.status == errorResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Collection+String
|
||||
|
||||
private extension Collection where Element == String {
|
||||
static var folderEmpty: [Element] {[]}
|
||||
static var folderWithArchives: [Element] {[
|
||||
".DS_Store",
|
||||
"SomeOtherArchive.doccarchive",
|
||||
"some-text.txt",
|
||||
"some-zipped-file.zip",
|
||||
"SomeArchive.doccarchive",
|
||||
"some-image.png",
|
||||
"AnotherArchive.doccarchive",
|
||||
"some-folder"
|
||||
]}
|
||||
static var folderWithNoArchives: [Element] {[
|
||||
".DS_Store",
|
||||
"some-text.txt",
|
||||
"some-zipped-file.zip",
|
||||
"some-image.png",
|
||||
"some-folder"
|
||||
]}
|
||||
static var listWithArchives: [Element] {[
|
||||
"AnotherArchive",
|
||||
"SomeArchive",
|
||||
"SomeOtherArchive"
|
||||
|
||||
]}
|
||||
static var listWithNoArchives: [Element] {[]}
|
||||
}
|
||||
|
||||
// MARK: - Collection+FileServiceError
|
||||
|
||||
private extension Collection where Element == FileServiceError {
|
||||
static var errorFileService: [Element] {[
|
||||
.folderPathEmpty,
|
||||
.folderNotFound,
|
||||
.folderNotDirectory,
|
||||
.other(NSError(domain: "", code: 0))
|
||||
]}
|
||||
}
|
||||
|
||||
// MARK: - Collection+HTTPResponseStatus
|
||||
|
||||
private extension Collection where Element == HTTPResponse.Status {
|
||||
static var errorResponse: [Element] {[
|
||||
.unprocessableContent,
|
||||
.notFound,
|
||||
.unprocessableContent,
|
||||
.badRequest
|
||||
]}
|
||||
}
|
||||
|
||||
// MARK: - String+Constants
|
||||
|
||||
private extension String {
|
||||
enum Path {
|
||||
static let archivesFolder: String = "/path/to/archives/folder"
|
||||
static let archivesResource: String = "/archives"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ struct AppBuilderTests {
|
||||
|
||||
private let appBuilder = AppBuilder(
|
||||
appName: "DoxyTest",
|
||||
archivesFolder: "Resources/Archives/Test"
|
||||
folderArchives: "Resources/Archives/Test"
|
||||
)
|
||||
private let arguments = TestArguments()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user