-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hovhannes Babayan
committed
Jan 9, 2015
1 parent
a547ea2
commit bc8150e
Showing
6 changed files
with
156 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Logs in, then returns list of hours grouped by project names | ||
*/ | ||
|
||
var ApiFactory = require('./../../').ApiFactory; | ||
var ApiConstants = require('./../../').ApiConstants; | ||
var util = require('util'); | ||
|
||
var instance = ApiFactory.getInstance({ | ||
url: 'http://localhost:8080', | ||
version: '4.0' | ||
}); | ||
|
||
util.print('Logs in, then returns list of hours grouped by project names\n'); | ||
util.log('Logging in ...'); | ||
instance.login('new@user.attask', 'user').then( | ||
function(data) { | ||
util.log('Running report ...'); | ||
var query = {}; | ||
query['project:name_1' + ApiConstants.GROUPBY] = true; | ||
query['hours' + ApiConstants.AGGFUNC] = ApiConstants.Functions.SUM; | ||
instance.report('hour', query).then( | ||
function(data) { | ||
util.log('Report success. Received data:'); | ||
console.log(util.inspect(data, {colors:true})); | ||
}, | ||
function(error) { | ||
util.log('Report failure. Received data:'); | ||
console.log(util.inspect(error, {colors:true})); | ||
} | ||
); | ||
}, | ||
function(error) { | ||
util.log('Login failure. Received data:'); | ||
console.log(util.inspect(error, {colors:true})); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
module.exports = function(Api) { | ||
Api.prototype.report = function () { | ||
throw new Error('Not implemented') | ||
/** | ||
* Performs report request, where only the aggregate of some field is desired, with one or more groupings. | ||
* @param {String} objCode One of object codes from {@link https://developers.attask.com/api-docs/api-explorer/|AtTask API Explorer} | ||
* @param {Object} query An object with search criteria and aggregate functions | ||
* @return {Promise} A promise which will resolved with results if everything went ok and rejected otherwise | ||
*/ | ||
Api.prototype.report = function (objCode, query) { | ||
return this.request(objCode + '/report', query, null, Api.Methods.GET); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require('./../common'); | ||
|
||
var Api = require('./../../').Api; | ||
var ApiConstants = require('./../../').ApiConstants; | ||
|
||
|
||
describe('Api.report() method', function() { | ||
|
||
var api; | ||
var url = 'http://foobar:8080'; | ||
|
||
beforeEach(function () { | ||
api = new Api({url: url}); | ||
sinon.stub(api, "request"); | ||
}); | ||
|
||
afterEach(function () { | ||
api.request.restore(); // Unwraps the spy | ||
}); | ||
|
||
it('should call request() with proper params and return value received from request()', function() { | ||
var query = { | ||
'foo': 'bar' | ||
}; | ||
|
||
var objCode = 'baz'; | ||
|
||
var expectedReturnValue = 123; | ||
api.request.returns(expectedReturnValue); | ||
|
||
var actualReturnedValue = api.report(objCode, query); | ||
expect(api.request).to.have.callCount(1); | ||
expect(api.request).to.have.been.calledWith(objCode + "/report", query, null, "GET"); | ||
expect(actualReturnedValue).to.equal(expectedReturnValue); | ||
}); | ||
}); |