2023-02-18 22:27:14 -08:00
|
|
|
import type { Config } from '@/config.js';
|
|
|
|
import type { ApDbResolverService } from '@/core/activitypub/ApDbResolverService.js';
|
|
|
|
import type { ApRendererService } from '@/core/activitypub/ApRendererService.js';
|
|
|
|
import type { ApRequestService } from '@/core/activitypub/ApRequestService.js';
|
|
|
|
import { Resolver } from '@/core/activitypub/ApResolverService.js';
|
|
|
|
import type { IObject } from '@/core/activitypub/type.js';
|
|
|
|
import type { HttpRequestService } from '@/core/HttpRequestService.js';
|
|
|
|
import type { InstanceActorService } from '@/core/InstanceActorService.js';
|
|
|
|
import type { LoggerService } from '@/core/LoggerService.js';
|
|
|
|
import type { MetaService } from '@/core/MetaService.js';
|
|
|
|
import type { UtilityService } from '@/core/UtilityService.js';
|
|
|
|
import { bindThis } from '@/decorators.js';
|
|
|
|
import type { NoteReactionsRepository, NotesRepository, PollsRepository, UsersRepository } from '@/models/index.js';
|
2021-07-10 07:14:57 -07:00
|
|
|
|
|
|
|
type MockResponse = {
|
|
|
|
type: string;
|
|
|
|
content: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export class MockResolver extends Resolver {
|
|
|
|
private _rs = new Map<string, MockResponse>();
|
2023-02-18 22:27:14 -08:00
|
|
|
|
|
|
|
constructor(loggerService: LoggerService) {
|
|
|
|
super(
|
|
|
|
{} as Config,
|
|
|
|
{} as UsersRepository,
|
|
|
|
{} as NotesRepository,
|
|
|
|
{} as PollsRepository,
|
|
|
|
{} as NoteReactionsRepository,
|
|
|
|
{} as UtilityService,
|
|
|
|
{} as InstanceActorService,
|
|
|
|
{} as MetaService,
|
|
|
|
{} as ApRequestService,
|
|
|
|
{} as HttpRequestService,
|
|
|
|
{} as ApRendererService,
|
|
|
|
{} as ApDbResolverService,
|
|
|
|
loggerService,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-10 07:14:57 -07:00
|
|
|
public async _register(uri: string, content: string | Record<string, any>, type = 'application/activity+json') {
|
|
|
|
this._rs.set(uri, {
|
|
|
|
type,
|
2022-05-21 06:21:41 -07:00
|
|
|
content: typeof content === 'string' ? content : JSON.stringify(content),
|
2021-07-10 07:14:57 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-03 22:03:09 -08:00
|
|
|
@bindThis
|
2021-07-10 07:14:57 -07:00
|
|
|
public async resolve(value: string | IObject): Promise<IObject> {
|
|
|
|
if (typeof value !== 'string') return value;
|
|
|
|
|
|
|
|
const r = this._rs.get(value);
|
|
|
|
|
|
|
|
if (!r) {
|
2023-05-28 19:54:49 -07:00
|
|
|
throw new Error('Not registed for mock');
|
2021-07-10 07:14:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const object = JSON.parse(r.content);
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
}
|