Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自動テストを修正 #564

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion packages/backend/src/core/AvatarDecorationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class AvatarDecorationService implements OnApplicationShutdown {
return;
}

const instanceHost = instance.host;
const instanceHost = instance!.host;
const decorationApiUrl = `https://${instanceHost}/api/get-avatar-decorations`;
const allRes = await this.httpRequestService.send(decorationApiUrl, {
method: 'POST',
Expand Down
14 changes: 10 additions & 4 deletions packages/backend/src/core/CustomEmojiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { bindThis } from '@/decorators.js';
import { DI } from '@/di-symbols.js';
import { MemoryKVCache, RedisSingleCache } from '@/misc/cache.js';
import { sqlLikeEscape } from '@/misc/sql-like-escape.js';
import type { EmojisRepository, MiRole, MiUser } from '@/models/_.js';
import type { DriveFilesRepository, EmojisRepository, MiRole, MiUser } from '@/models/_.js';
import type { MiEmoji } from '@/models/Emoji.js';
import type { Serialized } from '@/types.js';
import { DriveService } from '@/core/DriveService.js';
Expand Down Expand Up @@ -68,6 +68,8 @@ export class CustomEmojiService implements OnApplicationShutdown {
private redisClient: Redis.Redis,
@Inject(DI.emojisRepository)
private emojisRepository: EmojisRepository,
@Inject(DI.driveFilesRepository)
private driveFilesRepository: DriveFilesRepository,
private utilityService: UtilityService,
private idService: IdService,
private emojiEntityService: EmojiEntityService,
Expand Down Expand Up @@ -106,12 +108,16 @@ export class CustomEmojiService implements OnApplicationShutdown {
roleIdsThatCanBeUsedThisEmojiAsReaction: MiRole['id'][];
}, moderator?: MiUser): Promise<MiEmoji> {
// システムユーザーとして再アップロード
if (!data.driveFile.user?.isRoot) {
data.driveFile = await this.driveService.uploadFromUrl({
url: data.driveFile.url,
const driveFile = await this.driveFilesRepository.findOneBy({ url: data.originalUrl });
if (driveFile?.user !== null && !driveFile?.user.isRoot) {
const copyDriveFile = await this.driveService.uploadFromUrl({
url: data.originalUrl,
user: null,
force: true,
});
data.originalUrl = copyDriveFile.url;
data.publicUrl = copyDriveFile.webpublicUrl ?? copyDriveFile.url;
data.fileType = copyDriveFile.webpublicType ?? copyDriveFile.type;
}

const emoji = await this.emojisRepository.insertOne({
Expand Down
4 changes: 1 addition & 3 deletions packages/backend/src/core/TruncateAccountService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ export class TruncateAccountService {
}): Promise<void> {
const _user = await this.usersRepository.findOneByOrFail({ id: user.id });

this.queueService.createTruncateAccountJob(user, {
soft: false,
});
this.queueService.createTruncateAccountJob(user);
}
}

6 changes: 6 additions & 0 deletions packages/backend/src/core/WebhookTestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ function generateDummyNote(override?: Partial<MiNote>): MiNote {
replyUserHost: null,
renoteUserId: null,
renoteUserHost: null,
updatedAt: null,
updatedAtHistory: null,
noteEditHistory: [],
hasEvent: false,
disableRightClick: false,
deleteAt: null,
...override,
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/models/Meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ export class MiMeta {
public disablePublicNoteWhenInactive: boolean;

@Column('integer', {
nullable: false,
default: 7,
})
public moderatorInactivityLimitDays: number;

Expand Down
25 changes: 23 additions & 2 deletions packages/backend/src/models/json-schema/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,31 @@ export const packedNotificationSchema = {
optional: false, nullable: false,
enum: ['groupInvited'],
},
user: {
type: 'object',
ref: 'UserLite',
optional: false, nullable: false,
},
invitation: {
type: 'string',
type: 'object',
properties: {
id: {
type: 'string',
optional: false, nullable: false,
format: 'id',
},
group: {
type: 'object',
properties: {
name: {
type: 'string',
optional: false, nullable: false,
},
},
optional: false, nullable: false,
},
},
optional: false, nullable: false,
format: 'id',
},
},
}],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,10 @@ export class CheckModeratorsActivityProcessorService {

// -- SystemWebhook

const systemWebhooks = await this.systemWebhookService.fetchActiveSystemWebhooks()
.then(it => it.filter(it => it.on.includes('inactiveModeratorsDisablePublicNoteChanged')));
for (const systemWebhook of systemWebhooks) {
this.systemWebhookService.enqueueSystemWebhook(
systemWebhook,
'inactiveModeratorsDisablePublicNoteChanged',
{},
);
}
this.systemWebhookService.enqueueSystemWebhook(
'inactiveModeratorsDisablePublicNoteChanged',
{},
);
}

@bindThis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
let timeline = await query.limit(ps.limit).getMany();

timeline = timeline.filter(note => {
return !(note.user?.isSilenced && me && followings && note.userId !== me.id && !followings[note.userId]);
return !(note.user?.isSuspended && me && followings && note.userId !== me.id && !followings[note.userId]);
});

process.nextTick(() => {
Expand Down
20 changes: 14 additions & 6 deletions packages/backend/src/server/api/endpoints/notes/polls/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ export const meta = {
optional: true, nullable: false,
properties: {
sourceLang: { type: 'string' },
text: { type: 'string' },
text: {
type: 'array',
optional: true, nullable: false,
items: {
type: 'string',
optional: false, nullable: true,
},
},
},
},

Expand Down Expand Up @@ -130,7 +137,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

return Promise.resolve({
sourceLang: translationResult.sourceLang || '',
text: translationResult.text || '',
text: translationResult.text || [],
translator: translationResult.translator || [],
});
});
Expand Down Expand Up @@ -175,15 +182,16 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
};
}

private async apiCloudTranslationAdvanced(text: string, targetLang: string, saKey: string, projectId: string, location: string, model: string | null, glossary: string | null, provider: string) {
private async apiCloudTranslationAdvanced(text: string[], targetLang: string, saKey: string, projectId: string, location: string, model: string | null, glossary: string | null, provider: string) {
const [path, cleanup] = await createTemp();
fs.writeFileSync(path, saKey);

const translationClient = new TranslationServiceClient({ keyFilename: path });

const detectText = text.join('\n');
const detectRequest = {
parent: `projects/${projectId}/locations/${location}`,
content: text,
content: detectText,
};

let detectedLanguage = null;
Expand All @@ -203,15 +211,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

const translateRequest = {
parent: `projects/${projectId}/locations/${location}`,
contents: [text],
contents: text,
mimeType: 'text/plain',
sourceLanguageCode: null,
targetLanguageCode: detectedLanguage !== null ? detectedLanguage : targetLang,
model: modelConfig,
glossaryConfig: glossaryConfig,
};
const [translateResponse] = await translationClient.translateText(translateRequest);
const translatedText = translateResponse.translations && translateResponse.translations[0]?.translatedText;
const translatedText = translateResponse.translations && translateResponse.translations.map(t => t.translatedText ?? '');
const detectedLanguageCode = translateResponse.translations && translateResponse.translations[0]?.detectedLanguageCode;

cleanup();
Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/server/api/endpoints/notes/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const paramDef = {
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
origin: { type: 'string', enum: ['local', 'remote', 'combined'], default: 'combined' },
offset: { type: 'integer', default: 0 },
host: {
type: 'string',
Expand Down Expand Up @@ -72,7 +71,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
userId: ps.userId,
channelId: ps.channelId,
host: ps.host,
origin: ps.origin,
}, {
untilId: ps.untilId,
sinceId: ps.sinceId,
Expand Down
4 changes: 3 additions & 1 deletion packages/backend/src/server/api/stream/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ export default class Connection {
}

@bindThis
private typingOnMessaging(param: { partner?: MiUser['id']; group?: MiUserGroup['id']; }) {
private typingOnMessaging(data: JsonValue | undefined) {
if (!data) return;
const param = data as { partner?: MiUser['id']; group?: MiUserGroup['id']; };
if (this.user) {
if (param.partner) {
// this.globalEventService.publishMessagingStream(param.partner, this.user.id, 'typing', this.user.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class BubbleTimelineChannel extends Channel {

if (isRenotePacked(note) && !isQuotePacked(note) && !this.withRenotes) return;

if (note.user.isSilenced && !this.following[note.userId] && note.userId !== this.user!.id) return;
if (!this.following[note.userId] && note.userId !== this.user!.id) return;

if (this.isNoteMutedOrBlocked(note)) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class ReversiGameChannel extends Channel {
this.putStone(body.pos, body.id);
break;
case 'claimTimeIsUp': this.claimTimeIsUp(); break;
case 'reaction': this.sendReaction(body); break;
case 'reaction':
if (typeof body !== 'string') return;
this.sendReaction(body); break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/test/e2e/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ describe('Note', () => {

// NOTE: デフォルトでは登録されていないので落ちる
assert.strictEqual(res.status, 400);
assert.strictEqual(castAsError(res.body).error.code, 'UNAVAILABLE');
assert.strictEqual(castAsError(res.body).error.code, 'NO_TRANSLATE_SERVICE');
});
});
});
2 changes: 1 addition & 1 deletion packages/backend/test/e2e/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ describe('OAuth', () => {
bearer: true,
});
assert.strictEqual(createResult.status, 403);
assert.ok(createResult.headers.get('WWW-Authenticate')?.startsWith('Bearer realm="Misskey", error="insufficient_scope", error_description'));
assert.ok(createResult.headers.get('WWW-Authenticate')?.startsWith('Bearer realm="CherryPick", error="insufficient_scope", error_description'));
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/test/e2e/timelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ describe('Timelines', () => {
assert.strictEqual(res.body.some(note => note.id === bobNote2.id), true);
assert.strictEqual(res.body.some(note => note.id === carolNote1.id), false);
assert.strictEqual(res.body.some(note => note.id === carolNote2.id), false);
}, 1000 * 15);
}, 1000 * 30);

test.concurrent('フォローしているユーザーのチャンネル投稿が含まれない', async () => {
const [alice, bob] = await Promise.all([signup(), signup()]);
Expand Down
10 changes: 0 additions & 10 deletions packages/backend/test/unit/AbuseReportNotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,6 @@ describe('AbuseReportNotificationService', () => {
systemWebhookId: systemWebhook2.id,
isActive: false,
});
const recipient3 = await createRecipient({
method: 'webhook',
systemWebhookId: systemWebhook3.id,
isActive: false,
});
const recipient4 = await createRecipient({
method: 'webhook',
systemWebhookId: systemWebhook4.id,
isActive: false,
});

const reports: MiAbuseUserReport[] = [
{
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/test/unit/CustomEmojiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { DI } from '@/di-symbols.js';
import { GlobalModule } from '@/GlobalModule.js';
import { EmojisRepository } from '@/models/_.js';
import { MiEmoji } from '@/models/Emoji.js';
import { CoreModule } from '@/core/CoreModule.js';

describe('CustomEmojiService', () => {
let app: TestingModule;
Expand All @@ -27,7 +28,7 @@ describe('CustomEmojiService', () => {
app = await Test
.createTestingModule({
imports: [
GlobalModule,
GlobalModule, CoreModule,
],
providers: [
CustomEmojiService,
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/test/unit/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ describe('NoteCreateService', () => {
replyUserHost: null,
renoteUserId: null,
renoteUserHost: null,
updatedAt: null,
updatedAtHistory: null,
noteEditHistory: [],
hasEvent: false,
disableRightClick: false,
deleteAt: null,
};

const poll: IPoll = {
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/test/unit/misc/is-renote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ const base: MiNote = {
replyUserHost: null,
renoteUserId: null,
renoteUserHost: null,
updatedAt: null,
updatedAtHistory: null,
noteEditHistory: [],
hasEvent: false,
disableRightClick: false,
deleteAt: null,
};

describe('misc:is-renote', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ describe('CheckModeratorsActivityProcessorService', () => {
await service.notifyChangeToDisablePublicNote();

expect(systemWebhookService.enqueueSystemWebhook).toHaveBeenCalledTimes(1);
expect(systemWebhookService.enqueueSystemWebhook.mock.calls[0][0]).toEqual(systemWebhook3);
expect(systemWebhookService.enqueueSystemWebhook.mock.calls[0][0] as SystemWebhookEventType).toEqual('inactiveModeratorsDisablePublicNoteChanged');
});
});
});
10 changes: 9 additions & 1 deletion packages/cherrypick-js/etc/cherrypick-js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2485,7 +2485,15 @@ type ISigninHistoryRequest = operations['i___signin-history']['requestBody']['co
type ISigninHistoryResponse = operations['i___signin-history']['responses']['200']['content']['application/json'];

// @public (undocumented)
function isPureRenote(note: Note): note is PureRenote;
function isPureRenote(note: {
renote?: object | null;
reply?: object | null;
text: string | null;
cw?: string | null;
fileIds?: string[];
poll?: object | null;
event?: Record<string, never> | null;
}): note is PureRenote;

// @public (undocumented)
export interface IStream extends EventEmitter<StreamEvents> {
Expand Down
Loading
Loading