Bringt cards-native auf 0 SwiftLint-Violations bei 75 Files. Build-Status
unverändert grün (xcodebuild iOS Debug).
.swiftlint.yml
- identifier_name excludes erweitert um math/index-Konventionen
(i, j, n, m, x, y, w, h, r, g, b, a, c, d, s, f, p, q, t, l) —
in algorithmischem Code klarer als verbose
- opening_brace disabled — kollidiert mit SwiftFormats
wrapMultilineStatementBraces (SwiftFormat ist im Pre-Commit-Hook
und gewinnt)
Code-Modernisierungen (real, nicht nur Annotations)
- Cloze.swift: regex-Tuple bekommt `swiftlint:disable large_tuple`-
Region — Regex-Output-Type ist Builder-bedingt nicht reduzierbar
- Media.swift: `data(using: .utf8)` → `Data(s.utf8)` (non-failable),
`String(data:as:)` → `String(bytes:encoding:)`
- CardsTheme.swift: HSL-Wert-Typ statt anonymes 3-Tupel —
konkretere Call-Sites, kein `large_tuple`-Warning mehr
- MediaCache.swift: `CacheEntry`-Struct statt 3-Tupel im Prune-Pfad
- GradeQueue / MediaCache / StudySession / MarketplaceStore: OSLog-
Interpolations auf lokale Variablen ziehen — fixt Swift-6-Strict-
Concurrency-Fail bei Actor-isolated-Property-Zugriff aus
@Sendable-Autoclosure
- DeckMutations.swift, MarketplaceModeration.swift: verschachtelte
VersionInfo-Sub-Types auf Top-Level (`PullUpdateVersion`,
`OwnedMarketplaceVersion`) — fixt `nesting`-Warning
- Tests/UnitTests/*.swift: alle `""".data(using: .utf8)!` migriert auf
`Data("""…""".utf8)`; force-cast `as!` in MutationEncodingTests
durch guard-let + throw ersetzt
Pragmatische Disables (mit Doc-Comment-Begründung)
- DeckEditorView / MarketplacePublishView / DeckDetailView /
PublicDeckView / DeckListView / CardEditorView / CardsAPI:
`swiftlint:disable type_body_length` (+ teilweise file_length)
als Region-Disable mit `enable` nach dem Struct. Begründung im
Doc-Comment: Multi-State-Maschinen mit shared Toolbar + Sheets;
Aufspalten würde nur @Binding-Plumbing produzieren
Auto-Format-Aufräumung
- Redundante `Sendable`-Conformance entfernt (Swift 6 leitet das
bei Wert-Typen mit Sendable-Mitgliedern automatisch ab)
- EnvironmentValues nutzt jetzt @Entry-Macro statt manueller
EnvironmentKey-Boilerplate
- Brace-Reformatting + Import-Sortierung auf allen 75 Files
Ergebnis: 80 Warnings + 3 Errors → 0 / 0.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
121 lines
3.9 KiB
Swift
121 lines
3.9 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 = Data("""
|
|
{
|
|
"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
|
|
}
|
|
}
|
|
""".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 = Data("""
|
|
{
|
|
"featured": [],
|
|
"trending": []
|
|
}
|
|
""".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 = Data("""
|
|
{
|
|
"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
|
|
}
|
|
""".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 = Data("""
|
|
{
|
|
"subscribed": true,
|
|
"deck_slug": "english-a2",
|
|
"current_version_id": "v_1",
|
|
"private_deck_id": "private_deck_xyz"
|
|
}
|
|
""".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")
|
|
}
|
|
}
|