feat: Removes old snapshots, adds user view snapshots.

This commit is contained in:
2025-01-21 13:13:01 -05:00
parent 07f7f7f957
commit 20e58114c0
13 changed files with 67 additions and 8 deletions

View File

@@ -73,6 +73,40 @@ final class ViewSnapshotTests: XCTestCase {
// assertSnapshot(of: res.body.string, as: .html)
// }
// }
func testUserViews() async throws {
try await withDependencies {
$0.database.users = .mock
} operation: {
@Dependency(\.database) var database
try await configure(app, makeDatabaseClient: { _ in database })
try app.test(.GET, router.path(for: .user(.form))) { res in
assertSnapshot(of: res.body.string, as: .html)
}
try app.test(.POST, router.path(for: .user(.index))) { req in
req.body = ByteBuffer(string: "username=test&email=test@test.com&password=super-secret&confirmPassword=super-secret")
} afterResponse: { res in
assertSnapshot(of: res.body.string, as: .html)
}
try app.test(.GET, router.path(for: .user(.index))) { res in
assertSnapshot(of: res.body.string, as: .html)
}
try app.test(.GET, router.path(for: .user(.get(id: UUID(0))))) { res in
assertSnapshot(of: res.body.string, as: .html)
}
try app.test(.PATCH, router.path(for: .user(.update(id: UUID(0), updates: .mock)))) { req in
req.body = .init(string: "username=test&email=test@test.com")
} afterResponse: { res in
assertSnapshot(of: res.body.string, as: .html)
}
}
}
}
extension DatabaseClient.Employees {
@@ -87,6 +121,22 @@ extension DatabaseClient.Employees {
}
}
extension DatabaseClient.Users {
static var mock: Self {
.init(
count: { 1 },
create: { _ in User.mock },
delete: { _ in },
fetchAll: { [User.mock] },
get: { _ in User.mock },
login: { _ in User.Token.mock },
logout: { _ in },
token: { _ in User.Token.mock },
update: { _, _ in User.mock }
)
}
}
extension Date {
static var mock: Self {
Date(timeIntervalSince1970: 1_234_567_890)
@@ -140,6 +190,18 @@ extension User.Create {
}
}
extension User.Token {
static var mock: Self {
.init(id: UUID(1), userID: UUID(0), value: "test-token")
}
}
extension User.Update {
static var mock: Self {
User.Update(username: "test", email: "test@test.com")
}
}
extension Vendor {
static var mock: Self {
.init(id: UUID(0), name: "Test", branches: nil, createdAt: .mock, updatedAt: .mock)