Skip to content

Commit

Permalink
Merge remote-branch 'misskey/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
noridev committed Dec 22, 2023
2 parents 0678bf6 + 433d46e commit df37667
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
13 changes: 10 additions & 3 deletions packages/backend/src/core/UserListService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/

import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';
import { Inject, Injectable, OnApplicationShutdown, OnModuleInit } from '@nestjs/common';
import * as Redis from 'ioredis';
import { ModuleRef } from '@nestjs/core';
import type { UserListMembershipsRepository } from '@/models/_.js';
import type { MiUser } from '@/models/User.js';
import type { MiUserList } from '@/models/UserList.js';
Expand All @@ -21,12 +22,15 @@ import { RedisKVCache } from '@/misc/cache.js';
import { RoleService } from '@/core/RoleService.js';

@Injectable()
export class UserListService implements OnApplicationShutdown {
export class UserListService implements OnApplicationShutdown, OnModuleInit {
public static TooManyUsersError = class extends Error {};

public membersCache: RedisKVCache<Set<string>>;
private roleService: RoleService;

constructor(
private moduleRef: ModuleRef,

@Inject(DI.redis)
private redisClient: Redis.Redis,

Expand All @@ -38,7 +42,6 @@ export class UserListService implements OnApplicationShutdown {

private userEntityService: UserEntityService,
private idService: IdService,
private roleService: RoleService,
private globalEventService: GlobalEventService,
private proxyAccountService: ProxyAccountService,
private queueService: QueueService,
Expand All @@ -54,6 +57,10 @@ export class UserListService implements OnApplicationShutdown {
this.redisForSub.on('message', this.onMessage);
}

async onModuleInit() {
this.roleService = this.moduleRef.get(RoleService.name);
}

@bindThis
private async onMessage(_: string, data: string): Promise<void> {
const obj = JSON.parse(data);
Expand Down
15 changes: 7 additions & 8 deletions packages/backend/test/e2e/timelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ process.env.NODE_ENV = 'test';
process.env.FORCE_FOLLOW_REMOTE_USER_FOR_TESTING = 'true';

import * as assert from 'assert';
import { signup, api, post, react, startServer, waitFire, sleep, uploadUrl, randomString } from '../utils.js';
import { api, post, randomString, signup, sleep, startServer, uploadUrl } from '../utils.js';
import type { INestApplicationContext } from '@nestjs/common';
import type * as misskey from 'cherrypick-js';

function genHost() {
return randomString() + '.example.com';
Expand Down Expand Up @@ -366,8 +365,8 @@ describe('Timelines', () => {
await api('/following/create', { userId: bob.id }, alice);
await sleep(1000);
const [bobFile, carolFile] = await Promise.all([
uploadUrl(bob, 'https://raw.githubusercontent.com/misskey-dev/assets/main/icon.png'),
uploadUrl(carol, 'https://raw.githubusercontent.com/misskey-dev/assets/main/icon.png'),
uploadUrl(bob, 'https://raw.githubusercontent.com/misskey-dev/assets/main/public/icon.png'),
uploadUrl(carol, 'https://raw.githubusercontent.com/misskey-dev/assets/main/public/icon.png'),
]);
const bobNote1 = await post(bob, { text: 'hi' });
const bobNote2 = await post(bob, { fileIds: [bobFile.id] });
Expand Down Expand Up @@ -666,7 +665,7 @@ describe('Timelines', () => {
test.concurrent('[withFiles: true] ファイル付きノートのみ含まれる', async () => {
const [alice, bob] = await Promise.all([signup(), signup()]);

const file = await uploadUrl(bob, 'https://raw.githubusercontent.com/misskey-dev/assets/main/icon.png');
const file = await uploadUrl(bob, 'https://raw.githubusercontent.com/misskey-dev/assets/main/public/icon.png');
const bobNote1 = await post(bob, { text: 'hi' });
const bobNote2 = await post(bob, { fileIds: [file.id] });

Expand Down Expand Up @@ -804,7 +803,7 @@ describe('Timelines', () => {
test.concurrent('[withFiles: true] ファイル付きノートのみ含まれる', async () => {
const [alice, bob] = await Promise.all([signup(), signup()]);

const file = await uploadUrl(bob, 'https://raw.githubusercontent.com/misskey-dev/assets/main/icon.png');
const file = await uploadUrl(bob, 'https://raw.githubusercontent.com/misskey-dev/assets/main/public/icon.png');
const bobNote1 = await post(bob, { text: 'hi' });
const bobNote2 = await post(bob, { fileIds: [file.id] });

Expand Down Expand Up @@ -999,7 +998,7 @@ describe('Timelines', () => {

const list = await api('/users/lists/create', { name: 'list' }, alice).then(res => res.body);
await api('/users/lists/push', { listId: list.id, userId: bob.id }, alice);
const file = await uploadUrl(bob, 'https://raw.githubusercontent.com/misskey-dev/assets/main/icon.png');
const file = await uploadUrl(bob, 'https://raw.githubusercontent.com/misskey-dev/assets/main/public/icon.png');
const bobNote1 = await post(bob, { text: 'hi' });
const bobNote2 = await post(bob, { fileIds: [file.id] });

Expand Down Expand Up @@ -1158,7 +1157,7 @@ describe('Timelines', () => {
test.concurrent('[withFiles: true] ファイル付きノートのみ含まれる', async () => {
const [alice, bob] = await Promise.all([signup(), signup()]);

const file = await uploadUrl(bob, 'https://raw.githubusercontent.com/misskey-dev/assets/main/icon.png');
const file = await uploadUrl(bob, 'https://raw.githubusercontent.com/misskey-dev/assets/main/public/icon.png');
const bobNote1 = await post(bob, { text: 'hi' });
const bobNote2 = await post(bob, { fileIds: [file.id] });

Expand Down
20 changes: 17 additions & 3 deletions packages/backend/test/unit/RoleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,21 @@ describe('RoleService', () => {
CacheService,
IdService,
GlobalEventService,
{
provide: NotificationService,
useFactory: () => ({
createNotification: jest.fn(),
}),
},
{
provide: NotificationService.name,
useExisting: NotificationService,
},
],
})
.useMocker((token) => {
if (token === MetaService) {
return { fetch: jest.fn() };
} else if (token === NotificationService) {
return { createNotification: jest.fn() };
}
if (typeof token === 'function') {
const mockMetadata = moduleMocker.getMetadata(token) as MockFunctionMetadata<any, any>;
Expand All @@ -98,6 +106,8 @@ describe('RoleService', () => {

metaService = app.get<MetaService>(MetaService) as jest.Mocked<MetaService>;
notificationService = app.get<NotificationService>(NotificationService) as jest.Mocked<NotificationService>;

await roleService.onModuleInit();
});

afterEach(async () => {
Expand Down Expand Up @@ -284,10 +294,12 @@ describe('RoleService', () => {
const user = await createUser();
const role = await createRole({
isPublic: true,
name: 'a',
});

await roleService.assign(user.id, role.id);

clock.uninstall();
await sleep(100);

const assignments = await roleAssignmentsRepository.find({
Expand All @@ -301,7 +313,7 @@ describe('RoleService', () => {
expect(notificationService.createNotification).toHaveBeenCalled();
expect(notificationService.createNotification.mock.lastCall![0]).toBe(user.id);
expect(notificationService.createNotification.mock.lastCall![1]).toBe('roleAssigned');
expect(notificationService.createNotification.mock.lastCall![2]).toBe({
expect(notificationService.createNotification.mock.lastCall![2]).toEqual({
roleId: role.id,
});
});
Expand All @@ -310,10 +322,12 @@ describe('RoleService', () => {
const user = await createUser();
const role = await createRole({
isPublic: false,
name: 'a',
});

await roleService.assign(user.id, role.id);

clock.uninstall();
await sleep(100);

const assignments = await roleAssignmentsRepository.find({
Expand Down

0 comments on commit df37667

Please sign in to comment.