mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-05 00:45:50 +02:00
* wip * update fake-timers and migrate * fix * remove jest-mock * fix * fix * fix * fix * attempt to fix unit tests * attempt to fix e2e tests * fix federation test [ci skip] * attempt to fix e2e tests * fix typecheck * fix unit tests * fix * attempt to fix e2e * fix * Revert "attempt to fix e2e" This reverts commitb7b7b05d85. * attempt to fix e2e * revert attempt to fix e2e * update deps * update vitest * migrate * attempt to fix e2e * update * fix * remove vite swc plugin as oxc parser can handle decorators * attempt to fix drive/files/create test * Revert "attempt to fix drive/files/create test" This reverts commit4715153375. * fix: エンドポイントにまつわるテストをunitからe2eに移動 * attempt to fix e2e * remove swc * attempt to fix e2e * Revert "attempt to fix e2e" This reverts commit9fb86a4076. * add logs for debug * attempt to fix e2e * Partially revert "attempt to fix e2e" This reverts commitfb0008c85a. * attempt to fix test * fix: attempt to fix test * Revert "fix: attempt to fix test" This reverts commited2f5c40e8. * Revert "attempt to fix test" This reverts commitd7329c46f1. * attempt to fix e2e * fix: surpass eventemitter warning by increasing defaultMaxListeners * attempt to fix e2e * fix * fix e2e not ending properly * exp: add hanging-process reporter for investigation * Revert "exp: add hanging-process reporter for investigation" This reverts commit26851f8282. * update changelog
159 lines
4.7 KiB
TypeScript
159 lines
4.7 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { afterAll, afterEach, beforeEach, describe, expect, test } from 'vitest';
|
|
import { FlashService } from '@/core/FlashService.js';
|
|
import { IdService } from '@/core/IdService.js';
|
|
import { FlashLikesRepository, FlashsRepository, MiFlash, MiUser, UserProfilesRepository, UsersRepository } from '@/models/_.js';
|
|
import { DI } from '@/di-symbols.js';
|
|
import { GlobalModule } from '@/GlobalModule.js';
|
|
import { CoreModule } from '@/core/CoreModule.js';
|
|
|
|
describe('FlashService', () => {
|
|
let app: TestingModule;
|
|
let service: FlashService;
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
let flashsRepository: FlashsRepository;
|
|
let flashLikesRepository: FlashLikesRepository;
|
|
let usersRepository: UsersRepository;
|
|
let userProfilesRepository: UserProfilesRepository;
|
|
let idService: IdService;
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
let root: MiUser;
|
|
let alice: MiUser;
|
|
let bob: MiUser;
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
async function createFlash(data: Partial<MiFlash>) {
|
|
return flashsRepository.insert({
|
|
id: idService.gen(),
|
|
updatedAt: new Date(),
|
|
userId: root.id,
|
|
title: 'title',
|
|
summary: 'summary',
|
|
script: 'script',
|
|
permissions: [],
|
|
likedCount: 0,
|
|
...data,
|
|
}).then(x => flashsRepository.findOneByOrFail(x.identifiers[0]));
|
|
}
|
|
|
|
async function createUser(data: Partial<MiUser> = {}) {
|
|
const user = await usersRepository
|
|
.insert({
|
|
id: idService.gen(),
|
|
...data,
|
|
})
|
|
.then(x => usersRepository.findOneByOrFail(x.identifiers[0]));
|
|
|
|
await userProfilesRepository.insert({
|
|
userId: user.id,
|
|
});
|
|
|
|
return user;
|
|
}
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
beforeEach(async () => {
|
|
app = await Test.createTestingModule({
|
|
imports: [
|
|
GlobalModule,
|
|
CoreModule,
|
|
],
|
|
providers: [
|
|
FlashService,
|
|
IdService,
|
|
],
|
|
}).compile();
|
|
|
|
service = app.get(FlashService);
|
|
|
|
flashsRepository = app.get(DI.flashsRepository);
|
|
flashLikesRepository = app.get(DI.flashLikesRepository);
|
|
usersRepository = app.get(DI.usersRepository);
|
|
userProfilesRepository = app.get(DI.userProfilesRepository);
|
|
idService = app.get(IdService);
|
|
|
|
root = await createUser({ username: 'root', usernameLower: 'root' });
|
|
alice = await createUser({ username: 'alice', usernameLower: 'alice' });
|
|
bob = await createUser({ username: 'bob', usernameLower: 'bob' });
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await usersRepository.createQueryBuilder().delete().execute();
|
|
await userProfilesRepository.createQueryBuilder().delete().execute();
|
|
await flashsRepository.createQueryBuilder().delete().execute();
|
|
await flashLikesRepository.createQueryBuilder().delete().execute();
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await app.close();
|
|
});
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
describe('featured', () => {
|
|
test('should return featured flashes', async () => {
|
|
const flash1 = await createFlash({ likedCount: 1 });
|
|
const flash2 = await createFlash({ likedCount: 2 });
|
|
const flash3 = await createFlash({ likedCount: 3 });
|
|
|
|
const result = await service.featured({
|
|
offset: 0,
|
|
limit: 10,
|
|
});
|
|
|
|
expect(result).toEqual([flash3, flash2, flash1]);
|
|
});
|
|
|
|
test('should return featured flashes public visibility only', async () => {
|
|
const flash1 = await createFlash({ likedCount: 1, visibility: 'public' });
|
|
const flash2 = await createFlash({ likedCount: 2, visibility: 'public' });
|
|
const flash3 = await createFlash({ likedCount: 3, visibility: 'private' });
|
|
|
|
const result = await service.featured({
|
|
offset: 0,
|
|
limit: 10,
|
|
});
|
|
|
|
expect(result).toEqual([flash2, flash1]);
|
|
});
|
|
|
|
test('should return featured flashes with offset', async () => {
|
|
const flash1 = await createFlash({ likedCount: 1 });
|
|
const flash2 = await createFlash({ likedCount: 2 });
|
|
const flash3 = await createFlash({ likedCount: 3 });
|
|
|
|
const result = await service.featured({
|
|
offset: 1,
|
|
limit: 10,
|
|
});
|
|
|
|
expect(result).toEqual([flash2, flash1]);
|
|
});
|
|
|
|
test('should return featured flashes with limit', async () => {
|
|
const flash1 = await createFlash({ likedCount: 1 });
|
|
const flash2 = await createFlash({ likedCount: 2 });
|
|
const flash3 = await createFlash({ likedCount: 3 });
|
|
|
|
const result = await service.featured({
|
|
offset: 0,
|
|
limit: 2,
|
|
});
|
|
|
|
expect(result).toEqual([flash3, flash2]);
|
|
});
|
|
});
|
|
});
|