feat: Adds script to generate database seeded values and removes old mock storage.

This commit is contained in:
2025-01-16 21:00:27 -05:00
parent 09b46f672a
commit e1d07008a1
16 changed files with 399 additions and 535 deletions

View File

@@ -28,66 +28,3 @@ extension User.Update: Content {}
extension DatabaseClient.Users: TestDependencyKey {
public static let testValue: DatabaseClient.Users = Self()
}
#if DEBUG
typealias UserMockStorage = MockStorage<
User,
User.Create,
Void,
Void,
User.Update
>
private extension UserMockStorage {
static func make(_ mocks: [User]) -> Self {
@Dependency(\.date.now) var now
@Dependency(\.uuid) var uuid
return .init(
create: { model in
User(
id: uuid(),
email: model.email,
username: model.username,
createdAt: now,
updatedAt: now
)
},
update: { model, updates in
let user = User(
id: model.id,
email: updates.email ?? model.email,
username: updates.username ?? model.username,
createdAt: model.createdAt,
updatedAt: now
)
model = user
}
)
}
}
public extension User.Token {
static func mock(id: User.ID) -> Self {
.init(id: UUID(0), userID: id, value: "test")
}
}
public extension DatabaseClient.Users {
static func mock(_ mocks: [User]) -> Self {
let storage = UserMockStorage.make(mocks)
return .init(
count: { try await storage.count() },
create: { try await storage.create($0) },
delete: { try await storage.delete($0) },
fetchAll: { try await storage.fetchAll() },
get: { try await storage.get($0) },
login: { _ in .mock(id: UUID(0)) },
logout: { _ in },
token: { .mock(id: $0) },
update: { try await storage.update($0, $1) }
)
}
}
#endif