ReviewOS

also looking at this

stacks/postline

Sync Bluesky engagement metrics into analytics

#12
Merged glennmichael123 wants to merge feat/metrics-sync into main
10 files +200 -4
tests/unit/social-publish.test.tsmodified+33-0
Changes to tests/unit/social-publish.test.ts
@@ -159,6 +159,39 @@ describe('BlueskyPublishingDriver.publish', () => {
159159 expect(record.embed.images[0].image.ref.$link).toBeDefined()
160160 })
161161
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 // Second post "deleted" upstream — absent from the response.
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
162195 test('uploadBlob rejects images over 1MB', async () => {
163196 const captured: CapturedRequest[] = []
164197 mockBlueskyApi(captured)