FoundKey/packages/backend/test/misc/mock-resolver.mjs
Johann150 38786b6999
transform tests from ts to js
This allows to get rid of the special loader for ts files. There is
no need for the test files to be written in TypeScript, plain
JavaScript should be fine for this purpose.
2023-06-01 23:21:03 +02:00

31 lines
610 B
JavaScript

import { Resolver } from '../../built/remote/activitypub/resolver.js';
export class MockResolver extends Resolver {
_rs = new Map();
async _register(uri, content, type = 'application/activity+json') {
this._rs.set(uri, {
type,
content: typeof content === 'string' ? content : JSON.stringify(content),
});
}
async resolve(value) {
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;
}
}