mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-06-25 17:10:43 +00:00
attempt to fix drive/files/create test
This commit is contained in:
parent
7c6e969249
commit
4715153375
5 changed files with 47 additions and 11 deletions
|
|
@ -6,13 +6,12 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { CoreModule } from '@/core/CoreModule.js';
|
||||
import * as endpointsObject from './endpoint-list.js';
|
||||
import { endpointEntries } from './endpoint-entries.js';
|
||||
import { GetterService } from './GetterService.js';
|
||||
import { ApiLoggerService } from './ApiLoggerService.js';
|
||||
import type { Provider } from '@nestjs/common';
|
||||
|
||||
const endpoints = Object.entries(endpointsObject);
|
||||
const endpointProviders = endpoints.map(([path, endpoint]): Provider => ({ provide: `ep:${path}`, useClass: endpoint.default }));
|
||||
const endpointProviders = endpointEntries.map(([path, endpoint]): Provider => ({ provide: `ep:${path}`, useClass: endpoint.default }));
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
|
|
|||
25
packages/backend/src/server/api/endpoint-entries.ts
Normal file
25
packages/backend/src/server/api/endpoint-entries.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import * as endpointsObject from './endpoint-list.js';
|
||||
|
||||
type EndpointModule = {
|
||||
default: object;
|
||||
meta?: unknown;
|
||||
paramDef?: unknown;
|
||||
};
|
||||
|
||||
function isEndpointModule(endpoint: unknown): endpoint is EndpointModule {
|
||||
return endpoint != null
|
||||
&& typeof endpoint === 'object'
|
||||
&& 'default' in endpoint
|
||||
&& endpoint.default != null;
|
||||
}
|
||||
|
||||
// Vitest can expose unresolved namespace re-exports from endpoint-list as undefined
|
||||
// while loading the full endpoint graph. Keep a single normalized view here.
|
||||
export const endpointEntries = Object.entries(endpointsObject).flatMap(([path, endpoint]) => {
|
||||
return isEndpointModule(endpoint) ? [[path, endpoint] as const] : [];
|
||||
});
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
import { permissions } from 'misskey-js';
|
||||
import type { KeyOf, Schema } from '@/misc/json-schema.js';
|
||||
|
||||
import * as endpointsObject from './endpoint-list.js';
|
||||
import { endpointEntries } from './endpoint-entries.js';
|
||||
|
||||
interface IEndpointMetaBase {
|
||||
readonly stability?: 'deprecated' | 'experimental' | 'stable';
|
||||
|
|
@ -130,7 +130,7 @@ export interface IEndpoint {
|
|||
params: Schema;
|
||||
}
|
||||
|
||||
const endpoints: IEndpoint[] = Object.entries(endpointsObject).map(([name, ep]) => {
|
||||
const endpoints: IEndpoint[] = endpointEntries.map(([name, ep]) => {
|
||||
return {
|
||||
name: name,
|
||||
get meta() {
|
||||
|
|
|
|||
|
|
@ -21,8 +21,10 @@ import { IdService } from '@/core/IdService.js';
|
|||
// TODO: uploadableFileTypes で許可されていないファイルが弾かれるかのテスト
|
||||
|
||||
describe('/drive/files/create', () => {
|
||||
let module: TestingModule;
|
||||
let server: FastifyInstance;
|
||||
const HOOK_TIMEOUT = 60000;
|
||||
|
||||
let module: TestingModule | undefined;
|
||||
let server: FastifyInstance | undefined;
|
||||
let roleService: RoleService;
|
||||
let idService: IdService;
|
||||
|
||||
|
|
@ -106,7 +108,7 @@ describe('/drive/files/create', () => {
|
|||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
}, HOOK_TIMEOUT);
|
||||
|
||||
beforeEach(async () => {
|
||||
await roleService.unassign(root.id, role_tinyAttachment.id).catch(() => {
|
||||
|
|
@ -118,9 +120,14 @@ describe('/drive/files/create', () => {
|
|||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await server.close();
|
||||
await module.close();
|
||||
});
|
||||
if (server != null) {
|
||||
await server.close();
|
||||
}
|
||||
|
||||
if (module != null) {
|
||||
await module.close();
|
||||
}
|
||||
}, HOOK_TIMEOUT);
|
||||
|
||||
async function postFile(props: {
|
||||
name: string,
|
||||
|
|
@ -131,6 +138,10 @@ describe('/drive/files/create', () => {
|
|||
}) {
|
||||
const { name, comment, isSensitive, force, fileContent } = props;
|
||||
|
||||
if (server == null) {
|
||||
throw new Error('Server is not initialized');
|
||||
}
|
||||
|
||||
return await request(server.server)
|
||||
.post('/api/drive/files/create')
|
||||
.set('Content-Type', 'multipart/form-data')
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { defineConfig } from 'vitest/config';
|
|||
export const baseConfig = defineConfig({
|
||||
test: {
|
||||
exclude: ['node_modules', 'dist'],
|
||||
hookTimeout: 60000,
|
||||
coverage: {
|
||||
provider: 'v8',
|
||||
reportsDirectory: 'coverage',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue