import Foundation import Testing @testable import OrgSocialKit private let andros = URL(string: "https://host.org-social.org/andros/social.org")! private let relay = URL(string: "https://relay.org-social.org")! @Suite("RelayClient.fetchNotifications – andros account", .serialized) struct NotificationsTests { let client = RelayClient() @Test("returns a non-empty list for andros") func returnsNotifications() async throws { let items = try await client.fetchNotifications(for: andros, from: relay) #expect(!items.isEmpty) } @Test("every notification has a non-empty post URL") func postURLsNonEmpty() async throws { let items = try await client.fetchNotifications(for: andros, from: relay) for item in items { #expect(!item.post.isEmpty) } } @Test("all kinds are known values") func knownKinds() async throws { let items = try await client.fetchNotifications(for: andros, from: relay) let known: Set = [.mention, .reaction, .reply, .boost] for item in items { #expect(known.contains(item.kind)) } } @Test("reactions have a non-nil emoji") func reactionsHaveEmoji() async throws { let items = try await client.fetchNotifications(for: andros, from: relay) for item in items where item.kind == .reaction { #expect(item.emoji != nil) } } @Test("replies and reactions have a parent post") func repliesAndReactionsHaveParent() async throws { let items = try await client.fetchNotifications(for: andros, from: relay) for item in items where item.kind == .reply || item.kind == .reaction { #expect(item.parent != nil) } } @Test("authorFeedURL is a valid http(s) URL") func authorFeedURLValid() async throws { let items = try await client.fetchNotifications(for: andros, from: relay) for item in items { let scheme = item.authorFeedURL?.scheme ?? "" #expect(scheme == "https" || scheme == "http") } } @Test("all notifications have unique IDs (kind + post URL)") func uniqueIDs() async throws { let items = try await client.fetchNotifications(for: andros, from: relay) let ids = items.map(\.id) #expect(ids.count == Set(ids).count) } @Test("throws RelayError on invalid feed URL") func throwsOnMissingFeed() async throws { let missing = URL(string: "https://host.org-social.org/does-not-exist/social.org")! await #expect(throws: (any Error).self) { try await client.fetchNotifications(for: missing, from: relay) } } }