Code + Identity-Rename zur Vorbereitung auf Apple-Dev-Portal-Aktion (Bundle ev.mana.wordeck, App-Group group.ev.mana.wordeck, AASA applinks:wordeck.com). Build bleibt funktional, aber gegen die neue text-only-API können image-occlusion-Creates 422 zurückgeben — das wird mit der Wordeck-Native v1.0-Welle (parallele Apple-Aktion) sauber gemacht. Umbenennung: - 41 Files: cardecky/Cardecky → wordeck/Wordeck (Display, Strings, Kommentare) - 57 Files: CardsNative → WordeckNative, CardsAPI → WordeckAPI, CardsTheme → WordeckTheme, CardsBrand → WordeckBrand, CardsWidget → WordeckWidget, CardsDueWidget → WordeckDueWidget - Bundle-ID ev.mana.cardecky → ev.mana.wordeck (project.yml, Info.plist, entitlements, Keychain-Service, App-Group) - AASA applinks:cardecky.mana.how → applinks:wordeck.com - API-Base cardecky-api.mana.how → api.wordeck.com - 10 Files renamed (App-Entry, API-Extensions, Theme, Widget, Entitlements, Tests) - xcodeproj regenerated via xcodegen → WordeckNative.xcodeproj - MaskRegionsTests.swift gelöscht (image-occlusion entfällt mit Wordeck text-only) Forgejo-Repo git.mana.how/till/cards-native → wordeck-native umbenannt (Auto-Redirect aktiv). Lokales Verzeichnis Code/cards-native/ bleibt vorerst — wird beim nächsten Apple-Setup mit Bundle-Test umbenannt. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
107 lines
3.7 KiB
Swift
107 lines
3.7 KiB
Swift
import Foundation
|
|
import Testing
|
|
@testable import WordeckNative
|
|
|
|
@Suite("Mutation Body Encoding")
|
|
struct MutationEncodingTests {
|
|
private func encode(_ value: some Encodable) throws -> [String: Any] {
|
|
let data = try JSONEncoder().encode(value)
|
|
guard let dict = try JSONSerialization.jsonObject(with: data) as? [String: Any] else {
|
|
throw EncodeError.notADictionary
|
|
}
|
|
return dict
|
|
}
|
|
|
|
private enum EncodeError: Error {
|
|
case notADictionary
|
|
}
|
|
|
|
@Test("DeckCreateBody nutzt snake_case und lässt nil weg")
|
|
func deckCreateBody() throws {
|
|
let body = DeckCreateBody(
|
|
name: "Spanisch",
|
|
description: nil,
|
|
color: "#10803D",
|
|
category: .language,
|
|
visibility: .private
|
|
)
|
|
let json = try encode(body)
|
|
#expect(json["name"] as? String == "Spanisch")
|
|
#expect(json["color"] as? String == "#10803D")
|
|
#expect(json["category"] as? String == "language")
|
|
#expect(json["visibility"] as? String == "private")
|
|
// description war nil — sollte nicht im JSON sein
|
|
#expect(json["description"] == nil)
|
|
}
|
|
|
|
@Test("DeckUpdateBody kann archived: true setzen")
|
|
func deckUpdateBodyArchived() throws {
|
|
let body = DeckUpdateBody(archived: true)
|
|
let json = try encode(body)
|
|
#expect(json["archived"] as? Bool == true)
|
|
#expect(json["name"] == nil)
|
|
}
|
|
|
|
@Test("CardCreateBody für basic-Type")
|
|
func cardCreateBodyBasic() throws {
|
|
let body = CardCreateBody(
|
|
deckId: "deck_1",
|
|
type: .basic,
|
|
fields: CardFieldsBuilder.basic(front: "Hallo", back: "Hello"),
|
|
mediaRefs: nil
|
|
)
|
|
let json = try encode(body)
|
|
#expect(json["deck_id"] as? String == "deck_1")
|
|
#expect(json["type"] as? String == "basic")
|
|
let fields = json["fields"] as? [String: String]
|
|
#expect(fields?["front"] == "Hallo")
|
|
#expect(fields?["back"] == "Hello")
|
|
#expect(json["media_refs"] == nil)
|
|
}
|
|
|
|
@Test("CardCreateBody für basic-reverse Type-Name")
|
|
func cardCreateBodyBasicReverse() throws {
|
|
let body = CardCreateBody(
|
|
deckId: "d",
|
|
type: .basicReverse,
|
|
fields: CardFieldsBuilder.basic(front: "a", back: "b"),
|
|
mediaRefs: nil
|
|
)
|
|
let json = try encode(body)
|
|
#expect(json["type"] as? String == "basic-reverse")
|
|
}
|
|
|
|
@Test("CardCreateBody für cloze")
|
|
func cardCreateBodyCloze() throws {
|
|
let body = CardCreateBody(
|
|
deckId: "d",
|
|
type: .cloze,
|
|
fields: CardFieldsBuilder.cloze(text: "Die {{c1::Sonne}} scheint."),
|
|
mediaRefs: nil
|
|
)
|
|
let json = try encode(body)
|
|
#expect(json["type"] as? String == "cloze")
|
|
let fields = json["fields"] as? [String: String]
|
|
#expect(fields?["text"] == "Die {{c1::Sonne}} scheint.")
|
|
}
|
|
|
|
@Test("CardCreateBody multiple-choice Type-Name")
|
|
func cardCreateBodyMultipleChoice() throws {
|
|
let body = CardCreateBody(
|
|
deckId: "d",
|
|
type: .multipleChoice,
|
|
fields: CardFieldsBuilder.multipleChoice(front: "Q", answer: "A"),
|
|
mediaRefs: nil
|
|
)
|
|
let json = try encode(body)
|
|
#expect(json["type"] as? String == "multiple-choice")
|
|
}
|
|
|
|
@Test("CardUpdateBody nur mit fields")
|
|
func cardUpdateBodyFieldsOnly() throws {
|
|
let body = CardUpdateBody(fields: ["front": "neu"], mediaRefs: nil)
|
|
let json = try encode(body)
|
|
#expect((json["fields"] as? [String: String])?["front"] == "neu")
|
|
#expect(json["media_refs"] == nil)
|
|
}
|
|
}
|