v0.2.0 — Phase β-1 Decks lesen
Deck-Liste mit Web-Parität: alle eigenen Decks aus cardecky-api, Card-/Due-Counts pro Deck (Web-Pattern: separate Calls), Pull-to- Refresh, Offline-Read via SwiftData, Inbox-Banner für Marketplace- Forks. - Deck-Codable-DTO mit snake_case-CodingKeys (DeckCategory, DeckVisibility, FsrsSettings) - ISO8601-Date-Decoder mit Fractional-Seconds-Toleranz - CardsAPI.listDecks() + cardCount() + dueCount() - CachedDeck SwiftData-Model mit lastFetchedAt - DeckListStore (API + Cache, paralleles Counts-Fetching via TaskGroup) - DeckListView mit forest-Theme, deck.color-Streifen, Inbox-Banner - AccountView mit Sign-out - DashboardView durch DeckListView ersetzt - 6 Unit-Tests + 1 UI-Test grün Phasen-Plan: mana/docs/playbooks/CARDS_NATIVE_GREENFIELD.md Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
28b20cd934
commit
f664a00b64
12 changed files with 809 additions and 85 deletions
105
Tests/UnitTests/DeckDecodingTests.swift
Normal file
105
Tests/UnitTests/DeckDecodingTests.swift
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
import Foundation
|
||||
import Testing
|
||||
@testable import CardsNative
|
||||
|
||||
@Suite("Deck-JSON-Decoding")
|
||||
struct DeckDecodingTests {
|
||||
@Test("Wire-Format aus toDeckDto decodet sauber")
|
||||
func decodesDeckFromWireFormat() throws {
|
||||
let json = """
|
||||
{
|
||||
"id": "01ARZ3NDEKTSV4RRFFQ69G5FAV",
|
||||
"user_id": "user_123",
|
||||
"name": "Spanisch A1",
|
||||
"description": "Grundwortschatz",
|
||||
"color": "#10803D",
|
||||
"category": "language",
|
||||
"visibility": "private",
|
||||
"fsrs_settings": {"request_retention": 0.9, "maximum_interval": 365},
|
||||
"content_hash": "abc123",
|
||||
"forked_from_marketplace_deck_id": null,
|
||||
"forked_from_marketplace_version_id": null,
|
||||
"archived_at": null,
|
||||
"created_at": "2026-05-12T10:30:00.123Z",
|
||||
"updated_at": "2026-05-12T15:45:00.456Z"
|
||||
}
|
||||
""".data(using: .utf8)!
|
||||
|
||||
let decoder = JSONDecoder()
|
||||
decoder.dateDecodingStrategy = .iso8601withFractional
|
||||
let deck = try decoder.decode(Deck.self, from: json)
|
||||
|
||||
#expect(deck.id == "01ARZ3NDEKTSV4RRFFQ69G5FAV")
|
||||
#expect(deck.name == "Spanisch A1")
|
||||
#expect(deck.description == "Grundwortschatz")
|
||||
#expect(deck.color == "#10803D")
|
||||
#expect(deck.category == .language)
|
||||
#expect(deck.visibility == .private)
|
||||
#expect(deck.isFromMarketplace == false)
|
||||
#expect(deck.archivedAt == nil)
|
||||
}
|
||||
|
||||
@Test("Marketplace-Forks werden erkannt")
|
||||
func recognizesMarketplaceFork() throws {
|
||||
let json = """
|
||||
{
|
||||
"id": "deck_456",
|
||||
"user_id": "user_123",
|
||||
"name": "Geografie",
|
||||
"description": null,
|
||||
"color": null,
|
||||
"category": null,
|
||||
"visibility": "private",
|
||||
"fsrs_settings": {},
|
||||
"content_hash": null,
|
||||
"forked_from_marketplace_deck_id": "mp_deck_789",
|
||||
"forked_from_marketplace_version_id": "mp_ver_1",
|
||||
"archived_at": null,
|
||||
"created_at": "2026-05-01T00:00:00.000Z",
|
||||
"updated_at": "2026-05-01T00:00:00.000Z"
|
||||
}
|
||||
""".data(using: .utf8)!
|
||||
|
||||
let decoder = JSONDecoder()
|
||||
decoder.dateDecodingStrategy = .iso8601withFractional
|
||||
let deck = try decoder.decode(Deck.self, from: json)
|
||||
|
||||
#expect(deck.isFromMarketplace == true)
|
||||
#expect(deck.forkedFromMarketplaceDeckId == "mp_deck_789")
|
||||
#expect(deck.category == nil)
|
||||
}
|
||||
|
||||
@Test("DeckListResponse-Wrapper")
|
||||
func decodesListResponse() throws {
|
||||
let json = """
|
||||
{
|
||||
"decks": [
|
||||
{
|
||||
"id": "d1",
|
||||
"user_id": "u1",
|
||||
"name": "Deck 1",
|
||||
"description": null,
|
||||
"color": null,
|
||||
"category": null,
|
||||
"visibility": "private",
|
||||
"fsrs_settings": {},
|
||||
"content_hash": null,
|
||||
"forked_from_marketplace_deck_id": null,
|
||||
"forked_from_marketplace_version_id": null,
|
||||
"archived_at": null,
|
||||
"created_at": "2026-01-01T00:00:00.000Z",
|
||||
"updated_at": "2026-01-01T00:00:00.000Z"
|
||||
}
|
||||
],
|
||||
"total": 1
|
||||
}
|
||||
""".data(using: .utf8)!
|
||||
|
||||
let decoder = JSONDecoder()
|
||||
decoder.dateDecodingStrategy = .iso8601withFractional
|
||||
let response = try decoder.decode(DeckListResponse.self, from: json)
|
||||
|
||||
#expect(response.total == 1)
|
||||
#expect(response.decks.first?.name == "Deck 1")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue