wip
This commit is contained in:
@@ -3,7 +3,6 @@ process.env.NODE_ENV = 'test';
|
||||
import * as assert from 'assert';
|
||||
import { inspect } from 'node:util';
|
||||
import { DEFAULT_POLICIES } from '@/core/RoleService.js';
|
||||
import type { Packed } from '@/misc/json-schema.js';
|
||||
import {
|
||||
signup,
|
||||
post,
|
||||
@@ -19,6 +18,7 @@ import {
|
||||
} from '../utils.js';
|
||||
import type * as misskey from 'misskey-js';
|
||||
import type { INestApplicationContext } from '@nestjs/common';
|
||||
import { WeakSerialized } from 'schema-type';
|
||||
|
||||
const compareBy = <T extends { id: string }>(selector: (s: T) => string = (s: T): string => s.id) => (a: T, b: T): number => {
|
||||
return selector(a).localeCompare(selector(b));
|
||||
@@ -28,12 +28,9 @@ describe('アンテナ', () => {
|
||||
// エンティティとしてのアンテナを主眼においたテストを記述する
|
||||
// (Antennaを返すエンドポイント、Antennaエンティティを書き換えるエンドポイント、Antennaからノートを取得するエンドポイントをテストする)
|
||||
|
||||
// BUG misskey-jsとjson-schemaが一致していない。
|
||||
// - srcのenumにgroupが残っている
|
||||
// - userGroupIdが残っている, isActiveがない
|
||||
type Antenna = misskey.entities.Antenna | Packed<'Antenna'>;
|
||||
type User = misskey.entities.MeDetailed & { token: string };
|
||||
type Note = misskey.entities.Note;
|
||||
type Antenna = WeakSerialized<misskey.entities.Antenna>;
|
||||
type User = WeakSerialized<misskey.entities.MeDetailed & { token: string }>;
|
||||
type Note = WeakSerialized<misskey.entities.Note>;
|
||||
|
||||
// アンテナを作成できる最小のパラメタ
|
||||
const defaultParam = {
|
||||
|
@@ -10,6 +10,7 @@ import { DEFAULT_POLICIES } from '@/core/RoleService.js';
|
||||
import { entities } from '../src/postgres.js';
|
||||
import { loadConfig } from '../src/config.js';
|
||||
import type * as misskey from 'misskey-js';
|
||||
import { SchemaOrUndefined } from 'misskey-js/built/endpoints.types.js';
|
||||
|
||||
export { server as startServer } from '@/boot/common.js';
|
||||
|
||||
@@ -25,15 +26,18 @@ export const api = async (endpoint: string, params: any, me?: any) => {
|
||||
return await request(`api/${normalized}`, params, me);
|
||||
};
|
||||
|
||||
export type ApiRequest = {
|
||||
endpoint: string,
|
||||
parameters: object,
|
||||
export type ApiRequest<X extends keyof misskey.Endpoints = keyof misskey.Endpoints, D extends misskey.Endpoints[X]['defines'][number] = misskey.Endpoints[X]['defines'][number], P extends D['req'] = D['req']> = {
|
||||
endpoint: X,
|
||||
parameters: SchemaOrUndefined<P>,
|
||||
user: object | undefined,
|
||||
};
|
||||
|
||||
export const successfulApiCall = async <T, >(request: ApiRequest, assertion: {
|
||||
status?: number,
|
||||
} = {}): Promise<T> => {
|
||||
export const successfulApiCall = async <X extends keyof misskey.Endpoints, D extends misskey.Endpoints[X]['defines'][number] = misskey.Endpoints[X]['defines'][number]>(
|
||||
request: ApiRequest<X, D>,
|
||||
assertion: {
|
||||
status?: number,
|
||||
} = {}
|
||||
): Promise<SchemaOrUndefined<D['res']>> => {
|
||||
const { endpoint, parameters, user } = request;
|
||||
const res = await api(endpoint, parameters, user);
|
||||
const status = assertion.status ?? (res.body == null ? 204 : 200);
|
||||
@@ -41,11 +45,11 @@ export const successfulApiCall = async <T, >(request: ApiRequest, assertion: {
|
||||
return res.body;
|
||||
};
|
||||
|
||||
export const failedApiCall = async <T, >(request: ApiRequest, assertion: {
|
||||
export const failedApiCall = async <X extends keyof misskey.Endpoints>(request: ApiRequest<X>, assertion: {
|
||||
status: number,
|
||||
code: string,
|
||||
id: string
|
||||
}): Promise<T> => {
|
||||
}): Promise<misskey.Packed<'Error#/$defs/Error'>> => {
|
||||
const { endpoint, parameters, user } = request;
|
||||
const { status, code, id } = assertion;
|
||||
const res = await api(endpoint, parameters, user);
|
||||
|
Reference in New Issue
Block a user