test(backend): Add tests for users (#10546)
Co-authored-by: tamaina <tamaina@hotmail.co.jp>
This commit is contained in:
parent
49749b46c4
commit
5c3a4a8224
2 changed files with 903 additions and 4 deletions
|
@ -6,6 +6,7 @@ import WebSocket from 'ws';
|
|||
import fetch, { Blob, File, RequestInit } from 'node-fetch';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { JSDOM } from 'jsdom';
|
||||
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';
|
||||
|
@ -31,12 +32,12 @@ export type ApiRequest = {
|
|||
};
|
||||
|
||||
export const successfulApiCall = async <T, >(request: ApiRequest, assertion: {
|
||||
status: number,
|
||||
} = { status: 200 }): Promise<T> => {
|
||||
status?: number,
|
||||
} = {}): 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));
|
||||
const status = assertion.status ?? (res.body == null ? 204 : 200);
|
||||
assert.strictEqual(res.status, status, inspect(res.body, { depth: 5, colors: true }));
|
||||
return res.body;
|
||||
};
|
||||
|
||||
|
@ -188,6 +189,36 @@ export const channel = async (user: any, channel: any = {}): Promise<any> => {
|
|||
return res.body;
|
||||
};
|
||||
|
||||
export const role = async (user: any, role: any = {}, policies: any = {}): Promise<any> => {
|
||||
const res = await api('admin/roles/create', {
|
||||
asBadge: false,
|
||||
canEditMembersByModerator: false,
|
||||
color: null,
|
||||
condFormula: {
|
||||
id: 'ebef1684-672d-49b6-ad82-1b3ec3784f85',
|
||||
type: 'isRemote',
|
||||
},
|
||||
description: '',
|
||||
displayOrder: 0,
|
||||
iconUrl: null,
|
||||
isAdministrator: false,
|
||||
isModerator: false,
|
||||
isPublic: false,
|
||||
name: 'New Role',
|
||||
target: 'manual',
|
||||
policies: {
|
||||
...Object.entries(DEFAULT_POLICIES).map(([k, v]) => [k, {
|
||||
priority: 0,
|
||||
useDefault: true,
|
||||
value: v,
|
||||
}]),
|
||||
...policies,
|
||||
},
|
||||
...role,
|
||||
}, user);
|
||||
return res.body;
|
||||
};
|
||||
|
||||
interface UploadOptions {
|
||||
/** Optional, absolute path or relative from ./resources/ */
|
||||
path?: string | URL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue