Workspaces refactor #86

Merged
norm merged 189 commits from refactor/workspaces into main 2022-08-28 14:46:45 +00:00
Showing only changes of commit 154e0fe94a - Show all commits

View file

@ -38,12 +38,10 @@ describe('API', () => {
const res = await cli.request('i'); const res = await cli.request('i');
// validate response
expect(res).toEqual({ expect(res).toEqual({
id: 'foo' id: 'foo'
}); });
// validate fetch call
expect(getFetchCall(fetchMock.mock.calls[0])).toEqual({ expect(getFetchCall(fetchMock.mock.calls[0])).toEqual({
url: 'https://misskey.test/api/i', url: 'https://misskey.test/api/i',
method: 'POST', method: 'POST',
@ -51,6 +49,65 @@ describe('API', () => {
}); });
}); });
test('with params', async () => {
fetchMock.resetMocks();
fetchMock.mockResponse(async (req) => {
const body = await req.json();
if (req.method == 'POST' && req.url == 'https://misskey.test/api/notes/show') {
if (body.i === 'TOKEN' && body.noteId === 'aaaaa') {
return JSON.stringify({ id: 'foo' });
} else {
return { status: 400 };
}
} else {
return { status: 404 };
}
});
const cli = new APIClient({
origin: 'https://misskey.test',
credential: 'TOKEN',
});
const res = await cli.request('notes/show', { noteId: 'aaaaa' });
expect(res).toEqual({
id: 'foo'
});
expect(getFetchCall(fetchMock.mock.calls[0])).toEqual({
url: 'https://misskey.test/api/notes/show',
method: 'POST',
body: { i: 'TOKEN', noteId: 'aaaaa' }
});
});
test('204 No Content で null が返る', async () => {
fetchMock.resetMocks();
fetchMock.mockResponse(async (req) => {
if (req.method == 'POST' && req.url == 'https://misskey.test/api/reset-password') {
return { status: 204 };
} else {
return { status: 404 };
}
});
const cli = new APIClient({
origin: 'https://misskey.test',
credential: 'TOKEN',
});
const res = await cli.request('reset-password', { token: 'aaa', password: 'aaa' });
expect(res).toEqual(null);
expect(getFetchCall(fetchMock.mock.calls[0])).toEqual({
url: 'https://misskey.test/api/reset-password',
method: 'POST',
body: { i: 'TOKEN', token: 'aaa', password: 'aaa' }
});
});
test('インスタンスの credential が指定されていても引数で credential が null ならば null としてリクエストされる', async () => { test('インスタンスの credential が指定されていても引数で credential が null ならば null としてリクエストされる', async () => {
fetchMock.resetMocks(); fetchMock.resetMocks();
fetchMock.mockResponse(async (req) => { fetchMock.mockResponse(async (req) => {