Phase 2 aus dem Native-Auth-Vollausbau-Plan (Option A, siehe ../mana/docs/MANA_SWIFT.md). Entstanden weil drei Apps fast- byte-identische LoginView.swift hatten und Sign-Up/Forgot-PW komplett fehlten. ManaAuthUI-Library mit: - ManaBrandConfig — App-injizierte Theme-Werte (forest für Cards/ Manaspur, mana-default für Memoro), Environment-Key, View-Modifier - Base-Components: ManaAuthScaffold, ManaPrimaryButton, ManaTextField, ManaSecureField + .manaEmailField()-Modifier - ManaLoginView + LoginViewModel — Email/PW-Login, schaltet bei AuthError.emailNotVerified automatisch auf ManaEmailVerifyGateView - ManaSignUpView + SignUpViewModel — Email/Name/PW + awaiting- Verification-Hinweis-Screen - ManaEmailVerifyGateView + ViewModel — Resend-Verification - ManaForgotPasswordView + ViewModel — Reset-Mail anfordern (immer generischer Hinweis, User-Enumeration-Schutz) - ManaResetPasswordView + ViewModel — neues PW mit Token aus Universal-Link - ManaChangeEmailView, ManaChangePasswordView, ManaDeleteAccountView + internal ViewModels — Account-Bausteine - ManaDeleteAccountView ist zweistufig (Bestätigungs-Wort tippen + Passwort) → App-Store-Guideline 5.1.1(v) Pflicht-Surface 26/26 ViewModel-Tests grün via per-test-ID URLProtocol-Routing (löst Parallel-Pollution zwischen .serialized Suites). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
97 lines
3.3 KiB
Swift
97 lines
3.3 KiB
Swift
import Foundation
|
|
import ManaCore
|
|
import Testing
|
|
@testable import ManaAuthUI
|
|
|
|
@Suite("ForgotPasswordViewModel + ResetPasswordViewModel")
|
|
@MainActor
|
|
struct ForgotResetViewModelTests {
|
|
// MARK: - ForgotPassword
|
|
|
|
@Test("forgotPassword erfolgreich → .sent")
|
|
func forgotSuccess() async {
|
|
let mocked = makeMockedAuth()
|
|
let model = ForgotPasswordViewModel(
|
|
auth: mocked.auth,
|
|
resetUniversalLink: URL(string: "https://cardecky.mana.how/auth/reset")!
|
|
)
|
|
model.email = "u@x.de"
|
|
|
|
let captured = MockURLProtocol.Capture()
|
|
mocked.setHandler { request in
|
|
captured.store(request)
|
|
return (200, Data(#"{"success":true}"#.utf8))
|
|
}
|
|
|
|
await model.submit()
|
|
#expect(model.status == .sent)
|
|
#expect(captured.request?.url?.path == "/api/v1/auth/forgot-password")
|
|
}
|
|
|
|
@Test("forgotPassword leere Email → canSubmit false")
|
|
func forgotGuards() {
|
|
let model = ForgotPasswordViewModel(
|
|
auth: makeMockedAuth().auth,
|
|
resetUniversalLink: URL(string: "https://x.test/auth/reset")!
|
|
)
|
|
#expect(model.canSubmit == false)
|
|
model.email = "u@x.de"
|
|
#expect(model.canSubmit == true)
|
|
}
|
|
|
|
// MARK: - ResetPassword
|
|
|
|
@Test("resetPassword erfolgreich → .done")
|
|
func resetSuccess() async {
|
|
let mocked = makeMockedAuth()
|
|
let model = ResetPasswordViewModel(token: "tok123", auth: mocked.auth)
|
|
model.newPassword = "Neu-987654321"
|
|
model.confirmPassword = "Neu-987654321"
|
|
|
|
mocked.setHandler { _ in (200, Data(#"{"success":true}"#.utf8)) }
|
|
|
|
await model.submit()
|
|
#expect(model.status == .done)
|
|
#expect(model.newPassword == "")
|
|
#expect(model.confirmPassword == "")
|
|
}
|
|
|
|
@Test("resetPassword mit abgelaufenem Token → .error")
|
|
func resetTokenExpired() async {
|
|
let mocked = makeMockedAuth()
|
|
let model = ResetPasswordViewModel(token: "old", auth: mocked.auth)
|
|
model.newPassword = "Neu-987654321"
|
|
model.confirmPassword = "Neu-987654321"
|
|
|
|
mocked.setHandler { _ in
|
|
(400, Data(#"{"error":"TOKEN_EXPIRED","status":400}"#.utf8))
|
|
}
|
|
|
|
await model.submit()
|
|
if case let .error(message) = model.status {
|
|
#expect(message == "Der Link ist abgelaufen. Bitte fordere einen neuen an.")
|
|
} else {
|
|
Issue.record("Expected .error, got \(model.status)")
|
|
}
|
|
}
|
|
|
|
@Test("resetPassword validationHint bei Mismatch")
|
|
func resetMismatch() {
|
|
let model = ResetPasswordViewModel(token: "t", auth: makeMockedAuth().auth)
|
|
model.newPassword = "lang-genug"
|
|
model.confirmPassword = "anders-lang"
|
|
#expect(model.validationHint == "Die Passwörter stimmen nicht überein.")
|
|
#expect(model.canSubmit == false)
|
|
}
|
|
|
|
@Test("resetPassword canSubmit erfordert ≥8 Zeichen und Match")
|
|
func resetCanSubmit() {
|
|
let model = ResetPasswordViewModel(token: "t", auth: makeMockedAuth().auth)
|
|
model.newPassword = "kurz"
|
|
model.confirmPassword = "kurz"
|
|
#expect(model.canSubmit == false)
|
|
model.newPassword = "lang-genug"
|
|
model.confirmPassword = "lang-genug"
|
|
#expect(model.canSubmit == true)
|
|
}
|
|
}
|