diff options
Diffstat (limited to 'test/api.ts')
| -rw-r--r-- | test/api.ts | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/api.ts b/test/api.ts index 3380f3b630..8b27c54ed1 100644 --- a/test/api.ts +++ b/test/api.ts @@ -51,6 +51,42 @@ describe('API', () => { }); }); + test('インスタンスの credential が指定されていても引数で credential が null ならば null としてリクエストされる', async () => { + fetchMock.resetMocks(); + fetchMock.mockResponse(async (req) => { + const body = await req.json(); + if (req.method == 'POST' && req.url == 'https://misskey.test/api/i') { + if (typeof body.i === 'string') { + return JSON.stringify({ id: 'foo' }); + } else { + return { + status: 401, + body: JSON.stringify({ + error: { + message: 'Credential required.', + code: 'CREDENTIAL_REQUIRED', + id: '1384574d-a912-4b81-8601-c7b1c4085df1', + } + }) + }; + } + } else { + return { status: 404 }; + } + }); + + try { + const cli = new APIClient({ + origin: 'https://misskey.test', + credential: 'TOKEN', + }); + + await cli.request('i', {}, null); + } catch (e) { + expect(isAPIError(e)).toEqual(true); + } + }); + test('api error', async () => { fetchMock.resetMocks(); fetchMock.mockResponse(async (req) => { |