2018-10-15 21:37:21 +00:00
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
import * as assert from 'assert';
|
2023-03-03 02:13:12 +00:00
|
|
|
import { signup, api, startServer } from '../utils.js';
|
|
|
|
import type { INestApplicationContext } from '@nestjs/common';
|
2018-10-15 21:37:21 +00:00
|
|
|
|
|
|
|
describe('API', () => {
|
2023-03-03 02:13:12 +00:00
|
|
|
let p: INestApplicationContext;
|
2022-02-19 05:05:32 +00:00
|
|
|
let alice: any;
|
|
|
|
let bob: any;
|
|
|
|
let carol: any;
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
beforeAll(async () => {
|
2022-02-19 05:05:32 +00:00
|
|
|
p = await startServer();
|
|
|
|
alice = await signup({ username: 'alice' });
|
|
|
|
bob = await signup({ username: 'bob' });
|
|
|
|
carol = await signup({ username: 'carol' });
|
2023-03-03 02:13:12 +00:00
|
|
|
}, 1000 * 60 * 2);
|
2018-10-15 21:37:21 +00:00
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
afterAll(async () => {
|
2023-03-03 02:13:12 +00:00
|
|
|
await p.close();
|
2019-01-23 04:35:22 +00:00
|
|
|
});
|
|
|
|
|
2022-02-19 05:05:32 +00:00
|
|
|
describe('General validation', () => {
|
2023-03-03 02:13:12 +00:00
|
|
|
test('wrong type', async () => {
|
|
|
|
const res = await api('/test', {
|
2022-02-19 05:05:32 +00:00
|
|
|
required: true,
|
|
|
|
string: 42,
|
2018-10-15 21:37:21 +00:00
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 02:13:12 +00:00
|
|
|
});
|
2018-10-15 21:37:21 +00:00
|
|
|
|
2023-03-03 02:13:12 +00:00
|
|
|
test('missing require param', async () => {
|
|
|
|
const res = await api('/test', {
|
2022-02-19 05:05:32 +00:00
|
|
|
string: 'a',
|
2018-10-15 21:37:21 +00:00
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 02:13:12 +00:00
|
|
|
});
|
2018-10-15 21:37:21 +00:00
|
|
|
|
2023-03-03 02:13:12 +00:00
|
|
|
test('invalid misskey:id (empty string)', async () => {
|
|
|
|
const res = await api('/test', {
|
2022-02-19 05:05:32 +00:00
|
|
|
required: true,
|
|
|
|
id: '',
|
2018-10-15 21:37:21 +00:00
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 02:13:12 +00:00
|
|
|
});
|
2018-10-15 21:37:21 +00:00
|
|
|
|
2023-03-03 02:13:12 +00:00
|
|
|
test('valid misskey:id', async () => {
|
|
|
|
const res = await api('/test', {
|
2022-02-19 05:05:32 +00:00
|
|
|
required: true,
|
|
|
|
id: '8wvhjghbxu',
|
2018-10-15 21:37:21 +00:00
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.status, 200);
|
2023-03-03 02:13:12 +00:00
|
|
|
});
|
2018-10-15 23:54:36 +00:00
|
|
|
|
2023-03-03 02:13:12 +00:00
|
|
|
test('default value', async () => {
|
|
|
|
const res = await api('/test', {
|
2022-02-19 05:05:32 +00:00
|
|
|
required: true,
|
|
|
|
string: 'a',
|
2018-10-16 00:45:36 +00:00
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.status, 200);
|
2022-02-19 05:05:32 +00:00
|
|
|
assert.strictEqual(res.body.default, 'hello');
|
2023-03-03 02:13:12 +00:00
|
|
|
});
|
2018-10-16 00:45:36 +00:00
|
|
|
|
2023-03-03 02:13:12 +00:00
|
|
|
test('can set null even if it has default value', async () => {
|
|
|
|
const res = await api('/test', {
|
2022-02-19 05:05:32 +00:00
|
|
|
required: true,
|
|
|
|
nullableDefault: null,
|
2018-10-16 00:45:36 +00:00
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.status, 200);
|
2022-02-19 05:05:32 +00:00
|
|
|
assert.strictEqual(res.body.nullableDefault, null);
|
2023-03-03 02:13:12 +00:00
|
|
|
});
|
2018-10-16 01:18:47 +00:00
|
|
|
|
2023-03-03 02:13:12 +00:00
|
|
|
test('cannot set undefined if it has default value', async () => {
|
|
|
|
const res = await api('/test', {
|
2022-02-19 05:05:32 +00:00
|
|
|
required: true,
|
|
|
|
nullableDefault: undefined,
|
2018-10-16 01:18:47 +00:00
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.status, 200);
|
2022-02-19 05:05:32 +00:00
|
|
|
assert.strictEqual(res.body.nullableDefault, 'hello');
|
2023-03-03 02:13:12 +00:00
|
|
|
});
|
2019-01-25 01:58:39 +00:00
|
|
|
});
|
2018-10-15 21:37:21 +00:00
|
|
|
});
|