Beim Öffnen eines Marketplace-Decks crashed JSON-Decoder mit typeMismatch (Expected String, found Bool) auf owner.pseudonym. Ursache: Server-Schema (cards/apps/api/src/db/schema/marketplace/ authors.ts) hat pseudonym als `boolean NOT NULL DEFAULT false` — ein Flag, dass der Autor pseudonym auftritt (Anzeigename verbergen). Native hatte das fälschlich als String? (Anzeige-Pseudonym) interpretiert. Fix: - PublicDeckOwner.pseudonym: String? → Bool - decoder.decodeIfPresent(String.self) → decode(Bool.self) ?? false - Test-Fixture: "pseudonym": null → "pseudonym": false Build 3 → 4. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
121 lines
4 KiB
Swift
121 lines
4 KiB
Swift
import Foundation
|
|
import Testing
|
|
@testable import CardsNative
|
|
|
|
@Suite("Marketplace-JSON-Decoding")
|
|
struct MarketplaceDecodingTests {
|
|
private func decoder() -> JSONDecoder {
|
|
let d = JSONDecoder()
|
|
d.dateDecodingStrategy = .iso8601withFractional
|
|
return d
|
|
}
|
|
|
|
@Test("PublicDeckEntry aus Browse-Response")
|
|
func decodesPublicDeckEntry() throws {
|
|
let json = """
|
|
{
|
|
"slug": "geografie-welt-top30",
|
|
"title": "Geografie Welt Top 30",
|
|
"description": "Hauptstädte",
|
|
"language": "de",
|
|
"category": "geography",
|
|
"license": "CC0-1.0",
|
|
"price_credits": 0,
|
|
"card_count": 30,
|
|
"star_count": 12,
|
|
"subscriber_count": 5,
|
|
"is_featured": true,
|
|
"created_at": "2026-05-08T10:00:00.000Z",
|
|
"owner": {
|
|
"slug": "mana-curators",
|
|
"display_name": "mana-Kuratoren",
|
|
"verified_mana": true,
|
|
"verified_community": false,
|
|
"pseudonym": false
|
|
}
|
|
}
|
|
""".data(using: .utf8)!
|
|
|
|
let entry = try decoder().decode(PublicDeckEntry.self, from: json)
|
|
#expect(entry.slug == "geografie-welt-top30")
|
|
#expect(entry.cardCount == 30)
|
|
#expect(entry.isFeatured == true)
|
|
#expect(entry.isPaid == false)
|
|
#expect(entry.owner.verifiedMana == true)
|
|
}
|
|
|
|
@Test("ExploreResponse mit featured + trending")
|
|
func decodesExploreResponse() throws {
|
|
let json = """
|
|
{
|
|
"featured": [],
|
|
"trending": []
|
|
}
|
|
""".data(using: .utf8)!
|
|
let res = try decoder().decode(ExploreResponse.self, from: json)
|
|
#expect(res.featured.isEmpty)
|
|
#expect(res.trending.isEmpty)
|
|
}
|
|
|
|
@Test("PublicDeckDetail mit camelCase 'latest_version'")
|
|
func decodesPublicDeckDetail() throws {
|
|
let json = """
|
|
{
|
|
"deck": {
|
|
"id": "deck_1",
|
|
"slug": "english-a2",
|
|
"title": "English A2",
|
|
"description": null,
|
|
"language": "en",
|
|
"category": "language",
|
|
"license": "CC-BY-4.0",
|
|
"price_credits": 0,
|
|
"owner_user_id": "user_1",
|
|
"latest_version_id": "v_1",
|
|
"is_featured": false,
|
|
"is_takedown": false,
|
|
"created_at": "2026-05-01T00:00:00.000Z"
|
|
},
|
|
"latest_version": {
|
|
"id": "v_1",
|
|
"deck_id": "deck_1",
|
|
"semver": "1.0.0",
|
|
"changelog": "Initial release",
|
|
"content_hash": "abc",
|
|
"card_count": 500,
|
|
"published_at": "2026-05-01T00:00:00.000Z",
|
|
"deprecated_at": null
|
|
},
|
|
"owner": null
|
|
}
|
|
""".data(using: .utf8)!
|
|
|
|
let detail = try decoder().decode(PublicDeckDetail.self, from: json)
|
|
#expect(detail.deck.slug == "english-a2")
|
|
#expect(detail.latestVersion?.semver == "1.0.0")
|
|
#expect(detail.latestVersion?.cardCount == 500)
|
|
#expect(detail.owner == nil)
|
|
}
|
|
|
|
@Test("SubscribeResponse mit private_deck_id")
|
|
func decodesSubscribeResponse() throws {
|
|
let json = """
|
|
{
|
|
"subscribed": true,
|
|
"deck_slug": "english-a2",
|
|
"current_version_id": "v_1",
|
|
"private_deck_id": "private_deck_xyz"
|
|
}
|
|
""".data(using: .utf8)!
|
|
let res = try decoder().decode(SubscribeResponse.self, from: json)
|
|
#expect(res.subscribed == true)
|
|
#expect(res.privateDeckId == "private_deck_xyz")
|
|
}
|
|
|
|
@Test("MarketplaceSort-Werte sind exakt wie API erwartet")
|
|
func sortRawValues() {
|
|
#expect(MarketplaceSort.recent.rawValue == "recent")
|
|
#expect(MarketplaceSort.popular.rawValue == "popular")
|
|
#expect(MarketplaceSort.trending.rawValue == "trending")
|
|
}
|
|
}
|