1
+ import fs from 'node:fs/promises' ;
2
+
1
3
import type { TestProject } from 'vitest/node' ;
2
4
3
5
import { CredentialManager , XRPC } from '@atcute/client' ;
4
6
import { TestNetwork } from '@atcute/internal-dev-env' ;
5
7
8
+ declare module 'vitest' {
9
+ export interface ProvidedContext {
10
+ testPdsUrl : string ;
11
+ testPlcUrl : string ;
12
+ }
13
+ }
14
+
6
15
let network : TestNetwork ;
7
16
8
17
export async function setup ( project : TestProject ) {
@@ -19,6 +28,14 @@ export async function setup(project: TestProject) {
19
28
await createAccount ( rpc , 'alice.test' ) ;
20
29
await createAccount ( rpc , 'bob.test' ) ;
21
30
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
+
22
39
project . provide ( 'testPdsUrl' , network . pds . url ) ;
23
40
project . provide ( 'testPlcUrl' , network . plc . url ) ;
24
41
}
@@ -38,9 +55,39 @@ const createAccount = async (rpc: XRPC, handle: string) => {
38
55
console . log ( `🙋 Created new account: @${ handle } ` ) ;
39
56
} ;
40
57
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
+ } ) ;
46
93
}
0 commit comments