atproto/packages/ozone/tests/get-records.test.ts
Foysal Ahamed a2bad977a8
Ozone batch repo and record getters (#2836)
*  Add getRepos and getRecords endpoints for bulk fetching

*  Fix issues and add tests for get repos and get records

*  Use the right lxm

* 🐛 Revert changes in lockfile

*  Add getAccountInfos in PDS

* 🐛 Fix type def for repo and record view detail

*  Update snapshots

*  Update snapshots

*  Consolidate error type for com.atproto and tools.ozone getRecord error type

* 🧹 Cleanup

*  Update snapshots

*  Update snapshots

*  Changeset
2024-10-01 19:37:23 +02:00

88 lines
2.4 KiB
TypeScript

import {
SeedClient,
TestNetwork,
basicSeed,
TestOzone,
ModeratorClient,
} from '@atproto/dev-env'
import { AtpAgent } from '@atproto/api'
import {
REASONOTHER,
REASONSPAM,
} from '../src/lexicon/types/com/atproto/moderation/defs'
import { forSnapshot } from './_util'
import { ids } from '../src/lexicon/lexicons'
describe('admin get records view', () => {
let network: TestNetwork
let ozone: TestOzone
let agent: AtpAgent
let sc: SeedClient
let modClient: ModeratorClient
beforeAll(async () => {
network = await TestNetwork.create({
dbPostgresSchema: 'ozone_admin_get_records',
})
ozone = network.ozone
agent = ozone.getClient()
sc = network.getSeedClient()
modClient = ozone.getModClient()
await basicSeed(sc)
await network.processAll()
})
afterAll(async () => {
await network.close()
})
beforeAll(async () => {
await sc.createReport({
reportedBy: sc.dids.bob,
reasonType: REASONSPAM,
subject: {
$type: 'com.atproto.repo.strongRef',
uri: sc.posts[sc.dids.alice][0].ref.uriStr,
cid: sc.posts[sc.dids.alice][0].ref.cidStr,
},
})
await sc.createReport({
reportedBy: sc.dids.carol,
reasonType: REASONOTHER,
reason: 'defamation',
subject: {
$type: 'com.atproto.repo.strongRef',
uri: sc.posts[sc.dids.alice][0].ref.uriStr,
cid: sc.posts[sc.dids.alice][0].ref.cidStr,
},
})
await modClient.emitEvent({
event: { $type: 'tools.ozone.moderation.defs#modEventTakedown' },
subject: {
$type: 'com.atproto.repo.strongRef',
uri: sc.posts[sc.dids.alice][0].ref.uriStr,
cid: sc.posts[sc.dids.alice][0].ref.cidStr,
},
})
await network.bsky.ctx.dataplane.takedownRecord({
recordUri: sc.posts[sc.dids.alice][0].ref.uriStr,
})
})
it('get multiple records by uris', async () => {
const { data } = await agent.tools.ozone.moderation.getRecords(
{
uris: [
sc.posts[sc.dids.alice][0].ref.uriStr,
sc.posts[sc.dids.bob][0].ref.uriStr,
// create a uri for a non-existent collection
sc.posts[sc.dids.bob][0].ref.uriStr.replace('.post', '.test'),
],
},
{ headers: await ozone.modHeaders(ids.ToolsOzoneModerationGetRecords) },
)
expect(forSnapshot(data)).toMatchSnapshot()
})
})