mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-15 10:53:08 +02:00
d071d18dd7
* wip * wip * fix * clean up * Update tsconfig.json * Update activitypub.ts * wip
35 lines
842 B
TypeScript
35 lines
842 B
TypeScript
import Resolver from '../../src/remote/activitypub/resolver.js';
|
|
import { IObject } from '../../src/remote/activitypub/type.js';
|
|
|
|
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;
|
|
}
|
|
}
|