migration

This commit is contained in:
Daniel Arantes Loverde
2026-08-11 13:22:02 -03:00
parent c4d6998595
commit 7702836fe7
231 changed files with 4329 additions and 1958 deletions

View File

@@ -0,0 +1,85 @@
import Testing
@testable import PediFoods
// MARK: - formatPhoneBR
@Test("formatPhoneBR progressively formats as digits are typed")
func formatPhoneBRProgressiveFormatting() {
#expect(formatPhoneBR("") == "")
#expect(formatPhoneBR("1") == "(1")
#expect(formatPhoneBR("11") == "(11")
#expect(formatPhoneBR("119") == "(11) 9")
#expect(formatPhoneBR("1199999") == "(11) 99999")
#expect(formatPhoneBR("11999999999") == "(11) 99999-9999")
}
@Test("formatPhoneBR strips non-digit characters before formatting")
func formatPhoneBRStripsNonDigits() {
#expect(formatPhoneBR("(11) 99999-9999") == "(11) 99999-9999")
}
@Test("formatPhoneBR caps input at 11 digits")
func formatPhoneBRCapsAtElevenDigits() {
#expect(formatPhoneBR("119999999999999") == "(11) 99999-9999")
}
// MARK: - normalizePhoneNumberForAPI
@Test("normalizePhoneNumberForAPI returns empty for fewer than 10 digits")
func normalizePhoneNumberReturnsEmptyBelowTenDigits() {
#expect(normalizePhoneNumberForAPI("119999") == "")
}
@Test("normalizePhoneNumberForAPI prepends +55 to a bare local number")
func normalizePhoneNumberPrependsCountryCode() {
#expect(normalizePhoneNumberForAPI("11999999999") == "+5511999999999")
}
@Test("normalizePhoneNumberForAPI doesn't double the country code when it's already present")
func normalizePhoneNumberDoesNotDoubleCountryCode() {
#expect(normalizePhoneNumberForAPI("5511999999999") == "+5511999999999")
}
// MARK: - userFacingAuthErrorMessage
@Test("userFacingAuthErrorMessage uses ApiServiceError.sessionExpired's message when present")
func authErrorMessageUsesSessionExpiredMessage() {
let message = userFacingAuthErrorMessage(ApiServiceError.sessionExpired("Custom message"))
#expect(message == "Custom message")
}
@Test("userFacingAuthErrorMessage falls back to a default for a blank sessionExpired message")
func authErrorMessageFallsBackForBlankSessionExpired() {
let message = userFacingAuthErrorMessage(ApiServiceError.sessionExpired(" "))
#expect(message == "Sua sessão expirou. Faça login novamente.")
}
@Test("userFacingAuthErrorMessage maps NetworkError.httpError codes to distinct Portuguese messages")
func authErrorMessageMapsHttpErrorCodes() {
#expect(userFacingAuthErrorMessage(NetworkError.httpError(400, nil)).contains("Revise as informações"))
#expect(userFacingAuthErrorMessage(NetworkError.httpError(404, nil)).contains("Não encontramos"))
#expect(userFacingAuthErrorMessage(NetworkError.httpError(429, nil)).contains("Muitas tentativas"))
#expect(userFacingAuthErrorMessage(NetworkError.httpError(503, nil)).contains("instáveis"))
#expect(userFacingAuthErrorMessage(NetworkError.httpError(418, nil)).contains("Não foi possível concluir"))
}
@Test("userFacingAuthErrorMessage prefers the server's own message over the generic httpError mapping")
func authErrorMessagePrefersServerMessageOverGenericMapping() {
let message = userFacingAuthErrorMessage(NetworkError.httpError(400, "CPF já cadastrado"))
#expect(message == "CPF já cadastrado")
}
@Test("userFacingAuthErrorMessage maps unauthorized, rateLimited, transportError, cancelled, and timedOut")
func authErrorMessageMapsOtherNetworkErrorCases() {
#expect(userFacingAuthErrorMessage(NetworkError.unauthorized(nil)).contains("acesso expirou"))
#expect(userFacingAuthErrorMessage(NetworkError.rateLimited(nil)).contains("Muitas tentativas"))
#expect(userFacingAuthErrorMessage(NetworkError.transportError("timeout")).contains("conectar ao servidor"))
#expect(userFacingAuthErrorMessage(NetworkError.cancelled) == "Cancelado")
#expect(userFacingAuthErrorMessage(NetworkError.timedOut).contains("demorou demais"))
}
@Test("userFacingAuthErrorMessage falls back to a generic message for an unrecognized error type")
func authErrorMessageGenericFallbackForUnknownErrorType() {
struct SomeOtherError: Error {}
#expect(userFacingAuthErrorMessage(SomeOtherError()) == "Não foi possível concluir a operação. Tente novamente.")
}