FeedbackSubmission.images (base64, ohne data:-Praefix, 1:1 zum Web- und
Android-Vertrag); FeedbackClient-Payload sendet images:[{mime,b64}].
Additiv. Test deckt Bild-Payload ab.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
81 lines
3 KiB
Swift
81 lines
3 KiB
Swift
import Foundation
|
|
import Testing
|
|
@testable import ManaCore
|
|
|
|
@Suite("FeedbackClient")
|
|
struct FeedbackClientTests {
|
|
@Test("Payload enthält Pflichtfelder + Honeypot, spiegelt den Web-Vertrag")
|
|
func payloadCoreFields() {
|
|
let client = FeedbackClient(appId: "memoro")
|
|
let payload = client.payload(
|
|
for: FeedbackSubmission(kind: .bug, title: "Titel", description: "Beschreibung")
|
|
)
|
|
|
|
#expect(payload["kind"] as? String == "bug")
|
|
#expect(payload["appId"] as? String == "memoro")
|
|
#expect(payload["title"] as? String == "Titel")
|
|
#expect(payload["description"] as? String == "Beschreibung")
|
|
#expect(payload["_hp"] as? String == "")
|
|
#expect(payload["platform"] as? String == FeedbackPlatform.current.rawValue)
|
|
#expect(payload["appVersion"] != nil)
|
|
#expect(payload["context"] is [String: String])
|
|
|
|
// Anonyme Felder weglassen, wenn nicht gesetzt.
|
|
#expect(payload["contactEmail"] == nil)
|
|
#expect(payload["guestName"] == nil)
|
|
}
|
|
|
|
@Test("Anonyme Kontakt-Felder nur wenn gesetzt")
|
|
func payloadAnonFields() {
|
|
let client = FeedbackClient(appId: "manameme")
|
|
let payload = client.payload(
|
|
for: FeedbackSubmission(
|
|
kind: .feedback,
|
|
title: "T",
|
|
description: "D",
|
|
contactEmail: "a@b.de",
|
|
guestName: "Gast"
|
|
)
|
|
)
|
|
#expect(payload["contactEmail"] as? String == "a@b.de")
|
|
#expect(payload["guestName"] as? String == "Gast")
|
|
}
|
|
|
|
@Test("Bilder erscheinen als [{mime,b64}], fehlen wenn leer")
|
|
func payloadImages() {
|
|
let client = FeedbackClient(appId: "memoro")
|
|
// Ohne Bilder: kein images-Key.
|
|
let bare = client.payload(for: FeedbackSubmission(kind: .bug, title: "T", description: "D"))
|
|
#expect(bare["images"] == nil)
|
|
|
|
// Mit Bildern: Array von Dictionaries mit mime + b64 (reines base64).
|
|
let withImages = client.payload(
|
|
for: FeedbackSubmission(
|
|
kind: .bug,
|
|
title: "T",
|
|
description: "D",
|
|
images: [FeedbackImage(mime: "image/jpeg", b64: "QUJD")]
|
|
)
|
|
)
|
|
let images = withImages["images"] as? [[String: String]]
|
|
#expect(images?.count == 1)
|
|
#expect(images?.first?["mime"] == "image/jpeg")
|
|
#expect(images?.first?["b64"] == "QUJD")
|
|
}
|
|
|
|
@Test("Payload ist JSON-serialisierbar")
|
|
func payloadSerializable() throws {
|
|
let client = FeedbackClient(appId: "pageta")
|
|
let payload = client.payload(
|
|
for: FeedbackSubmission(kind: .wunsch, title: "T", description: "D")
|
|
)
|
|
let data = try JSONSerialization.data(withJSONObject: payload)
|
|
#expect(data.isEmpty == false)
|
|
}
|
|
|
|
@Test("Plattform ist ios oder macos zur Laufzeit")
|
|
func platformIsNative() {
|
|
let platform = FeedbackPlatform.current
|
|
#expect(platform == .ios || platform == .macos)
|
|
}
|
|
}
|