test(backend): Add tests for clips (#10358)
This commit is contained in:
parent
37b8f40151
commit
2e051c5871
2 changed files with 1009 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
|||
import * as assert from 'assert';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { isAbsolute, basename } from 'node:path';
|
||||
import { inspect } from 'node:util';
|
||||
import WebSocket from 'ws';
|
||||
import fetch, { Blob, File, RequestInit } from 'node-fetch';
|
||||
import { DataSource } from 'typeorm';
|
||||
|
@ -22,6 +24,36 @@ export const api = async (endpoint: string, params: any, me?: any) => {
|
|||
return await request(`api/${normalized}`, params, me);
|
||||
};
|
||||
|
||||
export type ApiRequest = {
|
||||
endpoint: string,
|
||||
parameters: object,
|
||||
user: object | undefined,
|
||||
};
|
||||
|
||||
export const successfulApiCall = async <T, >(request: ApiRequest, assertion: {
|
||||
status: number,
|
||||
} = { status: 200 }): Promise<T> => {
|
||||
const { endpoint, parameters, user } = request;
|
||||
const { status } = assertion;
|
||||
const res = await api(endpoint, parameters, user);
|
||||
assert.strictEqual(res.status, status, inspect(res.body));
|
||||
return res.body;
|
||||
};
|
||||
|
||||
export const failedApiCall = async <T, >(request: ApiRequest, assertion: {
|
||||
status: number,
|
||||
code: string,
|
||||
id: string
|
||||
}): Promise<T> => {
|
||||
const { endpoint, parameters, user } = request;
|
||||
const { status, code, id } = assertion;
|
||||
const res = await api(endpoint, parameters, user);
|
||||
assert.strictEqual(res.status, status, inspect(res.body));
|
||||
assert.strictEqual(res.body.error.code, code, inspect(res.body));
|
||||
assert.strictEqual(res.body.error.id, id, inspect(res.body));
|
||||
return res.body;
|
||||
};
|
||||
|
||||
const request = async (path: string, params: any, me?: any): Promise<{ body: any, status: number }> => {
|
||||
const auth = me ? {
|
||||
i: me.token,
|
||||
|
@ -69,6 +101,21 @@ export const post = async (user: any, params?: misskey.Endpoints['notes/create']
|
|||
return res.body ? res.body.createdNote : null;
|
||||
};
|
||||
|
||||
// 非公開ノートをAPI越しに見たときのノート NoteEntityService.ts
|
||||
export const hiddenNote = (note: any): any => {
|
||||
const temp = {
|
||||
...note,
|
||||
fileIds: [],
|
||||
files: [],
|
||||
text: null,
|
||||
cw: null,
|
||||
isHidden: true,
|
||||
};
|
||||
delete temp.visibleUserIds;
|
||||
delete temp.poll;
|
||||
return temp;
|
||||
};
|
||||
|
||||
export const react = async (user: any, note: any, reaction: string): Promise<any> => {
|
||||
await api('notes/reactions/create', {
|
||||
noteId: note.id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue