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,50 @@
import Foundation
import Testing
@testable import PediFoods
/// `AppContentCache.shared` is a true singleton with no injectable
/// instance; `invalidate()` with no prefix wipes every key regardless of
/// which test wrote it. Serialized so tests can't stomp on each other.
@Suite(.serialized)
struct AppContentCacheTests {
@Test("value(for:) returns what was just set")
func setThenGetRoundTrips() {
let key = "test.\(UUID().uuidString)"
AppContentCache.shared.set("hello", for: key, ttl: 60)
#expect(AppContentCache.shared.value(for: key, as: String.self) == "hello")
}
@Test("value(for:) returns nil once the TTL has elapsed")
func expiresAfterTTL() {
let key = "test.\(UUID().uuidString)"
AppContentCache.shared.set("hello", for: key, ttl: -1) // already expired
#expect(AppContentCache.shared.value(for: key, as: String.self) == nil)
}
@Test("value(for:) returns nil for a key that was never set")
func missingKeyReturnsNil() {
let key = "test.\(UUID().uuidString)"
#expect(AppContentCache.shared.value(for: key, as: String.self) == nil)
}
@Test("invalidate(prefix:) only removes keys matching that prefix")
func invalidateWithPrefixIsScoped() {
let prefix = "test.\(UUID().uuidString)."
AppContentCache.shared.set("a", for: "\(prefix)a", ttl: 60)
AppContentCache.shared.set("b", for: "\(prefix)b", ttl: 60)
AppContentCache.shared.set("unrelated", for: "unrelated.\(UUID().uuidString)", ttl: 60)
AppContentCache.shared.invalidate(prefix: prefix)
#expect(AppContentCache.shared.value(for: "\(prefix)a", as: String.self) == nil)
#expect(AppContentCache.shared.value(for: "\(prefix)b", as: String.self) == nil)
}
@Test("invalidate() with no prefix clears every entry")
func invalidateWithNoPrefixClearsEverything() {
let key = "test.\(UUID().uuidString)"
AppContentCache.shared.set("hello", for: key, ttl: 60)
AppContentCache.shared.invalidate()
#expect(AppContentCache.shared.value(for: key, as: String.self) == nil)
}
}