| @@ -159,6 +159,39 @@ describe('BlueskyPublishingDriver.publish', () => { |
| 159 | 159 | expect(record.embed.images[0].image.ref.$link).toBeDefined() |
| 160 | 160 | }) |
| 161 | 161 | |
| 162 | + test('postMetrics fetches engagement counts for up to 25 URIs', async () => { |
| 163 | + const captured: CapturedRequest[] = [] |
| 164 | + globalThis.fetch = (async (input: any) => { |
| 165 | + const url = new URL(String(input)) |
| 166 | + captured.push({ url: String(input), body: undefined }) |
| 167 | + const uris = url.searchParams.getAll('uris') |
| 168 | + return new Response(JSON.stringify({ |
| 169 | + |
| 170 | + posts: uris.slice(0, 1).map(uri => ({ uri, likeCount: 7, repostCount: 2, replyCount: 3 })), |
| 171 | + }), { status: 200, headers: { 'content-type': 'application/json' } }) |
| 172 | + }) as typeof fetch |
| 173 | + |
| 174 | + const driver = new BlueskyPublishingDriver() |
| 175 | + const metrics = await driver.postMetrics(identity, [ |
| 176 | + 'at://did:plc:test/app.bsky.feed.post/aaa', |
| 177 | + 'at://did:plc:test/app.bsky.feed.post/bbb', |
| 178 | + ]) |
| 179 | + |
| 180 | + expect(captured[0].url).toContain('app.bsky.feed.getPosts') |
| 181 | + expect(metrics).toEqual([ |
| 182 | + { uri: 'at://did:plc:test/app.bsky.feed.post/aaa', likeCount: 7, repostCount: 2, replyCount: 3 }, |
| 183 | + ]) |
| 184 | + }) |
| 185 | + |
| 186 | + test('postMetrics returns empty without hitting the API for no URIs', async () => { |
| 187 | + const captured: CapturedRequest[] = [] |
| 188 | + mockBlueskyApi(captured) |
| 189 | + |
| 190 | + const driver = new BlueskyPublishingDriver() |
| 191 | + expect(await driver.postMetrics(identity, [])).toEqual([]) |
| 192 | + expect(captured).toHaveLength(0) |
| 193 | + }) |
| 194 | + |
| 162 | 195 | test('uploadBlob rejects images over 1MB', async () => { |
| 163 | 196 | const captured: CapturedRequest[] = [] |
| 164 | 197 | mockBlueskyApi(captured) |