atproto/packages/bsky/tests/views/reposts.test.ts
Daniel Holmgren 50c0ec176c
Service auth method binding (lxm) (#2663)
* add scopes to service auth impl

* add error to getServiceAuth

* send scoped tokens from pds

* clean up privileged access scopes & allow simple service auth tokens for app passwords

* integration into ozone

* fix up bsky tests

* cleanup xrpc-server tests

* fix up tests & types

* one more test

* fix read after write tests

* fix mod auth test

* convert scopes to be a single method name

* add scope check callback for auth verifier

* pds changes only

* fix feed generation tests

* use scope for ozone service profile

* dont verify scopes on pds yet

* tidy

* tidy imports

* changeset

* add tests

* tidy

* another changeset

* scope -> lxm

* tidy

* clean up scope references

* update nonce size

* pr feedback

* trim trailing slash

* nonce -> jti

* fix xrpc-server test

* allow service auth on uploadBlob

* fix build error

* changeset

* build, tidy

* xrpc-server: update lxm claim check error

* appview: temporarily permit labeler service calls to omit lxm claim

* xrpc-server: fix test

* changeset

* fix merged tests

---------

Co-authored-by: Devin Ivy <devinivy@gmail.com>
2024-08-18 15:46:07 -04:00

114 lines
3.2 KiB
TypeScript

import { AtpAgent } from '@atproto/api'
import { TestNetwork, SeedClient, repostsSeed } from '@atproto/dev-env'
import { forSnapshot, paginateAll, stripViewer } from '../_util'
import { ids } from '../../src/lexicon/lexicons'
describe('pds repost views', () => {
let network: TestNetwork
let agent: AtpAgent
let sc: SeedClient
// account dids, for convenience
let alice: string
let bob: string
beforeAll(async () => {
network = await TestNetwork.create({
dbPostgresSchema: 'bsky_views_reposts',
})
agent = network.bsky.getClient()
sc = network.getSeedClient()
await repostsSeed(sc)
await network.processAll()
alice = sc.dids.alice
bob = sc.dids.bob
})
afterAll(async () => {
await network.close()
})
it('fetches reposted-by for a post', async () => {
const view = await agent.api.app.bsky.feed.getRepostedBy(
{ uri: sc.posts[alice][2].ref.uriStr },
{
headers: await network.serviceHeaders(
alice,
ids.AppBskyFeedGetRepostedBy,
),
},
)
expect(view.data.uri).toEqual(sc.posts[sc.dids.alice][2].ref.uriStr)
expect(forSnapshot(view.data.repostedBy)).toMatchSnapshot()
})
it('fetches reposted-by for a reply', async () => {
const view = await agent.api.app.bsky.feed.getRepostedBy(
{ uri: sc.replies[bob][0].ref.uriStr },
{
headers: await network.serviceHeaders(
alice,
ids.AppBskyFeedGetRepostedBy,
),
},
)
expect(view.data.uri).toEqual(sc.replies[sc.dids.bob][0].ref.uriStr)
expect(forSnapshot(view.data.repostedBy)).toMatchSnapshot()
})
it('paginates', async () => {
const results = (results) => results.flatMap((res) => res.repostedBy)
const paginator = async (cursor?: string) => {
const res = await agent.api.app.bsky.feed.getRepostedBy(
{
uri: sc.posts[alice][2].ref.uriStr,
cursor,
limit: 2,
},
{
headers: await network.serviceHeaders(
alice,
ids.AppBskyFeedGetRepostedBy,
),
},
)
return res.data
}
const paginatedAll = await paginateAll(paginator)
paginatedAll.forEach((res) =>
expect(res.repostedBy.length).toBeLessThanOrEqual(2),
)
const full = await agent.api.app.bsky.feed.getRepostedBy(
{ uri: sc.posts[alice][2].ref.uriStr },
{
headers: await network.serviceHeaders(
alice,
ids.AppBskyFeedGetRepostedBy,
),
},
)
expect(full.data.repostedBy.length).toEqual(4)
expect(results(paginatedAll)).toEqual(results([full.data]))
})
it('fetches reposted-by unauthed', async () => {
const { data: authed } = await agent.api.app.bsky.feed.getRepostedBy(
{ uri: sc.posts[alice][2].ref.uriStr },
{
headers: await network.serviceHeaders(
alice,
ids.AppBskyFeedGetRepostedBy,
),
},
)
const { data: unauthed } = await agent.api.app.bsky.feed.getRepostedBy({
uri: sc.posts[alice][2].ref.uriStr,
})
expect(unauthed.repostedBy.length).toBeGreaterThan(0)
expect(unauthed.repostedBy).toEqual(authed.repostedBy.map(stripViewer))
})
})