forked from bluesky-social/atproto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add getLists endpoint to proxied routes via ozone (bluesky-social#2493
) * ✨ Add getLists endpoint to proxied routes via ozone * ✅ Add tests for getLists via ozone * insert takedown label manually * ✏️ Fix typo in test * 🧹 Cleanup --------- Co-authored-by: dholms <[email protected]>
- Loading branch information
Showing
5 changed files
with
170 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { | ||
SeedClient, | ||
TestNetwork, | ||
TestOzone, | ||
basicSeed, | ||
ModeratorClient, | ||
RecordRef, | ||
} from '@atproto/dev-env' | ||
import AtpAgent, { BSKY_LABELER_DID } from '@atproto/api' | ||
import { TAKEDOWN_LABEL } from '../src/mod-service' | ||
|
||
describe('admin get lists', () => { | ||
let network: TestNetwork | ||
let ozone: TestOzone | ||
let agent: AtpAgent | ||
let appviewAgent: AtpAgent | ||
let sc: SeedClient | ||
let modClient: ModeratorClient | ||
let alicesList: RecordRef | ||
|
||
beforeAll(async () => { | ||
network = await TestNetwork.create({ | ||
dbPostgresSchema: 'ozone_admin_get_lists', | ||
}) | ||
ozone = network.ozone | ||
agent = ozone.getClient() | ||
appviewAgent = network.bsky.getClient() | ||
sc = network.getSeedClient() | ||
modClient = ozone.getModClient() | ||
await basicSeed(sc) | ||
alicesList = await sc.createList(sc.dids.alice, "Alice's List", 'mod') | ||
AtpAgent.configure({ appLabelers: [ozone.ctx.cfg.service.did] }) | ||
await network.processAll() | ||
}) | ||
|
||
afterAll(async () => { | ||
AtpAgent.configure({ appLabelers: [BSKY_LABELER_DID] }) | ||
await network.close() | ||
}) | ||
|
||
const getAlicesList = async () => { | ||
const [{ data: fromOzone }, { data: fromAppview }] = await Promise.all([ | ||
agent.api.app.bsky.graph.getLists( | ||
{ actor: sc.dids.alice }, | ||
{ headers: await ozone.modHeaders() }, | ||
), | ||
appviewAgent.api.app.bsky.graph.getLists({ actor: sc.dids.alice }), | ||
]) | ||
|
||
return { fromOzone, fromAppview } | ||
} | ||
|
||
it('returns lists from takendown account', async () => { | ||
const beforeTakedown = await getAlicesList() | ||
expect(beforeTakedown.fromOzone.lists[0].uri).toEqual(alicesList.uriStr) | ||
expect(beforeTakedown.fromAppview.lists[0].uri).toEqual(alicesList.uriStr) | ||
|
||
// Takedown alice's account | ||
await modClient.emitEvent({ | ||
event: { $type: 'tools.ozone.moderation.defs#modEventTakedown' }, | ||
subject: { | ||
$type: 'com.atproto.admin.defs#repoRef', | ||
did: sc.dids.alice, | ||
}, | ||
}) | ||
await network.processAll() | ||
|
||
const afterTakedown = await getAlicesList() | ||
|
||
// Verify that takendown list is shown when queried through ozone but not through appview | ||
expect(afterTakedown.fromAppview.lists.length).toBe(0) | ||
expect(afterTakedown.fromOzone.lists[0].uri).toEqual(alicesList.uriStr) | ||
|
||
// Reverse alice's account takedown | ||
await modClient.emitEvent({ | ||
event: { $type: 'tools.ozone.moderation.defs#modEventReverseTakedown' }, | ||
subject: { | ||
$type: 'com.atproto.admin.defs#repoRef', | ||
did: sc.dids.alice, | ||
}, | ||
}) | ||
await network.processAll() | ||
}) | ||
|
||
it('returns takendown lists', async () => { | ||
const beforeTakedown = await getAlicesList() | ||
expect(beforeTakedown.fromOzone.lists[0].uri).toEqual(alicesList.uriStr) | ||
expect(beforeTakedown.fromAppview.lists[0].uri).toEqual(alicesList.uriStr) | ||
|
||
// Takedown alice's list using a !takedown label | ||
await network.bsky.db.db | ||
.insertInto('label') | ||
.values({ | ||
src: ozone.ctx.cfg.service.did, | ||
uri: alicesList.uriStr, | ||
cid: alicesList.cidStr, | ||
val: TAKEDOWN_LABEL, | ||
neg: false, | ||
cts: new Date().toISOString(), | ||
}) | ||
.execute() | ||
|
||
const afterTakedown = await getAlicesList() | ||
|
||
// Verify that takendown list is shown when queried through ozone but not through appview | ||
expect(afterTakedown.fromAppview.lists.length).toBe(0) | ||
expect(afterTakedown.fromOzone.lists[0].uri).toEqual(alicesList.uriStr) | ||
}) | ||
}) |