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

This commit is contained in:
javier committed 2026-09-21 11:16:30 +02:00
1 parent 717df5208c
commit 6d7ab4bcba
19 files changed
+1381 -151

No files matched your search

@@ -0,0 +1,91 @@
import Testing
@testable import Persistence
@Suite(
"ListingFilter model",
.tags(.model)
)
struct ListingFilterTests {
// MARK: Methods tests
@Test
func `matches every listing by default`() {
#expect(slugs(.init()).count == Seed.listings.count)
}
@Test
func `matches every word of the query across title, publisher, and shop`() {
#expect(slugs(.init(query: "NIGHTWARD kestrel")) == [
"nightward-1-cgc-9-8", "nightward-the-first-year-hc", "nightward-2-cgc-9-6",
])
#expect(slugs(.init(query: "no such book")).isEmpty)
}
@Test
func `matches the given formats`() {
#expect(slugs(.init(formats: ["manga"])) == ["hollow-comet-vol-4", "solar-divide-vol-1", "hollow-comet-vol-1"])
}
@Test
func `matches slabbed or raw copies`() {
#expect(slugs(.init(isSlabbed: true)).count == 5)
#expect(slugs(.init(formats: ["single-issues"], isSlabbed: false)).count == 8)
}
@Test
func `leaves ungraded listings out of a grade range`() {
#expect(slugs(.init(gradeMin: 9.6)) == ["nightward-1-cgc-9-8", "paper-tigers-1-variant-b", "nightward-2-cgc-9-6"])
#expect(slugs(.init(gradeMax: 7)) == ["vermilion-lake-7-cgc-6-5"])
}
@Test
func `matches a price range in cents`() {
#expect(slugs(.init(priceMin: 10_000, priceMax: 20_000)) == [
"nightward-1-cgc-9-4", "nightward-1-raw-nm", "ferrous-saint-1-cbcs-9-0",
])
}
@Test
func `matches where a listing ships from`() {
#expect(slugs(.init(shipsFrom: .nl)).count == 9)
#expect(slugs(.init(shipsFrom: .eu)).count == Seed.listings.count - 3)
}
@Test
func `matches the remaining flags`() {
#expect(slugs(.init(verifiedShops: true)).count == Seed.listings.count - 3)
#expect(slugs(.init(keysOnly: true)).count == 8)
#expect(slugs(.init(firstPrintOnly: true)).count == Seed.listings.count - 4)
#expect(slugs(.init(acceptsOffers: true)).count == 7)
#expect(slugs(.init(publishers: ["Cutwater Press"])) == ["paper-tigers-1-variant-b", "paper-tigers-2"])
#expect(slugs(.init(shop: "silverfish-comics")).count == 4)
}
@Test
func `orders ungraded listings last by grade`() {
let grades = Seed.listings
.sorted(by: ListingFilter(sort: .gradeDescending).ordersBefore)
.map(\.grade)
#expect(grades.first == 9.8)
#expect(grades.suffix(6).allSatisfy { $0 == nil })
}
}
// MARK: - Helpers
private extension ListingFilterTests {
/// The slugs of the demo listings the filter matches, in seed order.
func slugs(
_ filter: ListingFilter
) -> [String] {
Seed.listings
.filter(filter.matches)
.map(\.slug)
}
}