1+ import fs from 'node:fs/promises' ;
2+
13import type { TestProject } from 'vitest/node' ;
24
35import { CredentialManager , XRPC } from '@atcute/client' ;
46import { TestNetwork } from '@atcute/internal-dev-env' ;
57
8+ declare module 'vitest' {
9+ export interface ProvidedContext {
10+ testPdsUrl : string ;
11+ testPlcUrl : string ;
12+ }
13+ }
14+
615let network : TestNetwork ;
716
817export 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 { buffer } = 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 : buffer ,
63+ } ) ;
64+
65+ const { data : profile } = 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}
0 commit comments