Skip to content

Commit

Permalink
fix(client): connect should return the client
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Reed committed Feb 10, 2020
1 parent 5ae3cfc commit 1e1846f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions test/Client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -24,15 +25,15 @@ 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 => {
expect(result).toBeDefined();
expect(result).toEqual(true);
});
});
it('#checkServer=invalid', () => {
it('#checkServer=invalid', async () => {
auth.password = 'invalid';
const ret = Client.checkServer(server, mockHTTP);
expect(ret).toBeDefined();
Expand All @@ -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);
});
});
});
Expand Down

0 comments on commit 1e1846f

Please sign in to comment.