init.setupShepherd(shepherd).then(function () { hbCheck(shepherd, true); shepherd._fire('ready'); deferred.resolve(); }).fail(function (err) { shepherd._server = null; shepherd._enabled = false; deferred.reject(err); }).done();
this.stop().then(function () { if (mode === true) { return shepherd._storage.reset().then(function () { debug('Database cleared.'); return shepherd.start(); }); } else return shepherd.start(); }).done(deferred.resolve, deferred.reject);
describe("players", function(done) { it("players exists as a public method on stattleship", function (done) { expect(typeof stattleship.players).to.eql('function'); done(); }); it("is successful when correct params are supplied", function(done) { var sport = 'baseball'; var league = 'mlb'; var endpoint = util.format('/%s/%s/players?page=1', sport, league); nock('https://api.stattleship.com') .get(endpoint) .reply(200, { players: [ { name: "Tony Stark" } ] }); stattleship.players(sport, league, {}).then(function(players) { expect(players[0].name).equals("Tony Stark"); done(); }).done(null, function(error) { done(error); }); }); });
paramedic.run(paramedicConfig) .catch(function (error) { if (error && error.stack) { console.error(error.stack); } else if (error) { console.error(error); } process.exit(1); }) .done(function(isTestPassed) { var exitCode = isTestPassed ? 0 : 1; console.log('Finished with exit code ' + exitCode); process.exit(exitCode); });
// called from Express framework function calculateRestHandler(req, res) { calculate() .then(function(result) { throw new Error('isCaugth') // triggers the catch() handler below res.status(200).send(result) }) .catch(function(error) { console.log(error) throw new Error('oops') // this error would not be noticed directly without the done() at the end of the promise chain res.status(500).send('internal chaos') }) .done() }
Q.all(reinitiateObservePromises).then(function (rsps) { _.forEach(rsps, function (rsp, idx) { if (rsp.code !== RSP.content) _.remove(self.observedList, paths[idx]); }); deferred.resolve(); }).fail(function (err) { deferred.reject(err); }).done();
this._coapServerStart(shepherd).then(function (server) { debug('Create a coap server for shepherd.'); shepherd._enabled = true; shepherd._server = server; return self._testRequestServer(shepherd); }).then(function () { debug('Coap server testing done.'); return self._loadNodesFromDb(shepherd); }).then(function () { debug('Loading cnodes from database done.'); return self._updateNetInfo(shepherd); }).then(function () { debug('coap-shepherd is up and ready.'); deferred.resolve(); }).fail(function (err) { debug(err); deferred.reject(err); }).done();
describe("injuries", function(done) { it("injuries exists as a public method on stattleship", function (done) { expect(typeof stattleship.injuries).to.eql('function'); done(); }); it("is successful when correct params are supplied", function(done) { var sport = 'baseball'; var league = 'mlb'; var endpoint = util.format('/%s/%s/injuries?page=1', sport, league); nock('https://api.stattleship.com') .get(endpoint) .reply(200, { injuries: [ { location_name: "Skull" } ] }); stattleship.injuries(sport, league, {}).then(function(injuries) { expect(injuries[0].location_name).equals("Skull"); done(); }).done(null, function(error) { done(error); }); }); });
describe("team_outcome_streaks", function(done) { it("team_outcome_streaks exists as a public method on stattleship", function (done) { expect(typeof stattleship.team_outcome_streaks).to.eql('function'); done(); }); it("is successful when correct params are supplied", function(done) { var sport = 'baseball'; var league = 'mlb'; var endpoint = util.format('/%s/%s/team_outcome_streaks?page=1', sport, league); nock('https://api.stattleship.com') .get(endpoint) .reply(200, { team_outcome_streaks: [ { streak_length: 42 } ] }); stattleship.team_outcome_streaks(sport, league, {}).then(function(team_outcome_streaks) { expect(team_outcome_streaks[0].streak_length).equals(42); done(); }).done(null, function(error) { done(error); }); }); });
describe("games", function(done) { it("game exists as a public method on stattleship", function (done) { expect(typeof stattleship.games).to.eql('function'); done(); }); it("is successful when correct params are supplied", function(done) { var sport = 'baseball'; var league = 'mlb'; var endpoint = util.format('/%s/%s/games?page=1', sport, league); nock('https://api.stattleship.com') .get(endpoint) .reply(200, { games: [ { label: "X-Men vs Avengers" } ] }); stattleship.games(sport, league, {}).then(function(games) { expect(games[0].label).equals("X-Men vs Avengers"); done(); }).done(null, function(error) { done(error); }); }); });
describe("rankings", function(done) { it("rankings exists as a public method on stattleship", function (done) { expect(typeof stattleship.rankings).to.eql('function'); done(); }); it("is successful when correct params are supplied", function(done) { var sport = 'baseball'; var league = 'mlb'; var endpoint = util.format('/%s/%s/rankings?page=1', sport, league); nock('https://api.stattleship.com') .get(endpoint) .reply(200, { rankings: [ { place: 42 } ] }); stattleship.rankings(sport, league, {}).then(function(rankings) { expect(rankings[0].place).equals(42); done(); }).done(null, function(error) { done(error); }); }); });
describe("rosters", function(done) { it("rosters exists as a public method on stattleship", function (done) { expect(typeof stattleship.rosters).to.eql('function'); done(); }); it("is successful when correct params are supplied", function(done) { var sport = 'baseball'; var league = 'mlb'; var endpoint = util.format('/%s/%s/rosters?page=1', sport, league); nock('https://api.stattleship.com') .get(endpoint) .reply(200, { rosters: [ { team_id: 'kjh34kj23hkjh' } ] }); stattleship.rosters(sport, league, {}).then(function(rosters) { expect(rosters[0].team_id).equals('kjh34kj23hkjh'); done(); }).done(null, function(error) { done(error); }); }); });
describe("team_game_logs", function(done) { it("team_game_logs exists as a public method on stattleship", function (done) { expect(typeof stattleship.team_game_logs).to.eql('function'); done(); }); it("is successful when correct params are supplied", function(done) { var sport = 'baseball'; var league = 'mlb'; var endpoint = util.format('/%s/%s/team_game_logs?page=1', sport, league); nock('https://api.stattleship.com') .get(endpoint) .reply(200, { team_game_logs: [ { home_team_outcome: 'win' } ] }); stattleship.team_game_logs(sport, league, {}).then(function(team_game_logs) { expect(team_game_logs[0].home_team_outcome).equals('win'); done(); }).done(null, function(error) { done(error); }); }); });
describe("top_stats", function(done) { it("top_stats exists as a public method on stattleship", function (done) { expect(typeof stattleship.top_stats).to.eql('function'); done(); }); it("is successful when correct params are supplied", function(done) { var sport = 'baseball'; var league = 'mlb'; var endpoint = util.format('/%s/%s/top_stats?page=1', sport, league); nock('https://api.stattleship.com') .get(endpoint) .reply(200, { top_stats: [ { stat_name: 'hits' } ] }); stattleship.top_stats(sport, league, {}).then(function(top_stats) { expect(top_stats[0].stat_name).equals('hits'); done(); }).done(null, function(error) { done(error); }); }); });
describe("penalties", function(done) { it("penalties exists as a public method on stattleship", function (done) { expect(typeof stattleship.penalties).to.eql('function'); done(); }); it("is successful when correct params are supplied", function(done) { var sport = 'baseball'; var league = 'mlb'; var endpoint = util.format('/%s/%s/penalties?page=1', sport, league); nock('https://api.stattleship.com') .get(endpoint) .reply(200, { penalties: [ { name: "Inappropriate Touching" } ] }); stattleship.penalties(sport, league, {}).then(function(penalties) { expect(penalties[0].name).equals("Inappropriate Touching"); done(); }).done(null, function(error) { done(error); }); }); });