feat: Refactoring routes to use shared / base routes.

This commit is contained in:
2025-01-21 16:00:16 -05:00
parent 20e58114c0
commit 66074d66f4
15 changed files with 445 additions and 227 deletions

View File

@@ -107,6 +107,66 @@ final class ViewSnapshotTests: XCTestCase {
}
}
}
func testVendorViews() async throws {
try await withDependencies {
$0.database.vendors = .mock
} operation: {
@Dependency(\.database) var database
try await configure(app, makeDatabaseClient: { _ in database })
try app.test(.GET, router.path(for: .vendor(.form))) { res in
assertSnapshot(of: res.body.string, as: .html)
}
try app.test(.POST, router.path(for: .vendor(.index))) { req in
req.body = ByteBuffer(string: "name=Test")
} afterResponse: { res in
assertSnapshot(of: res.body.string, as: .html)
}
try app.test(.GET, router.path(for: .vendor(.index))) { res in
assertSnapshot(of: res.body.string, as: .html)
}
try app.test(.GET, router.path(for: .vendor(.get(id: UUID(0))))) { res in
assertSnapshot(of: res.body.string, as: .html)
}
try app.test(.PUT, router.path(for: .vendor(.update(id: UUID(0), updates: .mock)))) { req in
req.body = .init(string: "name=Test")
} afterResponse: { res in
assertSnapshot(of: res.body.string, as: .html)
}
}
}
func testVendorBranchViews() async throws {
try await withDependencies {
$0.database.vendorBranches = .mock
} operation: {
@Dependency(\.database) var database
try await configure(app, makeDatabaseClient: { _ in database })
try app.test(.GET, router.path(for: .vendorBranch(.index(for: UUID(0))))) { res in
assertSnapshot(of: res.body.string, as: .html)
}
for context in SharedModels.ViewRoute.SelectContext.allCases {
try app.test(.GET, router.path(for: .vendorBranch(.select(context: context)))) { res in
assertSnapshot(of: res.body.string, as: .html)
}
}
try app.test(.POST, router.path(for: .vendorBranch(.create(.mock)))) { req in
req.body = .init(string: "name=Test&vendorID=\(UUID(0))")
} afterResponse: { res in
assertSnapshot(of: res.body.string, as: .html)
}
}
}
}
extension DatabaseClient.Employees {
@@ -137,6 +197,31 @@ extension DatabaseClient.Users {
}
}
extension DatabaseClient.Vendors {
static var mock: Self {
.init(
create: { _ in Vendor.mock },
delete: { _ in },
fetchAll: { _ in [Vendor.mock] },
get: { _, _ in Vendor.mock },
update: { _, _, _ in Vendor.mock }
)
}
}
extension DatabaseClient.VendorBranches {
static var mock: Self {
.init(
create: { _ in VendorBranch.mock },
delete: { _ in },
fetchAll: { _ in [VendorBranch.mock] },
fetchAllWithDetail: { [VendorBranch.Detail.mock] },
get: { _ in VendorBranch.mock },
update: { _, _ in VendorBranch.mock }
)
}
}
extension Date {
static var mock: Self {
Date(timeIntervalSince1970: 1_234_567_890)
@@ -214,6 +299,12 @@ extension Vendor.Create {
}
}
extension Vendor.Update {
static var mock: Self {
.init(name: "Test")
}
}
extension VendorBranch {
static var mock: Self {
.init(id: UUID(1), name: "Mock", vendorID: UUID(0), createdAt: .mock, updatedAt: .mock)