fix unit test

This commit is contained in:
tamaina 2025-07-17 14:55:52 +09:00
parent a6cdcfb2cf
commit bbdfb421f5
1 changed files with 35 additions and 8 deletions

View File

@ -26,6 +26,9 @@ import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
import { ModerationLogService } from '@/core/ModerationLogService.js'; import { ModerationLogService } from '@/core/ModerationLogService.js';
import { secureRndstr } from '@/misc/secure-rndstr.js'; import { secureRndstr } from '@/misc/secure-rndstr.js';
import { randomString } from '../utils.js'; import { randomString } from '../utils.js';
import { ApDeliverManagerService } from '@/core/activitypub/ApDeliverManagerService.js';
import { RelayService } from '@/core/RelayService.js';
import { ApLoggerService } from '@/core/activitypub/ApLoggerService.js';
function genHost() { function genHost() {
return randomString() + '.example.com'; return randomString() + '.example.com';
@ -42,6 +45,8 @@ describe('UserSuspendService', () => {
let globalEventService: jest.Mocked<GlobalEventService>; let globalEventService: jest.Mocked<GlobalEventService>;
let apRendererService: jest.Mocked<ApRendererService>; let apRendererService: jest.Mocked<ApRendererService>;
let moderationLogService: jest.Mocked<ModerationLogService>; let moderationLogService: jest.Mocked<ModerationLogService>;
let apDeliverManagerService: jest.Mocked<ApDeliverManagerService>;
let relayService: jest.Mocked<RelayService>;
async function createUser(data: Partial<MiUser> = {}): Promise<MiUser> { async function createUser(data: Partial<MiUser> = {}): Promise<MiUser> {
const user = { const user = {
@ -84,6 +89,7 @@ describe('UserSuspendService', () => {
imports: [GlobalModule], imports: [GlobalModule],
providers: [ providers: [
UserSuspendService, UserSuspendService,
ApDeliverManagerService,
{ {
provide: UserEntityService, provide: UserEntityService,
useFactory: () => ({ useFactory: () => ({
@ -94,6 +100,7 @@ describe('UserSuspendService', () => {
{ {
provide: QueueService, provide: QueueService,
useFactory: () => ({ useFactory: () => ({
deliverMany: jest.fn(),
deliver: jest.fn(), deliver: jest.fn(),
}), }),
}, },
@ -103,20 +110,38 @@ describe('UserSuspendService', () => {
publishInternalEvent: jest.fn(), publishInternalEvent: jest.fn(),
}), }),
}, },
{
provide: ApRendererService,
useFactory: () => ({
addContext: jest.fn(),
renderDelete: jest.fn(),
renderUndo: jest.fn(),
}),
},
{ {
provide: ModerationLogService, provide: ModerationLogService,
useFactory: () => ({ useFactory: () => ({
log: jest.fn(), log: jest.fn(),
}), }),
}, },
{
provide: RelayService,
useFactory: () => ({
deliverToRelays: jest.fn(),
}),
},
{
provide: ApRendererService,
useFactory: () => ({
renderDelete: jest.fn(),
renderUndo: jest.fn(),
renderPerson: jest.fn(),
renderUpdate: jest.fn(),
addContext: jest.fn(),
}),
},
{
provide: ApLoggerService,
useFactory: () => ({
logger: {
createSubLogger: jest.fn().mockReturnValue({
info: jest.fn(), error: jest.fn(), warn: jest.fn(), debug: jest.fn(),
}),
},
}),
},
], ],
}).compile(); }).compile();
@ -131,6 +156,8 @@ describe('UserSuspendService', () => {
globalEventService = app.get<GlobalEventService>(GlobalEventService) as jest.Mocked<GlobalEventService>; globalEventService = app.get<GlobalEventService>(GlobalEventService) as jest.Mocked<GlobalEventService>;
apRendererService = app.get<ApRendererService>(ApRendererService) as jest.Mocked<ApRendererService>; apRendererService = app.get<ApRendererService>(ApRendererService) as jest.Mocked<ApRendererService>;
moderationLogService = app.get<ModerationLogService>(ModerationLogService) as jest.Mocked<ModerationLogService>; moderationLogService = app.get<ModerationLogService>(ModerationLogService) as jest.Mocked<ModerationLogService>;
apDeliverManagerService = app.get<ApDeliverManagerService>(ApDeliverManagerService) as jest.Mocked<ApDeliverManagerService>;
relayService = app.get<RelayService>(RelayService) as jest.Mocked<RelayService>;
// Reset mocks // Reset mocks
jest.clearAllMocks(); jest.clearAllMocks();