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' ;
@@ -16,8 +18,8 @@ export async function setup(project: TestProject) {
16
18
handler : manager ,
17
19
} ) ;
18
20
19
- await createAccount ( rpc , 'alice.test' ) ;
20
- await createAccount ( rpc , 'bob.test' ) ;
21
+ await createAccount ( rpc , 'alice.test' , manager ) ;
22
+ await createAccount ( rpc , 'bob.test' , manager ) ;
21
23
22
24
project . provide ( 'testPdsUrl' , network . pds . url ) ;
23
25
project . provide ( 'testPlcUrl' , network . plc . url ) ;
@@ -27,7 +29,16 @@ export async function teardown() {
27
29
await network . close ( ) ;
28
30
}
29
31
30
- const createAccount = async ( rpc : XRPC , handle : string ) => {
32
+ // sleep function with promise
33
+ function sleep ( sec : number ) {
34
+ return new Promise ( ( res ) => setTimeout ( res , sec * 1000 ) ) ;
35
+ }
36
+
37
+ const createAccount = async (
38
+ rpc : XRPC ,
39
+ handle : string ,
40
+ manager : CredentialManager ,
41
+ ) => {
31
42
await rpc . call ( 'com.atproto.server.createAccount' , {
32
43
data : {
33
44
handle : handle ,
@@ -36,6 +47,87 @@ const createAccount = async (rpc: XRPC, handle: string) => {
36
47
} ,
37
48
} ) ;
38
49
console . log ( `🙋 Created new account: @${ handle } ` ) ;
50
+
51
+ // authenticate
52
+ // create post
53
+ await manager . login ( { identifier : 'alice.test' , password : 'password' } ) ;
54
+
55
+ const { data : post } = await rpc . call ( 'com.atproto.repo.createRecord' , {
56
+ data : {
57
+ repo : 'alice.test' ,
58
+ collection : 'app.bsky.feed.post' ,
59
+ record : {
60
+ $type : 'app.bsky.feed.post' ,
61
+ createdAt : new Date ( ) . toISOString ( ) ,
62
+ text : "Hi, I'm Alice!" ,
63
+ langs : [ 'en' ] ,
64
+ } ,
65
+ } ,
66
+ } ) ;
67
+ // console.log(`* post=${JSON.stringify(post, null, 2)}`);
68
+ /*
69
+ * post={
70
+ "uri": "at://did:plc:gcd4sqigo6mdn4njqwejknux/app.bsky.feed.post/3lik4gtsx5s2c",
71
+ "cid": "bafyreieqmqwthbpxhep2v3pu4zske2gekvwomzlzjlnt5ambn2vftcbyj4",
72
+ "commit": {
73
+ "cid": "bafyreidxz4gbxqk4bku7g3mk46hfk3ggz7i2eb547hlicboc2xg2y6nn7y",
74
+ "rev": "3lik4gtt32s2c"
75
+ },
76
+ "validationStatus": "valid"
77
+ }
78
+ */
79
+
80
+ const { buffer } = await fs . readFile (
81
+ 'bafkreifl3xu4hsmmlov54dcblrswri3xrjm6aivrj5zvrqdmgkuyuontpm.jpeg' ,
82
+ ) ;
83
+ const { data : blob } = await rpc . call ( 'com.atproto.repo.uploadBlob' , {
84
+ headers : { 'content-type' : 'image/jpeg' } ,
85
+ data : buffer ,
86
+ } ) ;
87
+ // console.log(`* blob=${JSON.stringify(blob, null, 2)}`);
88
+ /*
89
+ {
90
+ "blob": {
91
+ "$type": "blob",
92
+ "ref": {
93
+ "$link": "bafkreifl3xu4hsmmlov54dcblrswri3xrjm6aivrj5zvrqdmgkuyuontpm"
94
+ },
95
+ "mimeType": "image/jpeg",
96
+ "size": 315488
97
+ }
98
+ }
99
+ */
100
+
101
+ const { data : profile } = await rpc . call ( 'com.atproto.repo.createRecord' , {
102
+ data : {
103
+ repo : 'alice.test' ,
104
+ collection : 'app.bsky.actor.profile' ,
105
+ record : {
106
+ $type : 'app.bsky.actor.profile' ,
107
+ avatar : blob . blob ,
108
+ // avatar: {
109
+ // cid: blob.blob.ref.$link,
110
+ // mimeType: blob.blob.mimeType,
111
+ // size: blob.blob.size,
112
+ // },
113
+ createdAt : new Date ( ) . toISOString ( ) ,
114
+ description : "I'm Alice!" ,
115
+ displayName : 'alice' ,
116
+ } ,
117
+ } ,
118
+ } ) ;
119
+ console . log ( `profile=${ JSON . stringify ( profile , null , 2 ) } ` ) ;
120
+
121
+ const { data : records } = await rpc . get ( 'com.atproto.repo.listRecords' , {
122
+ params : {
123
+ repo : 'alice.test' ,
124
+ collection : 'app.bsky.actor.profile' ,
125
+ // collection: 'app.bsky.feed.post',
126
+ } ,
127
+ } ) ;
128
+ console . log ( `* records=${ JSON . stringify ( records , null , 2 ) } ` ) ;
129
+
130
+ await sleep ( 60 * 10 ) ;
39
131
} ;
40
132
41
133
declare module 'vitest' {
0 commit comments