mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-04 07:24:13 +00:00 
			
		
		
		
	* AP Actorの修正 * Add ActivityPub test * Fix person * Test * ap test * Revert "Test" This reverts commit 3c493eff4e89f94fd33f25189ba3bc96ef4366b3. * Test comment * fix * fix * Update inbox * indent * nl * indent * TODO * Fix inbox * Update test
		
			
				
	
	
		
			35 lines
		
	
	
	
		
			836 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
	
		
			836 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import Resolver from '../../src/remote/activitypub/resolver';
 | 
						|
import { IObject } from '../../src/remote/activitypub/type';
 | 
						|
 | 
						|
type MockResponse = {
 | 
						|
	type: string;
 | 
						|
	content: string;
 | 
						|
};
 | 
						|
 | 
						|
export class MockResolver extends Resolver {
 | 
						|
	private _rs = new Map<string, MockResponse>();
 | 
						|
	public async _register(uri: string, content: string | Record<string, any>, type = 'application/activity+json') {
 | 
						|
		this._rs.set(uri, {
 | 
						|
			type,
 | 
						|
			content: typeof content === 'string' ? content : JSON.stringify(content)
 | 
						|
		});
 | 
						|
	}
 | 
						|
 | 
						|
	public async resolve(value: string | IObject): Promise<IObject> {
 | 
						|
		if (typeof value !== 'string') return value;
 | 
						|
 | 
						|
		const r = this._rs.get(value);
 | 
						|
 | 
						|
		if (!r) {
 | 
						|
			throw {
 | 
						|
				name: `StatusError`,
 | 
						|
				statusCode: 404,
 | 
						|
				message: `Not registed for mock`
 | 
						|
			};
 | 
						|
		}
 | 
						|
 | 
						|
		const object = JSON.parse(r.content);
 | 
						|
 | 
						|
		return object;
 | 
						|
	}
 | 
						|
}
 |