summaryrefslogtreecommitdiff
path: root/packages/backend/test/unit
diff options
context:
space:
mode:
authorsyuilo <4439005+syuilo@users.noreply.github.com>2024-09-22 12:53:13 +0900
committerGitHub <noreply@github.com>2024-09-22 12:53:13 +0900
commit023fa30280e561e9921a2c83138af4cac01068ab (patch)
tree9c94734bd7cacdf28a66b9dfc9c4a8c2fb234604 /packages/backend/test/unit
parent:art: (diff)
downloadmisskey-023fa30280e561e9921a2c83138af4cac01068ab.tar.gz
misskey-023fa30280e561e9921a2c83138af4cac01068ab.tar.bz2
misskey-023fa30280e561e9921a2c83138af4cac01068ab.zip
refactor/perf(backend): provide metadata statically (#14601)
* wip * Update ReactionService.ts * Update ApiCallService.ts * Update timeline.ts * Update GlobalModule.ts * Update GlobalModule.ts * Update NoteEntityService.ts * wip * wip * wip * Update ApPersonService.ts * wip * Update GlobalModule.ts * Update mock-resolver.ts * Update RoleService.ts * Update activitypub.ts * Update activitypub.ts * Update activitypub.ts * Update activitypub.ts * Update activitypub.ts * clean up * Update utils.ts * Update UtilityService.ts * Revert "Update utils.ts" This reverts commit a27d4be764b78c1b5a9eac685e261fee49331d89. * Revert "Update UtilityService.ts" This reverts commit e5fd9e004c482cf099252201c0c1aa888e001430. * vuwa- * Revert "vuwa-" This reverts commit 0c3bd12472b4b9938cdff2d6f131e6800bc3724c. * Update entry.ts * Update entry.ts * Update entry.ts * Update entry.ts * Update jest.setup.ts
Diffstat (limited to 'packages/backend/test/unit')
-rw-r--r--packages/backend/test/unit/RoleService.ts45
-rw-r--r--packages/backend/test/unit/activitypub.ts21
2 files changed, 30 insertions, 36 deletions
diff --git a/packages/backend/test/unit/RoleService.ts b/packages/backend/test/unit/RoleService.ts
index b6cbe4c520..ef80d25f81 100644
--- a/packages/backend/test/unit/RoleService.ts
+++ b/packages/backend/test/unit/RoleService.ts
@@ -13,6 +13,7 @@ import * as lolex from '@sinonjs/fake-timers';
import { GlobalModule } from '@/GlobalModule.js';
import { RoleService } from '@/core/RoleService.js';
import {
+ MiMeta,
MiRole,
MiRoleAssignment,
MiUser,
@@ -41,7 +42,7 @@ describe('RoleService', () => {
let usersRepository: UsersRepository;
let rolesRepository: RolesRepository;
let roleAssignmentsRepository: RoleAssignmentsRepository;
- let metaService: jest.Mocked<MetaService>;
+ let meta: jest.Mocked<MiMeta>;
let notificationService: jest.Mocked<NotificationService>;
let clock: lolex.InstalledClock;
@@ -142,7 +143,7 @@ describe('RoleService', () => {
rolesRepository = app.get<RolesRepository>(DI.rolesRepository);
roleAssignmentsRepository = app.get<RoleAssignmentsRepository>(DI.roleAssignmentsRepository);
- metaService = app.get<MetaService>(MetaService) as jest.Mocked<MetaService>;
+ meta = app.get<MiMeta>(DI.meta) as jest.Mocked<MiMeta>;
notificationService = app.get<NotificationService>(NotificationService) as jest.Mocked<NotificationService>;
await roleService.onModuleInit();
@@ -164,11 +165,9 @@ describe('RoleService', () => {
describe('getUserPolicies', () => {
test('instance default policies', async () => {
const user = await createUser();
- metaService.fetch.mockResolvedValue({
- policies: {
- canManageCustomEmojis: false,
- },
- } as any);
+ meta.policies = {
+ canManageCustomEmojis: false,
+ };
const result = await roleService.getUserPolicies(user.id);
@@ -177,11 +176,9 @@ describe('RoleService', () => {
test('instance default policies 2', async () => {
const user = await createUser();
- metaService.fetch.mockResolvedValue({
- policies: {
- canManageCustomEmojis: true,
- },
- } as any);
+ meta.policies = {
+ canManageCustomEmojis: true,
+ };
const result = await roleService.getUserPolicies(user.id);
@@ -201,11 +198,9 @@ describe('RoleService', () => {
},
});
await roleService.assign(user.id, role.id);
- metaService.fetch.mockResolvedValue({
- policies: {
- canManageCustomEmojis: false,
- },
- } as any);
+ meta.policies = {
+ canManageCustomEmojis: false,
+ };
const result = await roleService.getUserPolicies(user.id);
@@ -236,11 +231,9 @@ describe('RoleService', () => {
});
await roleService.assign(user.id, role1.id);
await roleService.assign(user.id, role2.id);
- metaService.fetch.mockResolvedValue({
- policies: {
- driveCapacityMb: 50,
- },
- } as any);
+ meta.policies = {
+ driveCapacityMb: 50,
+ };
const result = await roleService.getUserPolicies(user.id);
@@ -260,11 +253,9 @@ describe('RoleService', () => {
},
});
await roleService.assign(user.id, role.id, new Date(Date.now() + (1000 * 60 * 60 * 24)));
- metaService.fetch.mockResolvedValue({
- policies: {
- canManageCustomEmojis: false,
- },
- } as any);
+ meta.policies = {
+ canManageCustomEmojis: false,
+ };
const result = await roleService.getUserPolicies(user.id);
expect(result.canManageCustomEmojis).toBe(true);
diff --git a/packages/backend/test/unit/activitypub.ts b/packages/backend/test/unit/activitypub.ts
index 763ce2b336..2fc08aec91 100644
--- a/packages/backend/test/unit/activitypub.ts
+++ b/packages/backend/test/unit/activitypub.ts
@@ -24,7 +24,6 @@ import { MiMeta, MiNote, UserProfilesRepository } from '@/models/_.js';
import { DI } from '@/di-symbols.js';
import { secureRndstr } from '@/misc/secure-rndstr.js';
import { DownloadService } from '@/core/DownloadService.js';
-import { MetaService } from '@/core/MetaService.js';
import type { MiRemoteUser } from '@/models/User.js';
import { genAidx } from '@/misc/id/aidx.js';
import { MockResolver } from '../misc/mock-resolver.js';
@@ -107,7 +106,14 @@ describe('ActivityPub', () => {
sensitiveWords: [] as string[],
prohibitedWords: [] as string[],
} as MiMeta;
- let meta = metaInitial;
+ const meta = { ...metaInitial };
+
+ function updateMeta(newMeta: Partial<MiMeta>): void {
+ for (const key in meta) {
+ delete (meta as any)[key];
+ }
+ Object.assign(meta, newMeta);
+ }
beforeAll(async () => {
const app = await Test.createTestingModule({
@@ -120,11 +126,8 @@ describe('ActivityPub', () => {
};
},
})
- .overrideProvider(MetaService).useValue({
- async fetch(): Promise<MiMeta> {
- return meta;
- },
- }).compile();
+ .overrideProvider(DI.meta).useFactory({ factory: () => meta })
+ .compile();
await app.init();
app.enableShutdownHooks();
@@ -367,7 +370,7 @@ describe('ActivityPub', () => {
});
test('cacheRemoteFiles=false disables caching', async () => {
- meta = { ...metaInitial, cacheRemoteFiles: false };
+ updateMeta({ ...metaInitial, cacheRemoteFiles: false });
const imageObject: IApDocument = {
type: 'Document',
@@ -396,7 +399,7 @@ describe('ActivityPub', () => {
});
test('cacheRemoteSensitiveFiles=false only affects sensitive files', async () => {
- meta = { ...metaInitial, cacheRemoteSensitiveFiles: false };
+ updateMeta({ ...metaInitial, cacheRemoteSensitiveFiles: false });
const imageObject: IApDocument = {
type: 'Document',