This commit is contained in:
tamaina 2023-04-22 17:12:40 +00:00
parent f3e3e0adb5
commit 5a4fc6e135

View file

@ -7,6 +7,7 @@ import { GlobalModule } from '@/GlobalModule.js';
import { RelayService } from '@/core/RelayService.js'; import { RelayService } from '@/core/RelayService.js';
import { ApRendererService } from '@/core/activitypub/ApRendererService.js'; import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
import { CreateSystemUserService } from '@/core/CreateSystemUserService.js'; import { CreateSystemUserService } from '@/core/CreateSystemUserService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { QueueService } from '@/core/QueueService.js'; import { QueueService } from '@/core/QueueService.js';
import { IdService } from '@/core/IdService.js'; import { IdService } from '@/core/IdService.js';
import type { RelaysRepository } from '@/models/index.js'; import type { RelaysRepository } from '@/models/index.js';
@ -21,6 +22,7 @@ describe('RelayService', () => {
let relayService: RelayService; let relayService: RelayService;
let queueService: jest.Mocked<QueueService>; let queueService: jest.Mocked<QueueService>;
let relaysRepository: RelaysRepository; let relaysRepository: RelaysRepository;
let userEntityService: UserEntityService;
beforeAll(async () => { beforeAll(async () => {
app = await Test.createTestingModule({ app = await Test.createTestingModule({
@ -32,6 +34,7 @@ describe('RelayService', () => {
CreateSystemUserService, CreateSystemUserService,
ApRendererService, ApRendererService,
RelayService, RelayService,
UserEntityService,
], ],
}) })
.useMocker((token) => { .useMocker((token) => {
@ -51,6 +54,7 @@ describe('RelayService', () => {
relayService = app.get<RelayService>(RelayService); relayService = app.get<RelayService>(RelayService);
queueService = app.get<QueueService>(QueueService) as jest.Mocked<QueueService>; queueService = app.get<QueueService>(QueueService) as jest.Mocked<QueueService>;
relaysRepository = app.get<RelaysRepository>(DI.relaysRepository); relaysRepository = app.get<RelaysRepository>(DI.relaysRepository);
userEntityService = app.get<UserEntityService>(UserEntityService);
}); });
afterAll(async () => { afterAll(async () => {
@ -63,7 +67,7 @@ describe('RelayService', () => {
expect(result.inbox).toBe('https://example.com'); expect(result.inbox).toBe('https://example.com');
expect(result.status).toBe('requesting'); expect(result.status).toBe('requesting');
expect(queueService.deliver).toHaveBeenCalled(); expect(queueService.deliver).toHaveBeenCalled();
expect(queueService.deliver.mock.lastCall![1].type).toBe('Follow'); expect(queueService.deliver.mock.lastCall![1]?.type).toBe('Follow');
expect(queueService.deliver.mock.lastCall![2]).toBe('https://example.com'); expect(queueService.deliver.mock.lastCall![2]).toBe('https://example.com');
//expect(queueService.deliver.mock.lastCall![0].username).toBe('relay.actor'); //expect(queueService.deliver.mock.lastCall![0].username).toBe('relay.actor');
}); });
@ -80,8 +84,8 @@ describe('RelayService', () => {
await relayService.removeRelay('https://example.com'); await relayService.removeRelay('https://example.com');
expect(queueService.deliver).toHaveBeenCalled(); expect(queueService.deliver).toHaveBeenCalled();
expect(queueService.deliver.mock.lastCall![1].type).toBe('Undo'); expect(queueService.deliver.mock.lastCall![1]?.type).toBe('Undo');
expect(queueService.deliver.mock.lastCall![1].object.type).toBe('Follow'); expect(queueService.deliver.mock.lastCall![1]?.object.type).toBe('Follow');
expect(queueService.deliver.mock.lastCall![2]).toBe('https://example.com'); expect(queueService.deliver.mock.lastCall![2]).toBe('https://example.com');
//expect(queueService.deliver.mock.lastCall![0].username).toBe('relay.actor'); //expect(queueService.deliver.mock.lastCall![0].username).toBe('relay.actor');