about summary refs log tree commit diff
path: root/jest
diff options
context:
space:
mode:
Diffstat (limited to 'jest')
-rw-r--r--jest/test-pds.ts57
1 files changed, 52 insertions, 5 deletions
diff --git a/jest/test-pds.ts b/jest/test-pds.ts
index 34c3e8bc4..0c9d946fc 100644
--- a/jest/test-pds.ts
+++ b/jest/test-pds.ts
@@ -2,7 +2,7 @@ import net from 'net'
 import path from 'path'
 import fs from 'fs'
 import {TestPds as DevEnvTestPDS, TestNetworkNoAppView} from '@atproto/dev-env'
-import {BskyAgent} from '@atproto/api'
+import {AtUri, BskyAgent} from '@atproto/api'
 
 export interface TestUser {
   email: string
@@ -29,13 +29,13 @@ export async function createServer(
     plc: {port: port2},
   })
 
-  const profilePic = fs.readFileSync(
+  const pic = fs.readFileSync(
     path.join(__dirname, '..', 'assets', 'default-avatar.jpg'),
   )
 
   return {
     pdsUrl,
-    mocker: new Mocker(pds, pdsUrl, profilePic),
+    mocker: new Mocker(pds, pdsUrl, pic),
     async close() {
       await pds.server.destroy()
       await plc.server.destroy()
@@ -50,7 +50,7 @@ class Mocker {
   constructor(
     public pds: DevEnvTestPDS,
     public service: string,
-    public profilePic: Uint8Array,
+    public pic: Uint8Array,
   ) {
     this.agent = new BskyAgent({service})
   }
@@ -90,7 +90,7 @@ class Mocker {
       password: 'hunter2',
     })
     await agent.upsertProfile(async () => {
-      const blob = await agent.uploadBlob(this.profilePic, {
+      const blob = await agent.uploadBlob(this.pic, {
         encoding: 'image/jpeg',
       })
       return {
@@ -146,6 +146,26 @@ class Mocker {
     }
     return await agent.post({
       text,
+      langs: ['en'],
+      createdAt: new Date().toISOString(),
+    })
+  }
+
+  async createImagePost(user: string, text: string) {
+    const agent = this.users[user]?.agent
+    if (!agent) {
+      throw new Error(`Not a user: ${user}`)
+    }
+    const blob = await agent.uploadBlob(this.pic, {
+      encoding: 'image/jpeg',
+    })
+    return await agent.post({
+      text,
+      langs: ['en'],
+      embed: {
+        $type: 'app.bsky.embed.images',
+        images: [{image: blob.data.blob, alt: ''}],
+      },
       createdAt: new Date().toISOString(),
     })
   }
@@ -162,6 +182,7 @@ class Mocker {
     return await agent.post({
       text,
       embed: {$type: 'app.bsky.embed.record', record: {uri, cid}},
+      langs: ['en'],
       createdAt: new Date().toISOString(),
     })
   }
@@ -178,6 +199,7 @@ class Mocker {
     return await agent.post({
       text,
       reply: {root: {uri, cid}, parent: {uri, cid}},
+      langs: ['en'],
       createdAt: new Date().toISOString(),
     })
   }
@@ -190,6 +212,31 @@ class Mocker {
     return await agent.like(uri, cid)
   }
 
+  async createFeed(user: string) {
+    const agent = this.users[user]?.agent
+    if (!agent) {
+      throw new Error(`Not a user: ${user}`)
+    }
+    const fg1Uri = AtUri.make(
+      this.users[user].did,
+      'app.bsky.feed.generator',
+      'alice-favs',
+    )
+    const avatarRes = await agent.api.com.atproto.repo.uploadBlob(this.pic, {
+      encoding: 'image/png',
+    })
+    return await agent.api.app.bsky.feed.generator.create(
+      {repo: this.users[user].did, rkey: fg1Uri.rkey},
+      {
+        did: 'did:web:fake.com',
+        displayName: 'alices feed',
+        description: 'all my fav stuff',
+        avatar: avatarRes.data.blob,
+        createdAt: new Date().toISOString(),
+      },
+    )
+  }
+
   async createInvite(forAccount: string) {
     const agent = new BskyAgent({service: this.agent.service})
     await agent.api.com.atproto.server.createInviteCode(