Commit b1786f7e authored by Aaron Tidwell's avatar Aaron Tidwell

fix exception thrown if client created without a option object. Add deps for...

fix exception thrown if client created without a option object.  Add deps for tests.  Add tests for challonge.js.  Hook up to travis for running tests.  Add test instructions to readme.  Update gitignore and test configs
parent 404039e0
key.js key.js
\ No newline at end of file coverage
node_modules
language: node_js
node_js:
- "6.0.0"
...@@ -11,7 +11,7 @@ var errorHandler = require('./error-handler'); ...@@ -11,7 +11,7 @@ var errorHandler = require('./error-handler');
for communicating with Challonge API for communicating with Challonge API
*/ */
var Client = exports.Client = function(options) { var Client = exports.Client = function(options) {
this.options = options; this.options = options || {};
//defaults - todo convert to an object merge //defaults - todo convert to an object merge
if (!this.options.version) { if (!this.options.version) {
this.options.version = 1; this.options.version = 1;
...@@ -164,4 +164,4 @@ Client.prototype.makeRequest = function(obj) { ...@@ -164,4 +164,4 @@ Client.prototype.makeRequest = function(obj) {
}); });
req.end(); req.end();
}; };
\ No newline at end of file
const Challonge = require('./challonge');
describe('Challonge object', () => {
it('should expose each of the api route class constructors', () => {
expect(Challonge.Client).toBeDefined();
expect(Challonge.Tournaments).toBeDefined();
expect(Challonge.Participants).toBeDefined();
expect(Challonge.Matches).toBeDefined();
});
it('should have a createClient method', () => {
expect(Challonge.createClient).toBeDefined();
});
describe('createClient method', () => {
let client;
beforeEach(() => {
client = Challonge.createClient({});
});
it('should return a new object with instantiated versions of the route classes', () => {
expect(client.client).toBeDefined();
expect(client.tournaments).toBeDefined();
expect(client.participants).toBeDefined();
expect(client.matches).toBeDefined();
});
it('should return a client with a setSubdomain method', () => {
expect(client.setSubdomain).toBeDefined();
});
it('should not fail if created with no arguments', () => {
client = Challonge.createClient();
});
});
describe('client.setSubdomain method', () => {
it('should proxy to setSubdomain on each of the clients route instances', () => {
const client = Challonge.createClient({});
spyOn(client.client, 'setSubdomain');
spyOn(client.tournaments, 'setSubdomain');
spyOn(client.participants, 'setSubdomain');
spyOn(client.matches, 'setSubdomain');
client.setSubdomain('somedomain');
expect(client.client.setSubdomain).toHaveBeenCalled();
expect(client.tournaments.setSubdomain).toHaveBeenCalled();
expect(client.participants.setSubdomain).toHaveBeenCalled();
expect(client.matches.setSubdomain).toHaveBeenCalled();
});
})
});
...@@ -23,9 +23,14 @@ ...@@ -23,9 +23,14 @@
"api-wrapper", "api-wrapper",
"wrapper" "wrapper"
], ],
"dependencies": { "dependencies": {},
},
"devDependencies": { "devDependencies": {
"istanbul": "^0.4.5",
"jasmine": "^2.5.3"
},
"scripts": {
"test": "./node_modules/jasmine/bin/jasmine.js",
"coverage": "node ./node_modules/istanbul/lib/cli.js cover --include-all-sources ./node_modules/jasmine/bin/jasmine.js"
}, },
"engine": "node >= 0.10.x" "engine": "node >= 0.10.x"
} }
...@@ -78,6 +78,23 @@ tournament: { tournamentType: 'single elimination' } ...@@ -78,6 +78,23 @@ tournament: { tournamentType: 'single elimination' }
tournament: { tournament_type: 'single elimination' } tournament: { tournament_type: 'single elimination' }
``` ```
## Development
### Install
``bash
$ git clone https://github.com/Tidwell/node-challonge
$ cd node-challonge
$ npm install
``
### Run Tests
[![Build Status](https://travis-ci.org/Tidwell/node-challonge.svg?branch=master)](https://travis-ci.org/Tidwell/node-challonge)
``bash
$ npm test
``
## TODO ## TODO
1. validate required params 1. validate required params
2. docs 2. docs
......
{
"spec_dir": "lib",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"spec/helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": false
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment