Skip to content

Commit

Permalink
fix: add options handling, test
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-koval committed Jan 17, 2018
1 parent 16b6338 commit bec8cf4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules/
/coverage/
/.envrc
.DS_Store
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Promise = require('bluebird');
const request = Promise.promisify(require('request'));

const { UnexpectedStatusCodeError } = require('./error');
const TrembitaError = require('./error');

const Trembita = class Trembita {
constructor(options) {
Expand All @@ -10,7 +10,7 @@ const Trembita = class Trembita {
return this.client(options)
.then(res => {
if (!expectedCodes.includes(res.statusCode)) {
const error = new UnexpectedStatusCodeError({
const error = new TrembitaError.UnexpectedStatusCodeError({
options,
httpStatusCode: res.statusCode,
httpBody: res.body
Expand All @@ -27,9 +27,9 @@ const Trembita = class Trembita {
this.log.trace({ options }, 'request')
return this.raw(options)
};
if (!options.endpoint) {
throw new Error('no endpoint');
}

if (!options) { throw new TrembitaError('missing options'); }
if (!options.endpoint) { throw new TrembitaError('missing endpoint'); }

this.endpoint = options.endpoint;
this.log = options.log || console;
Expand Down
8 changes: 8 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ describe('Trembita:', () => {
expect(tbita).to.have.property('client');
});

it('should fail if options are not provided', () => {
expect(() => new Trembita()).to.throw('missing options')
})

it('should fail if endpoint is not provided', () => {
expect(() => new Trembita({})).to.throw('missing endpoint')
})

it('should return status code 200 and resourse', () => {
scope
.get('/users?page=2')
Expand Down

0 comments on commit bec8cf4

Please sign in to comment.