atproto/packages/bsky/tests/views/actor-likes.test.ts
Matthieu Sieben 61dc0d60e1
Add linting rule to sort imports (#3220)
* Add linting rule to sort imports

* remove spacing between import groups

* changeset

* changeset

* prettier config fine tuning

* forbid use of deprecated imports

* tidy
2025-02-05 15:06:58 +01:00

140 lines
3.2 KiB
TypeScript

import { AtUri, AtpAgent } from '@atproto/api'
import { SeedClient, TestNetwork, basicSeed } from '@atproto/dev-env'
import { ids } from '../../src/lexicon/lexicons'
describe('bsky actor likes feed views', () => {
let network: TestNetwork
let agent: AtpAgent
let pdsAgent: AtpAgent
let sc: SeedClient
// account dids, for convenience
let alice: string
let bob: string
let carol: string
beforeAll(async () => {
network = await TestNetwork.create({
dbPostgresSchema: 'bsky_views_actor_likes',
})
agent = network.bsky.getClient()
pdsAgent = network.pds.getClient()
sc = network.getSeedClient()
await basicSeed(sc)
await network.processAll()
alice = sc.dids.alice
bob = sc.dids.bob
carol = sc.dids.carol
})
afterAll(async () => {
await network.close()
})
it('returns posts liked by actor', async () => {
const {
data: { feed: bobLikes },
} = await agent.api.app.bsky.feed.getActorLikes(
{ actor: sc.accounts[bob].handle },
{
headers: await network.serviceHeaders(
bob,
ids.AppBskyFeedGetActorLikes,
),
},
)
expect(bobLikes).toHaveLength(3)
await expect(
agent.api.app.bsky.feed.getActorLikes(
{ actor: sc.accounts[bob].handle },
{
headers: await network.serviceHeaders(
carol,
ids.AppBskyFeedGetActorLikes,
),
},
),
).rejects.toThrow('Profile not found')
})
it('viewer has blocked author of liked post(s)', async () => {
const bobBlocksAlice = await pdsAgent.api.app.bsky.graph.block.create(
{
repo: bob, // bob blocks alice
},
{
subject: alice,
createdAt: new Date().toISOString(),
},
sc.getHeaders(bob),
)
await network.processAll()
const {
data: { feed },
} = await agent.api.app.bsky.feed.getActorLikes(
{ actor: sc.accounts[bob].handle },
{
headers: await network.serviceHeaders(
bob,
ids.AppBskyFeedGetActorLikes,
),
},
)
expect(
feed.every((item) => {
return item.post.author.did !== alice
}),
).toBe(true)
// unblock
await pdsAgent.api.app.bsky.graph.block.delete(
{ repo: bob, rkey: new AtUri(bobBlocksAlice.uri).rkey },
sc.getHeaders(bob),
)
})
it('liked post author has blocked viewer', async () => {
const aliceBlockBob = await pdsAgent.api.app.bsky.graph.block.create(
{
repo: alice, // alice blocks bob
},
{
subject: bob,
createdAt: new Date().toISOString(),
},
sc.getHeaders(alice),
)
await network.processAll()
const {
data: { feed },
} = await agent.api.app.bsky.feed.getActorLikes(
{ actor: sc.accounts[bob].handle },
{
headers: await network.serviceHeaders(
bob,
ids.AppBskyFeedGetActorLikes,
),
},
)
expect(
feed.every((item) => {
return item.post.author.did !== alice
}),
).toBe(true)
// unblock
await pdsAgent.api.app.bsky.graph.block.delete(
{ repo: alice, rkey: new AtUri(aliceBlockBob.uri).rkey },
sc.getHeaders(alice),
)
})
})