wip
This commit is contained in:
parent
caca0da912
commit
79e5075564
|
@ -85,6 +85,7 @@ describe('AnnouncementService', () => {
|
||||||
})
|
})
|
||||||
.compile();
|
.compile();
|
||||||
|
|
||||||
|
await app.init();
|
||||||
app.enableShutdownHooks();
|
app.enableShutdownHooks();
|
||||||
|
|
||||||
announcementService = app.get<AnnouncementService>(AnnouncementService);
|
announcementService = app.get<AnnouncementService>(AnnouncementService);
|
||||||
|
|
|
@ -23,6 +23,7 @@ describe('DriveService', () => {
|
||||||
imports: [GlobalModule, CoreModule],
|
imports: [GlobalModule, CoreModule],
|
||||||
providers: [DriveService],
|
providers: [DriveService],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
await app.init();
|
||||||
app.enableShutdownHooks();
|
app.enableShutdownHooks();
|
||||||
driveService = app.get<DriveService>(DriveService);
|
driveService = app.get<DriveService>(DriveService);
|
||||||
});
|
});
|
||||||
|
|
|
@ -58,6 +58,7 @@ describe('FetchInstanceMetadataService', () => {
|
||||||
}})
|
}})
|
||||||
.compile();
|
.compile();
|
||||||
|
|
||||||
|
await app.init();
|
||||||
app.enableShutdownHooks();
|
app.enableShutdownHooks();
|
||||||
|
|
||||||
fetchInstanceMetadataService = app.get<FetchInstanceMetadataService>(FetchInstanceMetadataService);
|
fetchInstanceMetadataService = app.get<FetchInstanceMetadataService>(FetchInstanceMetadataService);
|
||||||
|
|
|
@ -50,6 +50,7 @@ describe('FileInfoService', () => {
|
||||||
})
|
})
|
||||||
.compile();
|
.compile();
|
||||||
|
|
||||||
|
await app.init();
|
||||||
app.enableShutdownHooks();
|
app.enableShutdownHooks();
|
||||||
|
|
||||||
fileInfoService = app.get<FileInfoService>(FileInfoService);
|
fileInfoService = app.get<FileInfoService>(FileInfoService);
|
||||||
|
|
|
@ -28,6 +28,7 @@ describe('MetaService', () => {
|
||||||
],
|
],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
|
await app.init();
|
||||||
app.enableShutdownHooks();
|
app.enableShutdownHooks();
|
||||||
|
|
||||||
metaService = app.get<MetaService>(MetaService, { strict: false });
|
metaService = app.get<MetaService>(MetaService, { strict: false });
|
||||||
|
|
|
@ -18,6 +18,7 @@ describe('MfmService', () => {
|
||||||
const app = await Test.createTestingModule({
|
const app = await Test.createTestingModule({
|
||||||
imports: [GlobalModule, CoreModule],
|
imports: [GlobalModule, CoreModule],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
await app.init();
|
||||||
mfmService = app.get<MfmService>(MfmService);
|
mfmService = app.get<MfmService>(MfmService);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
143
packages/backend/test/unit/NoteCreateService.ts
Normal file
143
packages/backend/test/unit/NoteCreateService.ts
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
process.env.NODE_ENV = 'test';
|
||||||
|
|
||||||
|
import { jest } from '@jest/globals';
|
||||||
|
import { ModuleMocker } from 'jest-mock';
|
||||||
|
import { Test } from '@nestjs/testing';
|
||||||
|
import * as Redis from 'ioredis';
|
||||||
|
import { GlobalModule } from '@/GlobalModule.js';
|
||||||
|
import type { UsersRepository, MiUser, NotesRepository } from '@/models/_.js';
|
||||||
|
import { DI } from '@/di-symbols.js';
|
||||||
|
import { genAidx } from '@/misc/id/aidx.js';
|
||||||
|
import { CacheService } from '@/core/CacheService.js';
|
||||||
|
import { IdService } from '@/core/IdService.js';
|
||||||
|
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
||||||
|
import { secureRndstr } from '@/misc/secure-rndstr.js';
|
||||||
|
import { NoteCreateService } from '@/core/NoteCreateService.js';
|
||||||
|
import { CoreModule } from '@/core/CoreModule.js';
|
||||||
|
import { MetaService } from '@/core/MetaService.js';
|
||||||
|
import { RoleService } from '@/core/RoleService.js';
|
||||||
|
import NotesChart from '@/core/chart/charts/notes.js';
|
||||||
|
import PerUserNotesChart from '@/core/chart/charts/per-user-notes.js';
|
||||||
|
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||||
|
import { HashtagService } from '@/core/HashtagService.js';
|
||||||
|
import { AntennaService } from '@/core/AntennaService.js';
|
||||||
|
import ActiveUsersChart from '@/core/chart/charts/active-users.js';
|
||||||
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
||||||
|
import { ApPersonService } from '@/core/activitypub/models/ApPersonService.js';
|
||||||
|
import { UtilityService } from '@/core/UtilityService.js';
|
||||||
|
import { sleep } from '../utils.js';
|
||||||
|
import type { TestingModule } from '@nestjs/testing';
|
||||||
|
import type { MockFunctionMetadata } from 'jest-mock';
|
||||||
|
|
||||||
|
const moduleMocker = new ModuleMocker(global);
|
||||||
|
|
||||||
|
describe('NoteCreateService', () => {
|
||||||
|
let app: TestingModule;
|
||||||
|
let noteCreateService: NoteCreateService;
|
||||||
|
let usersRepository: UsersRepository;
|
||||||
|
let notesRepository: NotesRepository;
|
||||||
|
let globalEventService: jest.Mocked<GlobalEventService>;
|
||||||
|
let redisForTimelines: jest.Mocked<Redis.Redis>;
|
||||||
|
|
||||||
|
function createUser(data: Partial<MiUser> = {}) {
|
||||||
|
const un = secureRndstr(16);
|
||||||
|
return usersRepository.insert({
|
||||||
|
id: genAidx(new Date()),
|
||||||
|
createdAt: new Date(),
|
||||||
|
username: un,
|
||||||
|
usernameLower: un,
|
||||||
|
...data,
|
||||||
|
})
|
||||||
|
.then(x => usersRepository.findOneByOrFail(x.identifiers[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
app = await Test.createTestingModule({
|
||||||
|
imports: [
|
||||||
|
GlobalModule,
|
||||||
|
//CoreModule,
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
UtilityService,
|
||||||
|
MetaService,
|
||||||
|
CacheService,
|
||||||
|
IdService,
|
||||||
|
RoleService,
|
||||||
|
NotesChart,
|
||||||
|
PerUserNotesChart,
|
||||||
|
ActiveUsersChart,
|
||||||
|
UserEntityService,
|
||||||
|
NoteEntityService,
|
||||||
|
HashtagService,
|
||||||
|
AntennaService,
|
||||||
|
NoteCreateService,
|
||||||
|
],
|
||||||
|
})
|
||||||
|
.useMocker((token) => {
|
||||||
|
if (token === GlobalEventService) {
|
||||||
|
return {
|
||||||
|
publishNotesStream: jest.fn(),
|
||||||
|
publishMainStream: jest.fn(),
|
||||||
|
};
|
||||||
|
} else if (token === DI.redisForTimelines) {
|
||||||
|
return {
|
||||||
|
xadd: jest.fn(),
|
||||||
|
};
|
||||||
|
} else if (typeof token === 'function') {
|
||||||
|
const mockMetadata = moduleMocker.getMetadata(token) as MockFunctionMetadata<any, any>;
|
||||||
|
const Mock = moduleMocker.generateFromMetadata(mockMetadata);
|
||||||
|
return new Mock();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.compile();
|
||||||
|
|
||||||
|
await app.init();
|
||||||
|
app.enableShutdownHooks();
|
||||||
|
|
||||||
|
noteCreateService = app.get<NoteCreateService>(NoteCreateService);
|
||||||
|
usersRepository = app.get<UsersRepository>(DI.usersRepository);
|
||||||
|
globalEventService = app.get<GlobalEventService>(GlobalEventService) as jest.Mocked<GlobalEventService>;
|
||||||
|
redisForTimelines = app.get<Redis.Redis>(DI.redisForTimelines) as jest.Mocked<Redis.Redis>;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await Promise.all([
|
||||||
|
app.get(DI.metasRepository).delete({}),
|
||||||
|
usersRepository.delete({}),
|
||||||
|
notesRepository.delete({}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
await app.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('create', () => {
|
||||||
|
test('text', async () => {
|
||||||
|
const me = await createUser();
|
||||||
|
const follower = await createUser();
|
||||||
|
await app.get(DI.followingsRepository).insert({
|
||||||
|
id: genAidx(new Date()),
|
||||||
|
followerId: follower.id,
|
||||||
|
followeeId: me.id,
|
||||||
|
createdAt: new Date(),
|
||||||
|
});
|
||||||
|
const result = await noteCreateService.create(me, {
|
||||||
|
text: 'Hello, Misskey!',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.text).toBe('Hello, Misskey!');
|
||||||
|
|
||||||
|
await sleep(100);
|
||||||
|
|
||||||
|
expect(globalEventService.publishNotesStream).toHaveBeenCalled();
|
||||||
|
expect(globalEventService.publishNotesStream.mock.lastCall![0].id).toBe(result.id);
|
||||||
|
expect(redisForTimelines.xadd).toHaveBeenCalled();
|
||||||
|
expect(redisForTimelines.xadd.mock.calls.some(call => call[0] === `homeTimeline:${follower.id}`)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -17,6 +17,7 @@ describe('ReactionService', () => {
|
||||||
const app = await Test.createTestingModule({
|
const app = await Test.createTestingModule({
|
||||||
imports: [GlobalModule, CoreModule],
|
imports: [GlobalModule, CoreModule],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
await app.init();
|
||||||
reactionService = app.get<ReactionService>(ReactionService);
|
reactionService = app.get<ReactionService>(ReactionService);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ describe('RelayService', () => {
|
||||||
})
|
})
|
||||||
.compile();
|
.compile();
|
||||||
|
|
||||||
|
await app.init();
|
||||||
app.enableShutdownHooks();
|
app.enableShutdownHooks();
|
||||||
|
|
||||||
relayService = app.get<RelayService>(RelayService);
|
relayService = app.get<RelayService>(RelayService);
|
||||||
|
|
|
@ -87,6 +87,7 @@ describe('RoleService', () => {
|
||||||
})
|
})
|
||||||
.compile();
|
.compile();
|
||||||
|
|
||||||
|
await app.init();
|
||||||
app.enableShutdownHooks();
|
app.enableShutdownHooks();
|
||||||
|
|
||||||
roleService = app.get<RoleService>(RoleService);
|
roleService = app.get<RoleService>(RoleService);
|
||||||
|
|
|
@ -24,6 +24,7 @@ describe('S3Service', () => {
|
||||||
imports: [GlobalModule, CoreModule],
|
imports: [GlobalModule, CoreModule],
|
||||||
providers: [S3Service],
|
providers: [S3Service],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
await app.init();
|
||||||
app.enableShutdownHooks();
|
app.enableShutdownHooks();
|
||||||
s3Service = app.get<S3Service>(S3Service);
|
s3Service = app.get<S3Service>(S3Service);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue