Skip to content

Commit 3e63566

Browse files
authored
test: prefill profile data for Alice and Bob (#66)
1 parent 3c2af13 commit 3e63566

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

packages/client/alice-avatar.jpeg

57.3 KB
Loading

packages/client/globalSetup.ts

+52-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
import fs from 'node:fs/promises';
2+
13
import type { TestProject } from 'vitest/node';
24

35
import { CredentialManager, XRPC } from '@atcute/client';
46
import { TestNetwork } from '@atcute/internal-dev-env';
57

8+
declare module 'vitest' {
9+
export interface ProvidedContext {
10+
testPdsUrl: string;
11+
testPlcUrl: string;
12+
}
13+
}
14+
615
let network: TestNetwork;
716

817
export async function setup(project: TestProject) {
@@ -19,6 +28,14 @@ export async function setup(project: TestProject) {
1928
await createAccount(rpc, 'alice.test');
2029
await createAccount(rpc, 'bob.test');
2130

31+
await manager.login({ identifier: 'alice.test', password: 'password' });
32+
await createProfileRecord(rpc, 'alice.test');
33+
await createSamplePosts(rpc, 'alice.test');
34+
35+
await manager.login({ identifier: 'bob.test', password: 'password' });
36+
await createProfileRecord(rpc, 'bob.test');
37+
await createSamplePosts(rpc, 'bob.test');
38+
2239
project.provide('testPdsUrl', network.pds.url);
2340
project.provide('testPlcUrl', network.plc.url);
2441
}
@@ -38,9 +55,39 @@ const createAccount = async (rpc: XRPC, handle: string) => {
3855
console.log(`🙋 Created new account: @${handle}`);
3956
};
4057

41-
declare module 'vitest' {
42-
export interface ProvidedContext {
43-
testPdsUrl: string;
44-
testPlcUrl: string;
45-
}
58+
async function createProfileRecord(rpc: XRPC, handle: string) {
59+
const imageBuffer = await fs.readFile('alice-avatar.jpeg');
60+
const { data: blob } = await rpc.call('com.atproto.repo.uploadBlob', {
61+
headers: { 'content-type': 'image/jpeg' },
62+
data: imageBuffer,
63+
});
64+
65+
await rpc.call('com.atproto.repo.createRecord', {
66+
data: {
67+
repo: handle,
68+
collection: 'app.bsky.actor.profile',
69+
record: {
70+
$type: 'app.bsky.actor.profile',
71+
avatar: blob.blob,
72+
createdAt: new Date().toISOString(),
73+
description: "I'm Alice!",
74+
displayName: 'alice',
75+
},
76+
},
77+
});
78+
}
79+
80+
async function createSamplePosts(rpc: XRPC, handle: string) {
81+
await rpc.call('com.atproto.repo.createRecord', {
82+
data: {
83+
repo: handle,
84+
collection: 'app.bsky.feed.post',
85+
record: {
86+
$type: 'app.bsky.feed.post',
87+
createdAt: new Date().toISOString(),
88+
text: `Hi, I'm ${handle}!`,
89+
langs: ['en'],
90+
},
91+
},
92+
});
4693
}

packages/internal/dev-env/lib/pds.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ export class TestPdsServer {
114114
recursive: true,
115115
force: true,
116116
});
117-
await fs.rm(this.additional.blobstoreLoc, { force: true });
117+
await fs.rm(this.additional.blobstoreLoc, {
118+
recursive: true,
119+
force: true,
120+
});
118121
}
119122
}

0 commit comments

Comments
 (0)