diff --git a/src/Client.ts b/src/Client.ts index 88c49a89..ed54cd88 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -109,7 +109,11 @@ export class Client implements IHasHTTP { } try { - return await this.user().login(); + return await this.user() + .login() + .then(() => { + return this; + }); } catch (err) { if (err.code === 401) { throw new TwitarrError('username or password was invalid', err.code, err.options, err.errors, err.data); diff --git a/test/Client.spec.ts b/test/Client.spec.ts index 9801ca0d..9efb77ed 100644 --- a/test/Client.spec.ts +++ b/test/Client.spec.ts @@ -5,13 +5,14 @@ import { TwitarrAuthConfig } from '../src/api/TwitarrAuthConfig'; import { TwitarrServer } from '../src/api/TwitarrServer'; import { MockHTTP } from './rest/MockHTTP'; +import { ITwitarrHTTP } from '../src/api/ITwitarrHTTP'; const SERVER_NAME = 'Demo'; const SERVER_URL = 'http://demo.twitarr.com/'; const SERVER_USER = 'demo'; const SERVER_PASSWORD = 'demo'; -let twitarr: Client, server, auth, mockHTTP; +let twitarr: Client, server: TwitarrServer, auth: TwitarrAuthConfig, mockHTTP: ITwitarrHTTP; describe('Client', () => { beforeEach(() => { @@ -24,7 +25,7 @@ describe('Client', () => { it('* server = undefined', () => { expect(twitarr.server).toBeUndefined(); }); - it('#checkServer', () => { + it('#checkServer', async () => { const ret = Client.checkServer(server, mockHTTP); expect(ret).toBeDefined(); return ret.then(result => { @@ -32,7 +33,7 @@ describe('Client', () => { expect(result).toEqual(true); }); }); - it('#checkServer=invalid', () => { + it('#checkServer=invalid', async () => { auth.password = 'invalid'; const ret = Client.checkServer(server, mockHTTP); expect(ret).toBeDefined(); @@ -41,12 +42,12 @@ describe('Client', () => { expect(result).toEqual(true); }); }); - it('#connect', () => { + it('#connect', async () => { const ret = twitarr.connect(SERVER_NAME, SERVER_URL, SERVER_USER, SERVER_PASSWORD); expect(ret).toBeDefined(); return ret.then(result => { expect(result).toBeDefined(); - expect(result).toEqual('demo:12345'); + expect(result).toBeInstanceOf(Client); }); }); });