← All repositories

crossmate

A collaborative crossword app for iPhone and iPad

git clone https://code.inqk.net/crossmate.git


Tests/Unit/FriendInviteRecencyStoreTests.swift (1775B)

1import Foundation
2import Testing
3@testable import Crossmate
4
5@MainActor
6@Suite("Friend invite recency")
7struct FriendInviteRecencyStoreTests {
8    private func makeStore() throws -> FriendInviteRecencyStore {
9        let suiteName = "friend-invite-recency-\(UUID().uuidString)"
10        let defaults = try #require(UserDefaults(suiteName: suiteName))
11        defaults.removePersistentDomain(forName: suiteName)
12        return FriendInviteRecencyStore(defaults: defaults)
13    }
14
15    @Test("Invites are ranked from most to least recent")
16    func ranksInvitesByRecentUse() throws {
17        let store = try makeStore()
18
19        store.recordInvite(to: "_alice")
20        store.recordInvite(to: "_bob")
21        store.recordInvite(to: "_carol")
22
23        #expect(store.ranksByAuthorID == [
24            "_carol": 0,
25            "_bob": 1,
26            "_alice": 2,
27        ])
28    }
29
30    @Test("Inviting the same friend again moves them to the front")
31    func reinviteMovesFriendToFront() throws {
32        let store = try makeStore()
33        store.recordInvite(to: "_alice")
34        store.recordInvite(to: "_bob")
35
36        store.recordInvite(to: "_alice")
37
38        #expect(store.ranksByAuthorID == [
39            "_alice": 0,
40            "_bob": 1,
41        ])
42    }
43
44    @Test("Invite ordering survives a new store instance")
45    func persistsInviteOrdering() throws {
46        let suiteName = "friend-invite-recency-\(UUID().uuidString)"
47        let defaults = try #require(UserDefaults(suiteName: suiteName))
48        defaults.removePersistentDomain(forName: suiteName)
49        FriendInviteRecencyStore(defaults: defaults).recordInvite(to: "_alice")
50
51        let reloaded = FriendInviteRecencyStore(defaults: defaults)
52
53        #expect(reloaded.ranksByAuthorID == ["_alice": 0])
54    }
55}