1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
import Foundation
@testable import Grain
/// Response payloads shaped like the real endpoints, so a rendered view takes
/// its loaded branch rather than its error branch. Image URLs point at
/// `test.local` and simply fail to load, which is the same path a broken
/// thumbnail takes in production.
enum Fixtures {
static let profile = """
{
"cid": "bafyprofile",
"did": "did:plc:test",
"handle": "tester.grain.social",
"displayName": "Tester",
"avatar": "https://test.local/avatar.jpg",
"createdAt": "2025-01-01T00:00:00Z"
}
"""
static let photo = """
{
"uri": "at://did:plc:test/social.grain.photo/1",
"cid": "bafyphoto",
"thumb": "https://test.local/thumb.jpg",
"fullsize": "https://test.local/full.jpg",
"alt": "A test photo",
"aspectRatio": {"width": 3, "height": 2}
}
"""
static let gallery = """
{
"uri": "at://did:plc:test/social.grain.gallery/1",
"cid": "bafygallery",
"title": "A test gallery",
"description": "Description long enough to need wrapping in the card.",
"creator": \(profile),
"items": [\(photo)],
"favCount": 3,
"commentCount": 2,
"createdAt": "2025-01-02T00:00:00Z",
"indexedAt": "2025-01-02T00:00:00Z"
}
"""
static let feed = """
{"items": [\(gallery)], "cursor": null}
"""
static let notifications = """
{
"notifications": [
{
"uri": "at://did:plc:test/notification/1",
"reason": "like",
"createdAt": "2025-01-03T00:00:00Z",
"author": \(profile),
"galleryUri": "at://did:plc:test/social.grain.gallery/1",
"galleryTitle": "A test gallery"
},
{
"uri": "at://did:plc:test/notification/2",
"reason": "follow",
"createdAt": "2025-01-03T00:00:00Z",
"author": \(profile)
},
{
"uri": "at://did:plc:test/notification/3",
"reason": "comment",
"createdAt": "2025-01-03T00:00:00Z",
"author": \(profile),
"commentText": "A test comment"
}
],
"cursor": null
}
"""
}
extension Fixtures {
/// `getGallery` wraps the gallery; the bare object above is what the feed
/// returns inside its items array.
static let galleryResponse = """
{"gallery": \(gallery)}
"""
static let commentThread = """
{
"comments": [
{
"uri": "at://did:plc:test/social.grain.comment/1",
"cid": "bafycomment1",
"author": \(profile),
"text": "A comment mentioning @tester.grain.social and #film.",
"createdAt": "2025-01-03T00:00:00Z",
"favCount": 2
},
{
"uri": "at://did:plc:test/social.grain.comment/2",
"cid": "bafycomment2",
"author": \(profile),
"text": "A reply to it.",
"replyTo": "at://did:plc:test/social.grain.comment/1",
"createdAt": "2025-01-03T01:00:00Z"
}
],
"cursor": null,
"totalCount": 2
}
"""
}
// MARK: - Whole-app routing
extension Fixtures {
static let profileDetailed = """
{
"cid": "bafyprofile",
"did": "did:plc:test",
"handle": "tester.grain.social",
"displayName": "Tester",
"description": "A profile with a description long enough to wrap onto a second line.",
"avatar": "https://test.local/avatar.jpg",
"cameras": ["Fujifilm X100V", "Leica M6"],
"followersCount": 1200,
"followsCount": 34,
"galleryCount": 5,
"indexedAt": "2025-01-01T00:00:00Z",
"createdAt": "2025-01-01T00:00:00Z"
}
"""
/// Two people, one already followed, so a list renders both button states.
static let actorList = """
{"totalCount": 2, "items": [
{
"did": "did:plc:a", "handle": "alpha.test", "displayName": "Alpha",
"description": "First person", "avatar": "https://test.local/a.jpg",
"viewer": {"following": "at://did:plc:test/social.grain.graph.follow/1"}
},
{"did": "did:plc:b", "handle": "beta.test", "displayName": "Beta", "viewer": {}}
], "cursor": null}
"""
static let blockList = """
{"items": [
{"did": "did:plc:a", "handle": "alpha.test", "displayName": "Alpha",
"avatar": "https://test.local/a.jpg", "blockUri": "at://did:plc:test/social.grain.graph.block/1"},
{"did": "did:plc:b", "handle": "beta.test", "blockUri": "at://did:plc:test/social.grain.graph.block/2"}
], "cursor": null}
"""
static let muteList = """
{"items": [
{"did": "did:plc:a", "handle": "alpha.test", "displayName": "Alpha", "avatar": "https://test.local/a.jpg"},
{"did": "did:plc:b", "handle": "beta.test"}
], "cursor": null}
"""
static let suggestedFollows = """
{"items": [
{"did": "did:plc:a", "handle": "alpha.test", "displayName": "Alpha", "followersCount": 120},
{"did": "did:plc:b", "handle": "beta.test", "followersCount": 3}
]}
"""
static let storyAuthors = """
{"authors": [
{"profile": \(profile), "storyCount": 2, "latestAt": "\(freshTimestamp)"},
{
"profile": {"cid": "c2", "did": "did:plc:other", "handle": "other.test", "displayName": "Other"},
"storyCount": 1, "latestAt": "\(freshTimestamp)"
}
]}
"""
static let stories = """
{"stories": [
{
"uri": "at://did:plc:test/social.grain.story/1", "cid": "bafystory1",
"creator": \(profile),
"thumb": "https://test.local/thumb.jpg", "fullsize": "https://test.local/full.jpg",
"aspectRatio": {"width": 3, "height": 4},
"createdAt": "\(freshTimestamp)"
},
{
"uri": "at://did:plc:test/social.grain.story/2", "cid": "bafystory2",
"creator": \(profile),
"thumb": "https://test.local/thumb2.jpg", "fullsize": "https://test.local/full2.jpg",
"aspectRatio": {"width": 4, "height": 3},
"locationDisplay": "Test City",
"createdAt": "\(freshTimestamp)"
}
]}
"""
static let preferences = """
{"preferences": [
{"$type": "social.grain.actor.defs#pinnedFeedsPref", "items": [
{"id": "recent", "label": "Recent", "type": "feed", "path": "/"},
{"id": "following", "label": "Following", "type": "feed", "path": "/feeds/following"},
{"id": "camera:Leica M6", "label": "Leica M6", "type": "camera", "path": "/c/leica"}
]},
{"$type": "social.grain.actor.defs#photoMetadataPref", "includeExif": true, "includeLocation": true}
]}
"""
static let locations = """
{"locations": [
{"name": "Lisboa", "h3Index": "8a2a1072b59ffff", "galleryCount": 12},
{"name": "Porto", "h3Index": "8a2a1072b58ffff", "galleryCount": 4}
]}
"""
static let cameras = """
{"cameras": [
{"camera": "Fujifilm X100V", "photoCount": 40},
{"camera": "Leica M6", "photoCount": 12}
]}
"""
/// Stories expire 24 hours after `latestAt`, so a literal date would turn
/// every story fixture into a time bomb.
static var freshTimestamp: String {
DateFormatting.nowISO(date: Date().addingTimeInterval(-3600))
}
/// A correct payload for every endpoint a screen might fan out to, so a
/// render settles on its loaded state rather than its error state.
static var routes: [String: String] {
[
"getFeed": feed,
"getGallery": galleryResponse,
"comment.getThread": commentThread,
"getPreferences": preferences,
"getLocations": locations,
"getCameras": cameras,
"searchGalleries": feed,
"actor.searchActors": actorList,
"searchActorsTypeahead": #"{"actors": []}"#,
"actor.getProfile": profileDetailed,
"story.getAuthors": storyAuthors,
"story.getArchive": stories,
"getStories": stories,
"getStory": #"{"story": null}"#,
"listNotifications": notifications,
"getUnreadCount": #"{"count": 0}"#,
"describeLabels": #"{"policies": {"labelValues": [], "labelValueDefinitions": []}}"#,
"getKnownFollowers": actorList,
"gallery.getFavorites": actorList,
"getFollowers": actorList,
"getFollowing": actorList,
"getSuggestedFollows": suggestedFollows,
"getBlocks": blockList,
"getMutes": muteList,
"actor.getFavorites": feed,
"getActorGalleries": feed,
]
}
}
extension AccountServer {
/// Where a test account's tokens came from: a PDS that is its own
/// authorization server, as a self-hosted one is.
static let test = AccountServer(
pds: URL(string: "https://pds.test")!,
issuer: "https://pds.test",
tokenEndpoint: URL(string: "https://pds.test/oauth/token")!,
revocationEndpoint: URL(string: "https://pds.test/oauth/revoke")!
)
}