mirror of
https://github.com/MisskeyIO/misskey
synced 2024-12-15 07:08:53 +09:00
8d06a6475e
* chore: 著作権とライセンスについての情報を各ファイルに追加する * chore: Add the SPDX information to each file Add copyright and licensing information as defined in version 3.0 of the REUSE Specification. * tweak format --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * chore: Add SPDX-License-Identifier [skip ci] * add missing SPDX-License-Identifier * remove unused file --------- Co-authored-by: Shun Sakai <sorairolake@protonmail.ch> Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> Co-authored-by: Chocolate Pie <106949016+chocolate-pie@users.noreply.github.com>
79 lines
2.3 KiB
TypeScript
79 lines
2.3 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
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';
|
|
|
|
type MockResponse = {
|
|
type: string;
|
|
content: string;
|
|
};
|
|
|
|
export class MockResolver extends Resolver {
|
|
#responseMap = new Map<string, MockResponse>();
|
|
#remoteGetTrials: string[] = [];
|
|
|
|
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,
|
|
);
|
|
}
|
|
|
|
public register(uri: string, content: string | Record<string, any>, type = 'application/activity+json'): void {
|
|
this.#responseMap.set(uri, {
|
|
type,
|
|
content: typeof content === 'string' ? content : JSON.stringify(content),
|
|
});
|
|
}
|
|
|
|
public clear(): void {
|
|
this.#responseMap.clear();
|
|
this.#remoteGetTrials.length = 0;
|
|
}
|
|
|
|
public remoteGetTrials(): string[] {
|
|
return this.#remoteGetTrials;
|
|
}
|
|
|
|
@bindThis
|
|
public async resolve(value: string | IObject): Promise<IObject> {
|
|
if (typeof value !== 'string') return value;
|
|
|
|
this.#remoteGetTrials.push(value);
|
|
const r = this.#responseMap.get(value);
|
|
|
|
if (!r) {
|
|
throw new Error('Not registed for mock');
|
|
}
|
|
|
|
const object = JSON.parse(r.content);
|
|
|
|
return object;
|
|
}
|
|
}
|