50c0ec176c
* 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>
150 lines
4.2 KiB
TypeScript
150 lines
4.2 KiB
TypeScript
import { AtpAgent } from '@atproto/api'
|
|
import { TestNetwork, SeedClient, basicSeed } from '@atproto/dev-env'
|
|
import { stripViewer } from '../_util'
|
|
import { ids } from '../../src/lexicon/lexicons'
|
|
|
|
describe('pds user search views', () => {
|
|
let network: TestNetwork
|
|
let agent: AtpAgent
|
|
let sc: SeedClient
|
|
|
|
beforeAll(async () => {
|
|
network = await TestNetwork.create({
|
|
dbPostgresSchema: 'bsky_views_suggestions',
|
|
})
|
|
agent = network.bsky.getClient()
|
|
sc = network.getSeedClient()
|
|
await basicSeed(sc)
|
|
await network.processAll()
|
|
|
|
const suggestions = [
|
|
{ did: sc.dids.alice, order: 1 },
|
|
{ did: sc.dids.bob, order: 2 },
|
|
{ did: sc.dids.carol, order: 3 },
|
|
{ did: sc.dids.dan, order: 4 },
|
|
]
|
|
|
|
await network.bsky.db.db
|
|
.insertInto('suggested_follow')
|
|
.values(suggestions)
|
|
.execute()
|
|
})
|
|
|
|
afterAll(async () => {
|
|
await network.close()
|
|
})
|
|
|
|
it('actor suggestion gives users', async () => {
|
|
const result = await agent.api.app.bsky.actor.getSuggestions(
|
|
{},
|
|
{
|
|
headers: await network.serviceHeaders(
|
|
sc.dids.carol,
|
|
ids.AppBskyActorGetSuggestions,
|
|
),
|
|
},
|
|
)
|
|
|
|
// does not include carol, because she is requesting
|
|
expect(result.data.actors.length).toBe(2)
|
|
expect(result.data.actors[0].handle).toEqual('bob.test')
|
|
expect(result.data.actors[0].displayName).toEqual('bobby')
|
|
expect(result.data.actors[1].handle).toEqual('dan.test')
|
|
expect(result.data.actors[1].displayName).toBeUndefined()
|
|
})
|
|
|
|
it('does not suggest followed users', async () => {
|
|
const result = await agent.api.app.bsky.actor.getSuggestions(
|
|
{},
|
|
{
|
|
headers: await network.serviceHeaders(
|
|
sc.dids.alice,
|
|
ids.AppBskyActorGetSuggestions,
|
|
),
|
|
},
|
|
)
|
|
|
|
// alice follows everyone
|
|
expect(result.data.actors.length).toBe(0)
|
|
})
|
|
|
|
it('paginates', async () => {
|
|
const result1 = await agent.api.app.bsky.actor.getSuggestions(
|
|
{ limit: 2 },
|
|
{
|
|
headers: await network.serviceHeaders(
|
|
sc.dids.carol,
|
|
ids.AppBskyActorGetSuggestions,
|
|
),
|
|
},
|
|
)
|
|
expect(result1.data.actors.length).toBe(1)
|
|
expect(result1.data.actors[0].handle).toEqual('bob.test')
|
|
|
|
const result2 = await agent.api.app.bsky.actor.getSuggestions(
|
|
{ limit: 2, cursor: result1.data.cursor },
|
|
{
|
|
headers: await network.serviceHeaders(
|
|
sc.dids.carol,
|
|
ids.AppBskyActorGetSuggestions,
|
|
),
|
|
},
|
|
)
|
|
expect(result2.data.actors.length).toBe(1)
|
|
expect(result2.data.actors[0].handle).toEqual('dan.test')
|
|
|
|
const result3 = await agent.api.app.bsky.actor.getSuggestions(
|
|
{ limit: 2, cursor: result2.data.cursor },
|
|
{
|
|
headers: await network.serviceHeaders(
|
|
sc.dids.carol,
|
|
ids.AppBskyActorGetSuggestions,
|
|
),
|
|
},
|
|
)
|
|
expect(result3.data.actors.length).toBe(0)
|
|
expect(result3.data.cursor).toBeUndefined()
|
|
})
|
|
|
|
it('fetches suggestions unauthed', async () => {
|
|
const { data: authed } = await agent.api.app.bsky.actor.getSuggestions(
|
|
{},
|
|
{
|
|
headers: await network.serviceHeaders(
|
|
sc.dids.carol,
|
|
ids.AppBskyActorGetSuggestions,
|
|
),
|
|
},
|
|
)
|
|
const { data: unauthed } = await agent.api.app.bsky.actor.getSuggestions({})
|
|
const omitViewerFollows = ({ did }) => {
|
|
return did !== sc.dids.carol && !sc.follows[sc.dids.carol][did]
|
|
}
|
|
expect(unauthed.actors.length).toBeGreaterThan(0)
|
|
expect(unauthed.actors.filter(omitViewerFollows)).toEqual(
|
|
authed.actors.map(stripViewer),
|
|
)
|
|
})
|
|
|
|
it('returns tagged suggestions', async () => {
|
|
const suggestions = [
|
|
{
|
|
tag: 'test',
|
|
subject: 'did:example:test',
|
|
subjectType: 'actor',
|
|
},
|
|
{
|
|
tag: 'another',
|
|
subject: 'at://did:example:another/app.bsky.feed.generator/my-feed',
|
|
subjectType: 'feed',
|
|
},
|
|
]
|
|
await network.bsky.db.db
|
|
.insertInto('tagged_suggestion')
|
|
.values(suggestions)
|
|
.execute()
|
|
const res = await agent.api.app.bsky.unspecced.getTaggedSuggestions()
|
|
expect(res.data.suggestions).toEqual(suggestions)
|
|
})
|
|
})
|