about summary refs log tree commit diff
path: root/jest
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-09-20 19:47:56 -0700
committerGitHub <noreply@github.com>2023-09-20 19:47:56 -0700
commit5a945c2024855b89dfb99f81a2c4d226bb39dc32 (patch)
tree3a42e8e8d79c281606c2b7d9bff9380df596d8c7 /jest
parent68dd3210d11bf8a15c319768d3e338c629a69d4b (diff)
downloadvoidsky-5a945c2024855b89dfb99f81a2c4d226bb39dc32.tar.zst
Prefilter the mergefeed to ensure a better mix of following and custom feeds (#1498)
* Prefilter the mergefeed to ensure a better mix of following and custom feeds

* Test suite improvements & tests for the mergefeed (#1499)

* Disable invite codes test for now

* Update test sim to latest iphone

* Introduce TestCtrls driver

* Add mergefeed tests
Diffstat (limited to 'jest')
-rw-r--r--jest/test-pds.ts42
1 files changed, 30 insertions, 12 deletions
diff --git a/jest/test-pds.ts b/jest/test-pds.ts
index 0c9d946fc..37ad824a0 100644
--- a/jest/test-pds.ts
+++ b/jest/test-pds.ts
@@ -1,7 +1,7 @@
 import net from 'net'
 import path from 'path'
 import fs from 'fs'
-import {TestPds as DevEnvTestPDS, TestNetworkNoAppView} from '@atproto/dev-env'
+import {TestNetworkNoAppView} from '@atproto/dev-env'
 import {AtUri, BskyAgent} from '@atproto/api'
 
 export interface TestUser {
@@ -24,7 +24,7 @@ export async function createServer(
   const port = await getPort()
   const port2 = await getPort(port + 1)
   const pdsUrl = `http://localhost:${port}`
-  const {pds, plc} = await TestNetworkNoAppView.create({
+  const testNet = await TestNetworkNoAppView.create({
     pds: {port, publicUrl: pdsUrl, inviteRequired},
     plc: {port: port2},
   })
@@ -35,10 +35,10 @@ export async function createServer(
 
   return {
     pdsUrl,
-    mocker: new Mocker(pds, pdsUrl, pic),
+    mocker: new Mocker(testNet, pdsUrl, pic),
     async close() {
-      await pds.server.destroy()
-      await plc.server.destroy()
+      await testNet.pds.server.destroy()
+      await testNet.plc.server.destroy()
     },
   }
 }
@@ -48,13 +48,21 @@ class Mocker {
   users: Record<string, TestUser> = {}
 
   constructor(
-    public pds: DevEnvTestPDS,
+    public testNet: TestNetworkNoAppView,
     public service: string,
     public pic: Uint8Array,
   ) {
     this.agent = new BskyAgent({service})
   }
 
+  get pds() {
+    return this.testNet.pds
+  }
+
+  get plc() {
+    return this.testNet.plc
+  }
+
   // NOTE
   // deterministic date generator
   // we use this to ensure the mock dataset is always the same
@@ -212,24 +220,34 @@ class Mocker {
     return await agent.like(uri, cid)
   }
 
-  async createFeed(user: string) {
+  async createFeed(user: string, rkey: string, posts: string[]) {
     const agent = this.users[user]?.agent
     if (!agent) {
       throw new Error(`Not a user: ${user}`)
     }
-    const fg1Uri = AtUri.make(
+    const fgUri = AtUri.make(
       this.users[user].did,
       'app.bsky.feed.generator',
-      'alice-favs',
+      rkey,
     )
+    const fg1 = await this.testNet.createFeedGen({
+      [fgUri.toString()]: async () => {
+        return {
+          encoding: 'application/json',
+          body: {
+            feed: posts.slice(0, 30).map(uri => ({post: uri})),
+          },
+        }
+      },
+    })
     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},
+      {repo: this.users[user].did, rkey},
       {
-        did: 'did:web:fake.com',
-        displayName: 'alices feed',
+        did: fg1.did,
+        displayName: rkey,
         description: 'all my fav stuff',
         avatar: avatarRes.data.blob,
         createdAt: new Date().toISOString(),