2023-07-27 14:31:52 +09:00
|
|
|
/*
|
2024-02-14 00:59:27 +09:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 14:31:52 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-02-19 15:27:14 +09: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';
|
2024-01-08 17:43:52 +09:00
|
|
|
import type {
|
|
|
|
FollowRequestsRepository,
|
2024-09-22 12:53:13 +09:00
|
|
|
MiMeta,
|
2024-01-08 17:43:52 +09:00
|
|
|
NoteReactionsRepository,
|
|
|
|
NotesRepository,
|
|
|
|
PollsRepository,
|
|
|
|
UsersRepository,
|
|
|
|
} from '@/models/_.js';
|
2021-07-10 23:14:57 +09:00
|
|
|
|
|
|
|
type MockResponse = {
|
|
|
|
type: string;
|
|
|
|
content: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export class MockResolver extends Resolver {
|
2023-07-09 08:59:44 +09:00
|
|
|
#responseMap = new Map<string, MockResponse>();
|
|
|
|
#remoteGetTrials: string[] = [];
|
2023-02-19 15:27:14 +09:00
|
|
|
|
|
|
|
constructor(loggerService: LoggerService) {
|
|
|
|
super(
|
|
|
|
{} as Config,
|
2024-09-22 12:53:13 +09:00
|
|
|
{} as MiMeta,
|
2023-02-19 15:27:14 +09:00
|
|
|
{} as UsersRepository,
|
|
|
|
{} as NotesRepository,
|
|
|
|
{} as PollsRepository,
|
|
|
|
{} as NoteReactionsRepository,
|
2023-09-22 16:43:01 +09:00
|
|
|
{} as FollowRequestsRepository,
|
2023-02-19 15:27:14 +09:00
|
|
|
{} as UtilityService,
|
|
|
|
{} as InstanceActorService,
|
|
|
|
{} as ApRequestService,
|
|
|
|
{} as HttpRequestService,
|
|
|
|
{} as ApRendererService,
|
|
|
|
{} as ApDbResolverService,
|
|
|
|
loggerService,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-07-09 08:59:44 +09:00
|
|
|
public register(uri: string, content: string | Record<string, any>, type = 'application/activity+json'): void {
|
|
|
|
this.#responseMap.set(uri, {
|
2021-07-10 23:14:57 +09:00
|
|
|
type,
|
2022-05-21 22:21:41 +09:00
|
|
|
content: typeof content === 'string' ? content : JSON.stringify(content),
|
2021-07-10 23:14:57 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-09 08:59:44 +09:00
|
|
|
public clear(): void {
|
|
|
|
this.#responseMap.clear();
|
|
|
|
this.#remoteGetTrials.length = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public remoteGetTrials(): string[] {
|
|
|
|
return this.#remoteGetTrials;
|
|
|
|
}
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2021-07-10 23:14:57 +09:00
|
|
|
public async resolve(value: string | IObject): Promise<IObject> {
|
|
|
|
if (typeof value !== 'string') return value;
|
|
|
|
|
2023-07-09 08:59:44 +09:00
|
|
|
this.#remoteGetTrials.push(value);
|
|
|
|
const r = this.#responseMap.get(value);
|
2021-07-10 23:14:57 +09:00
|
|
|
|
|
|
|
if (!r) {
|
2023-05-29 11:54:49 +09:00
|
|
|
throw new Error('Not registed for mock');
|
2021-07-10 23:14:57 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
const object = JSON.parse(r.content);
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
}
|