feat: Updates to use swift-validations for database.
All checks were successful
CI / Linux Tests (push) Successful in 6m28s
All checks were successful
CI / Linux Tests (push) Successful in 6m28s
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import DatabaseClient
|
||||
import Dependencies
|
||||
import Foundation
|
||||
import ManualDCore
|
||||
@@ -41,26 +40,6 @@ struct UserDatabaseTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func createUserFails() async throws {
|
||||
try await withDatabase {
|
||||
@Dependency(\.database.users) var users
|
||||
|
||||
await #expect(throws: ValidationError.self) {
|
||||
try await users.create(.init(email: "", password: "", confirmPassword: ""))
|
||||
}
|
||||
|
||||
await #expect(throws: ValidationError.self) {
|
||||
try await users.create(.init(email: "testy@example.com", password: "", confirmPassword: ""))
|
||||
}
|
||||
|
||||
await #expect(throws: ValidationError.self) {
|
||||
try await users.create(
|
||||
.init(email: "testy@example.com", password: "super-secret", confirmPassword: ""))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func deleteFailsWithInvalidUserID() async throws {
|
||||
try await withDatabase {
|
||||
@@ -148,4 +127,64 @@ struct UserDatabaseTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(
|
||||
arguments: [
|
||||
UserProfileModel(
|
||||
userID: UUID(0), firstName: "", lastName: "McTestface", companyName: "Acme Co.",
|
||||
streetAddress: "1234 Sesame St", city: "Nowhere", state: "CA", zipCode: "55555"
|
||||
),
|
||||
UserProfileModel(
|
||||
userID: UUID(0), firstName: "Testy", lastName: "", companyName: "Acme Co.",
|
||||
streetAddress: "1234 Sesame St", city: "Nowhere", state: "CA", zipCode: "55555"
|
||||
),
|
||||
UserProfileModel(
|
||||
userID: UUID(0), firstName: "Testy", lastName: "McTestface", companyName: "",
|
||||
streetAddress: "1234 Sesame St", city: "Nowhere", state: "CA", zipCode: "55555"
|
||||
),
|
||||
UserProfileModel(
|
||||
userID: UUID(0), firstName: "Testy", lastName: "McTestface", companyName: "Acme Co.",
|
||||
streetAddress: "", city: "Nowhere", state: "CA", zipCode: "55555"
|
||||
),
|
||||
UserProfileModel(
|
||||
userID: UUID(0), firstName: "Testy", lastName: "McTestface", companyName: "Acme Co.",
|
||||
streetAddress: "1234 Sesame St", city: "", state: "CA", zipCode: "55555"
|
||||
),
|
||||
UserProfileModel(
|
||||
userID: UUID(0), firstName: "Testy", lastName: "McTestface", companyName: "Acme Co.",
|
||||
streetAddress: "1234 Sesame St", city: "Nowhere", state: "", zipCode: "55555"
|
||||
),
|
||||
UserProfileModel(
|
||||
userID: UUID(0), firstName: "Testy", lastName: "McTestface", companyName: "Acme Co.",
|
||||
streetAddress: "1234 Sesame St", city: "Nowhere", state: "CA", zipCode: ""
|
||||
),
|
||||
]
|
||||
)
|
||||
func profileValidations(model: UserProfileModel) {
|
||||
var errors = [String]()
|
||||
#expect(throws: (any Error).self) {
|
||||
do {
|
||||
try model.validate()
|
||||
} catch {
|
||||
// Just checking to make sure I'm not testing the same error over and over /
|
||||
// making sure I've reset to good values / only testing one property at a time.
|
||||
#expect(!errors.contains("\(error)"))
|
||||
errors.append("\(error)")
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(
|
||||
arguments: [
|
||||
User.Create(email: "", password: "super-secret", confirmPassword: "super-secret"),
|
||||
User.Create(email: "testy@example.com", password: "", confirmPassword: "super-secret"),
|
||||
User.Create(email: "testy@example.com", password: "super-secret", confirmPassword: ""),
|
||||
User.Create(email: "testy@example.com", password: "super", confirmPassword: "super"),
|
||||
]
|
||||
)
|
||||
func userValidations(model: User.Create) {
|
||||
#expect(throws: (any Error).self) {
|
||||
try model.validate()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user