Commit 420653f2 authored by Aaron Tidwell's avatar Aaron Tidwell Committed by GitHub

add support for process and abort checkin endpoints (#27)

parent 6b6b80d8
......@@ -15,6 +15,8 @@ const Client = require('./client').Client;
* start POST tournaments/:tournament/start
* finalize POST tournaments/:tournament/finalize
* reset POST tournaments/:tournament/reset
* process_check_ins POST tournaments/:tournament/process_check_ins
* abort_check_in POST tournaments/:tournament/abort_check_in
* </pre>
*/
const Tournaments = exports.Tournaments = function(options) {
......@@ -246,3 +248,65 @@ Tournaments.prototype.reset = function(obj) {
obj.method = 'POST';
this.makeRequest(obj);
};
/**
* @function
* @memberof Tournaments
* @param {object} obj params to pass to the api request
* @param {string} obj.id The url of the tournament to processCheckIns
* @param {function} obj.callback A method to call when the API returns. Arguments are (error, data)
* @description
* This should be invoked after a tournament's check-in window closes before the tournament is started.
* <pre>
Marks participants who have not checked in as inactive.
Moves inactive participants to bottom seeds (ordered by original seed).
Transitions the tournament state from 'checking_in' to 'checked_in'
NOTE: Checked in participants on the waiting list will be promoted if slots become available.
</pre>
* See the {@link http://api.challonge.com/v1/documents/tournaments/process_check_ins|Challonge API Doc} for a full list of object properties.
* @example
client.tournaments.processCheckIns({
id: 'my-tournament-url',
callback: (err, data) => {
console.log(err, data);
}
});
*/
Tournaments.prototype.processCheckIns = function(obj) {
obj.path = '/' + this.options.get('subdomain') + obj.id + '/process_check_ins';
delete obj.id;
obj.method = 'POST';
this.makeRequest(obj);
};
/**
* @function
* @memberof Tournaments
* @param {object} obj params to pass to the api request
* @param {string} obj.id The url of the tournament to abortCheckIn
* @param {function} obj.callback A method to call when the API returns. Arguments are (error, data)
* @description
* When your tournament is in a 'checking_in' or 'checked_in' state, there's no way to edit the tournament's start time (start_at) or check-in duration (check_in_duration). You must first abort check-in, then you may edit those attributes.
* <pre>
Makes all participants active and clears their checked_in_at times.
Transitions the tournament state from 'checking_in' or 'checked_in' to 'pending'
</pre>
* See the {@link http://api.challonge.com/v1/documents/tournaments/abort_check_in|Challonge API Doc} for a full list of object properties.
* @example
client.tournaments.abortCheckIn({
id: 'my-tournament-url',
callback: (err, data) => {
console.log(err, data);
}
});
*/
Tournaments.prototype.abortCheckIn = function(obj) {
obj.path = '/' + this.options.get('subdomain') + obj.id + '/abort_check_in';
delete obj.id;
obj.method = 'POST';
this.makeRequest(obj);
};
......@@ -261,4 +261,58 @@ describe('tournaments endpoints', () => {
});
});
});
// process_check_ins POST tournaments/:tournament/process_check_ins
describe('process_check_ins', () => {
it('should create an appropriate url without a subdomain', () => {
tournamentsInstance.makeRequest = (obj) => {
expect(obj).toEqual({
path: '/25/process_check_ins',
method: 'POST'
});
};
tournamentsInstance.processCheckIns({
id: 25
});
});
it('should create an appropriate url with a subdomain', () => {
tournamentsInstance.options.subdomain = 'somedomain-';
tournamentsInstance.makeRequest = (obj) => {
expect(obj).toEqual({
path: '/somedomain-25/process_check_ins',
method: 'POST'
});
};
tournamentsInstance.processCheckIns({
id: 25
});
});
});
// process_check_ins POST tournaments/:tournament/process_check_ins
describe('abort_check_in', () => {
it('should create an appropriate url without a subdomain', () => {
tournamentsInstance.makeRequest = (obj) => {
expect(obj).toEqual({
path: '/25/abort_check_in',
method: 'POST'
});
};
tournamentsInstance.abortCheckIn({
id: 25
});
});
it('should create an appropriate url with a subdomain', () => {
tournamentsInstance.options.subdomain = 'somedomain-';
tournamentsInstance.makeRequest = (obj) => {
expect(obj).toEqual({
path: '/somedomain-25/abort_check_in',
method: 'POST'
});
};
tournamentsInstance.abortCheckIn({
id: 25
});
});
});
});
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