2018-10-15 14:37:21 -07:00
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
2019-04-07 05:50:36 -07:00
|
|
|
import * as assert from 'assert';
|
|
|
|
import * as childProcess from 'child_process';
|
2022-02-26 18:07:39 -08:00
|
|
|
import { async, signup, request, post, react, uploadFile, startServer, shutdownServer } from './utils.js';
|
2018-10-15 14:37:21 -07:00
|
|
|
|
|
|
|
describe('API', () => {
|
2019-04-07 05:50:36 -07:00
|
|
|
let p: childProcess.ChildProcess;
|
2022-02-18 21:05:32 -08:00
|
|
|
let alice: any;
|
|
|
|
let bob: any;
|
|
|
|
let carol: any;
|
2019-04-07 05:50:36 -07:00
|
|
|
|
2022-02-18 21:05:32 -08:00
|
|
|
before(async () => {
|
|
|
|
p = await startServer();
|
|
|
|
alice = await signup({ username: 'alice' });
|
|
|
|
bob = await signup({ username: 'bob' });
|
|
|
|
carol = await signup({ username: 'carol' });
|
2019-04-07 05:50:36 -07:00
|
|
|
});
|
2018-10-15 14:37:21 -07:00
|
|
|
|
2022-02-18 21:05:32 -08:00
|
|
|
after(async () => {
|
|
|
|
await shutdownServer(p);
|
2019-01-22 20:35:22 -08:00
|
|
|
});
|
|
|
|
|
2022-02-18 21:05:32 -08:00
|
|
|
describe('General validation', () => {
|
|
|
|
it('wrong type', async(async () => {
|
|
|
|
const res = await request('/test', {
|
|
|
|
required: true,
|
|
|
|
string: 42,
|
2018-10-15 14:37:21 -07:00
|
|
|
});
|
2019-04-07 05:50:36 -07:00
|
|
|
assert.strictEqual(res.status, 400);
|
2018-10-15 14:37:21 -07:00
|
|
|
}));
|
|
|
|
|
2022-02-18 21:05:32 -08:00
|
|
|
it('missing require param', async(async () => {
|
|
|
|
const res = await request('/test', {
|
|
|
|
string: 'a',
|
2018-10-15 14:37:21 -07:00
|
|
|
});
|
2019-04-07 05:50:36 -07:00
|
|
|
assert.strictEqual(res.status, 400);
|
2018-10-15 14:37:21 -07:00
|
|
|
}));
|
|
|
|
|
2022-02-18 21:05:32 -08:00
|
|
|
it('invalid misskey:id (empty string)', async(async () => {
|
|
|
|
const res = await request('/test', {
|
|
|
|
required: true,
|
|
|
|
id: '',
|
2018-10-15 14:37:21 -07:00
|
|
|
});
|
2019-04-07 05:50:36 -07:00
|
|
|
assert.strictEqual(res.status, 400);
|
2018-10-15 14:37:21 -07:00
|
|
|
}));
|
|
|
|
|
2022-02-18 21:05:32 -08:00
|
|
|
it('valid misskey:id', async(async () => {
|
|
|
|
const res = await request('/test', {
|
|
|
|
required: true,
|
|
|
|
id: '8wvhjghbxu',
|
2018-10-15 14:37:21 -07:00
|
|
|
});
|
2019-04-07 05:50:36 -07:00
|
|
|
assert.strictEqual(res.status, 200);
|
2018-10-15 16:54:36 -07:00
|
|
|
}));
|
|
|
|
|
2022-02-18 21:05:32 -08:00
|
|
|
it('default value', async(async () => {
|
|
|
|
const res = await request('/test', {
|
|
|
|
required: true,
|
|
|
|
string: 'a',
|
2018-10-15 17:45:36 -07:00
|
|
|
});
|
2019-04-07 05:50:36 -07:00
|
|
|
assert.strictEqual(res.status, 200);
|
2022-02-18 21:05:32 -08:00
|
|
|
assert.strictEqual(res.body.default, 'hello');
|
2018-10-15 17:45:36 -07:00
|
|
|
}));
|
|
|
|
|
2022-02-18 21:05:32 -08:00
|
|
|
it('can set null even if it has default value', async(async () => {
|
|
|
|
const res = await request('/test', {
|
|
|
|
required: true,
|
|
|
|
nullableDefault: null,
|
2018-10-15 17:45:36 -07:00
|
|
|
});
|
2019-04-07 05:50:36 -07:00
|
|
|
assert.strictEqual(res.status, 200);
|
2022-02-18 21:05:32 -08:00
|
|
|
assert.strictEqual(res.body.nullableDefault, null);
|
2018-10-15 18:18:47 -07:00
|
|
|
}));
|
|
|
|
|
2022-02-18 21:05:32 -08:00
|
|
|
it('cannot set undefined if it has default value', async(async () => {
|
|
|
|
const res = await request('/test', {
|
|
|
|
required: true,
|
|
|
|
nullableDefault: undefined,
|
2018-10-15 18:18:47 -07:00
|
|
|
});
|
2019-04-07 05:50:36 -07:00
|
|
|
assert.strictEqual(res.status, 200);
|
2022-02-18 21:05:32 -08:00
|
|
|
assert.strictEqual(res.body.nullableDefault, 'hello');
|
2019-01-24 17:58:39 -08:00
|
|
|
}));
|
|
|
|
});
|
2018-10-15 14:37:21 -07:00
|
|
|
});
|