Files
andros b1dcf15ff7 Add notification tests against andros relay account; fix duplicate ID bug
- NotificationsTests: 8 tests against andros feed covering kinds, emojis, parents, authorFeedURL and error handling
- OrgSocialNotification.id: changed from post URL to "kind:postURL" — the relay can return the same post URL for different kinds (reply + mention simultaneously), so the ID must be composite
2026-04-19 08:46:34 +02:00

76 lines
2.7 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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<OrgSocialNotification.Kind> = [.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)
}
}
}