Skip to content

Commit

Permalink
added .revenue to Apartment
Browse files Browse the repository at this point in the history
  • Loading branch information
abarnhard committed Jul 25, 2014
1 parent 5f2135c commit e36f4ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/models/apartment.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ Apartment.tenants = function(cb){
});
};

Apartment.revenue = function(cb){
Apartment.find({}, function(apts){
var sum = 0;
for(var i = 0; i < apts.length; i++){
if(apts[i].renters.length > 0){
sum += apts[i].cost();
}
}
cb(sum);
});
};

// HELPER FUNCTIONS //

function reProto(apt){
Expand Down
8 changes: 8 additions & 0 deletions test/unit/apartment.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ describe('Apartment', function(){
});
});
});
describe('.revenue', function(){
it('should return the total revenue from all occupied apartments', function(done){
Apartment.revenue(function(revenue){
expect(revenue).to.equal(4500);
done();
});
});
});

});

0 comments on commit e36f4ca

Please sign in to comment.