remove inline providers from unit tests

This commit is contained in:
Hazelnoot 2025-10-01 11:56:16 -04:00
parent 92892338f3
commit a3e969625d
6 changed files with 33 additions and 76 deletions

View file

@ -18,6 +18,7 @@ import { RelayService } from '@/core/RelayService.js';
import { SystemAccountService } from '@/core/SystemAccountService.js';
import { GlobalModule } from '@/GlobalModule.js';
import { UtilityService } from '@/core/UtilityService.js';
import { CoreModule } from '@/core/CoreModule.js';
const moduleMocker = new ModuleMocker(global);
@ -30,26 +31,17 @@ describe('RelayService', () => {
app = await Test.createTestingModule({
imports: [
GlobalModule,
],
providers: [
IdService,
ApRendererService,
RelayService,
UserEntityService,
SystemAccountService,
UtilityService,
CoreModule,
],
})
.useMocker((token) => {
if (token === QueueService) {
return { deliver: jest.fn() };
}
if (typeof token === 'function') {
const mockMetadata = moduleMocker.getMetadata(token) as MockFunctionMetadata<any, any>;
const Mock = moduleMocker.generateFromMetadata(mockMetadata);
return new Mock();
}
})
.overrideProvider(QueueService).useValue({ deliver: jest.fn() })
.compile();
await app.init();
@ -63,6 +55,10 @@ describe('RelayService', () => {
await app.close();
});
afterEach(() => {
queueService.deliver.mockReset();
});
test('addRelay', async () => {
const result = await relayService.addRelay('https://example.com');