mirror of
https://github.com/Febbweiss/CloudBudget.git
synced 2026-03-05 06:45:39 +00:00
Feature: add retrieve account entries service
This commit is contained in:
@@ -252,11 +252,7 @@ module.exports = {
|
|||||||
|
|
||||||
list_entries : function(request, response) {
|
list_entries : function(request, response) {
|
||||||
return check_account(request, response, function(errors, account) {
|
return check_account(request, response, function(errors, account) {
|
||||||
Entry.find({
|
list_entries(account.id, null, function(errors, entries) {
|
||||||
account_id: account.id
|
|
||||||
})
|
|
||||||
.sort('-date')
|
|
||||||
.exec(function(errors, entries) {
|
|
||||||
if( errors ) {
|
if( errors ) {
|
||||||
return Handler.errorHandler(errors, 500, response);
|
return Handler.errorHandler(errors, 500, response);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -568,5 +568,48 @@ describe('API /accounts', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('* Retrieve', function() {
|
||||||
|
it('should retrieve all entries', function(done) {
|
||||||
|
request(globalServer)
|
||||||
|
.get('/api/accounts/' + account_id + '/entries')
|
||||||
|
.set('Authorization', 'JWT ' + token)
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.expect(200)
|
||||||
|
.end(function(errors, result) {
|
||||||
|
should.not.exist(errors);
|
||||||
|
|
||||||
|
var entries = result.body.entries;
|
||||||
|
should.exist(entries);
|
||||||
|
entries.should.be.instanceof(Array);
|
||||||
|
|
||||||
|
var balance = result.body.balance;
|
||||||
|
should.exist(balance);
|
||||||
|
balance.should.be.instanceof(Number);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail to retrieve entries for unknown account', function(done) {
|
||||||
|
request(globalServer)
|
||||||
|
.get('/api/accounts/' + token + '/entries')
|
||||||
|
.set('Authorization', 'JWT ' + token)
|
||||||
|
.expect(404, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail to retrieve entries for invalid account', function(done) {
|
||||||
|
request(globalServer)
|
||||||
|
.get('/api/accounts/1/entries')
|
||||||
|
.set('Authorization', 'JWT ' + token)
|
||||||
|
.expect(404, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail to retrieve entries for the not owned given account', function(done) {
|
||||||
|
request(globalServer)
|
||||||
|
.get('/api/accounts/' + account_id + '/entries')
|
||||||
|
.set('Authorization', 'JWT ' + hacker_token)
|
||||||
|
.expect(401, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user