Added the catalogue models and seed to support phase 2 of the POC prototype in the Persistence package.

This commit is contained in:
javier committed 2026-09-21 11:44:41 +02:00
1 parent ea89ea892a
commit 09c7b8a1a7
10 files changed
+238 -21

No files matched your search

@@ -0,0 +1,35 @@
import Testing
@testable import Persistence
@Suite(
"AccountRepository repository",
.tags(.repository)
)
struct AccountRepositoryTests {
// MARK: Methods tests
@Test
func `finds the seeded demo buyer`() async throws {
try await withDatabase { fluent in
let user = try await AccountRepository(fluent: fluent).account(email: AccountRepository.demoEmail)
#expect(user.email == "mara.v@example.com")
#expect(user.displayName == "Mara Visser")
}
}
@Test
func `joins an unknown email once, named after its local part`() async throws {
try await withDatabase { fluent in
let repository = AccountRepository(fluent: fluent)
let joined = try await repository.account(email: "sam@example.com")
let returning = try await repository.account(email: "sam@example.com")
#expect(joined.displayName == "sam")
#expect(returning == joined)
}
}
}
@@ -78,27 +78,13 @@ struct CatalogueRepositoryTests {
private extension CatalogueRepositoryTests {
/// Runs the body against a migrated, seeded in-memory catalogue, shutting the pool down after.
/// Runs the body against a migrated, seeded in-memory catalogue.
func withCatalogue(
_ body: (CatalogueRepository) async throws -> Void
) async throws {
let fluent = try Service(
driver: .inMemory,
logger: Logger(label: "test")
)()
do {
await PrepareDB()(for: fluent)
try await fluent.migrate()
try await body(.init(fluent: fluent))
} catch {
try? await fluent.shutdown()
throw error
try await withDatabase {
try await body(.init(fluent: $0))
}
try await fluent.shutdown()
}
}