|
@@ -48,14 +48,26 @@ describe('AccountController', function() {
|
|
|
"type": "DEPOSIT",
|
|
"type": "DEPOSIT",
|
|
|
"category": "560a84058812ad8d0ff200f0",
|
|
"category": "560a84058812ad8d0ff200f0",
|
|
|
"sub_category": "560a84058812ad8d0ff200f3"
|
|
"sub_category": "560a84058812ad8d0ff200f3"
|
|
|
- };
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ DEFAULT_ACCOUNTS = [
|
|
|
|
|
+ {
|
|
|
|
|
+ "_id": "560a84058812ad8d0ff200ee",
|
|
|
|
|
+ "name": "foo",
|
|
|
|
|
+ "reference": "baz",
|
|
|
|
|
+ "user_id": "55b78934d2a706265ea28e9c"
|
|
|
|
|
+ }, {
|
|
|
|
|
+ "_id": "560a7ad08812ad8d0ff20068",
|
|
|
|
|
+ "name": "bar",
|
|
|
|
|
+ "user_id": "55b78934d2a706265ea28e9c"
|
|
|
|
|
+ }
|
|
|
|
|
+ ];
|
|
|
|
|
|
|
|
beforeEach(module('cloudbudget'));
|
|
beforeEach(module('cloudbudget'));
|
|
|
|
|
|
|
|
- beforeEach(inject(function ( _$rootScope_, _$httpBackend_, $controller, _$location_, $routeParams, _$timeout_, _$filter_, _AccountService_, _FlashService_, _apiRoutes_) {
|
|
|
|
|
|
|
+ beforeEach(inject(function ( _$rootScope_, _$httpBackend_, $controller, _$location_, _$timeout_, _$filter_, _AccountService_, _FlashService_, _apiRoutes_) {
|
|
|
$location = _$location_;
|
|
$location = _$location_;
|
|
|
- $httpBackend = $httpBackend;
|
|
|
|
|
- $rootScope = _$rootScope_.$new();
|
|
|
|
|
|
|
+ $httpBackend = _$httpBackend_;
|
|
|
|
|
+ $rootScope = _$rootScope_;
|
|
|
$scope = _$rootScope_.$new();
|
|
$scope = _$rootScope_.$new();
|
|
|
$scope.form = {
|
|
$scope.form = {
|
|
|
$valid: true,
|
|
$valid: true,
|
|
@@ -74,18 +86,21 @@ describe('AccountController', function() {
|
|
|
'$rootScope': $rootScope,
|
|
'$rootScope': $rootScope,
|
|
|
'$routeParams': {account_id: DEFAULT_ACCOUNT._id},
|
|
'$routeParams': {account_id: DEFAULT_ACCOUNT._id},
|
|
|
FlashService: _FlashService_,
|
|
FlashService: _FlashService_,
|
|
|
- AccountService: _AccountService_,
|
|
|
|
|
|
|
+ AccountService: _AccountService_
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
}));
|
|
}));
|
|
|
|
|
|
|
|
describe('init()', function() {
|
|
describe('init()', function() {
|
|
|
- it('should init successfully', inject(function($httpBackend) {
|
|
|
|
|
|
|
+ it('should init successfully', inject(function($httpBackend, $rootScope) {
|
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id)
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id)
|
|
|
.respond(DEFAULT_ACCOUNT);
|
|
.respond(DEFAULT_ACCOUNT);
|
|
|
|
|
|
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
|
.respond({entry: null, entries:[DEFAULT_ENTRY], balance: 100});
|
|
.respond({entry: null, entries:[DEFAULT_ENTRY], balance: 100});
|
|
|
|
|
+
|
|
|
|
|
+ $httpBackend.expect('GET', apiRoutes.accounts )
|
|
|
|
|
+ .respond(DEFAULT_ACCOUNTS);
|
|
|
|
|
|
|
|
var accountController = createController();
|
|
var accountController = createController();
|
|
|
$httpBackend.flush();
|
|
$httpBackend.flush();
|
|
@@ -95,15 +110,19 @@ describe('AccountController', function() {
|
|
|
accountController.account._id.should.be.equal(DEFAULT_ACCOUNT._id);
|
|
accountController.account._id.should.be.equal(DEFAULT_ACCOUNT._id);
|
|
|
accountController.entries.should.be.instanceof(Array).and.have.lengthOf(1);
|
|
accountController.entries.should.be.instanceof(Array).and.have.lengthOf(1);
|
|
|
accountController.balance.should.be.equal(100);
|
|
accountController.balance.should.be.equal(100);
|
|
|
|
|
+ $rootScope.accounts.should.be.instanceof(Array).and.have.lengthOf(2);
|
|
|
}));
|
|
}));
|
|
|
|
|
|
|
|
- it('should fail to init', inject(function($httpBackend) {
|
|
|
|
|
|
|
+ it('should fail to init', inject(function($httpBackend, $rootScope) {
|
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id)
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id)
|
|
|
.respond(400);
|
|
.respond(400);
|
|
|
|
|
|
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
|
.respond(400);
|
|
.respond(400);
|
|
|
|
|
|
|
|
|
|
+ $httpBackend.expect('GET', apiRoutes.accounts )
|
|
|
|
|
+ .respond(400);
|
|
|
|
|
+
|
|
|
var accountController = createController();
|
|
var accountController = createController();
|
|
|
$httpBackend.flush();
|
|
$httpBackend.flush();
|
|
|
$timeout.flush();
|
|
$timeout.flush();
|
|
@@ -111,6 +130,7 @@ describe('AccountController', function() {
|
|
|
should.not.exist(accountController.account);
|
|
should.not.exist(accountController.account);
|
|
|
accountController.entries.should.be.instanceof(Array).and.have.lengthOf(0);
|
|
accountController.entries.should.be.instanceof(Array).and.have.lengthOf(0);
|
|
|
should.not.exist(accountController.balance);
|
|
should.not.exist(accountController.balance);
|
|
|
|
|
+ should.not.exist($rootScope.accounts);
|
|
|
}));
|
|
}));
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -122,6 +142,9 @@ describe('AccountController', function() {
|
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
|
.respond({entry: null, entries:[], balance: 0});
|
|
.respond({entry: null, entries:[], balance: 0});
|
|
|
|
|
|
|
|
|
|
+ $httpBackend.expect('GET', apiRoutes.accounts )
|
|
|
|
|
+ .respond(DEFAULT_ACCOUNTS);
|
|
|
|
|
+
|
|
|
var accountController = createController();
|
|
var accountController = createController();
|
|
|
$httpBackend.flush();
|
|
$httpBackend.flush();
|
|
|
$timeout.flush();
|
|
$timeout.flush();
|
|
@@ -150,6 +173,9 @@ describe('AccountController', function() {
|
|
|
|
|
|
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
|
.respond({entry: null, entries:[], balance: 0});
|
|
.respond({entry: null, entries:[], balance: 0});
|
|
|
|
|
+
|
|
|
|
|
+ $httpBackend.expect('GET', apiRoutes.accounts )
|
|
|
|
|
+ .respond(DEFAULT_ACCOUNTS);
|
|
|
|
|
|
|
|
var accountController = createController();
|
|
var accountController = createController();
|
|
|
$httpBackend.flush();
|
|
$httpBackend.flush();
|
|
@@ -179,6 +205,9 @@ describe('AccountController', function() {
|
|
|
|
|
|
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
|
.respond({entry: null, entries:[DEFAULT_ENTRY], balance: 100});
|
|
.respond({entry: null, entries:[DEFAULT_ENTRY], balance: 100});
|
|
|
|
|
+
|
|
|
|
|
+ $httpBackend.expect('GET', apiRoutes.accounts )
|
|
|
|
|
+ .respond(DEFAULT_ACCOUNTS);
|
|
|
|
|
|
|
|
var accountController = createController();
|
|
var accountController = createController();
|
|
|
$httpBackend.flush();
|
|
$httpBackend.flush();
|
|
@@ -203,6 +232,9 @@ describe('AccountController', function() {
|
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
|
.respond({entry: null, entries:[DEFAULT_ACCOUNT], balance: 100});
|
|
.respond({entry: null, entries:[DEFAULT_ACCOUNT], balance: 100});
|
|
|
|
|
|
|
|
|
|
+ $httpBackend.expect('GET', apiRoutes.accounts )
|
|
|
|
|
+ .respond(DEFAULT_ACCOUNTS);
|
|
|
|
|
+
|
|
|
var accountController = createController();
|
|
var accountController = createController();
|
|
|
$httpBackend.flush();
|
|
$httpBackend.flush();
|
|
|
$timeout.flush();
|
|
$timeout.flush();
|
|
@@ -228,6 +260,9 @@ describe('AccountController', function() {
|
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
|
.respond({entry: null, entries:[DEFAULT_ENTRY], balance: 100});
|
|
.respond({entry: null, entries:[DEFAULT_ENTRY], balance: 100});
|
|
|
|
|
|
|
|
|
|
+ $httpBackend.expect('GET', apiRoutes.accounts )
|
|
|
|
|
+ .respond(DEFAULT_ACCOUNTS);
|
|
|
|
|
+
|
|
|
var accountController = createController();
|
|
var accountController = createController();
|
|
|
$httpBackend.flush();
|
|
$httpBackend.flush();
|
|
|
$timeout.flush();
|
|
$timeout.flush();
|
|
@@ -264,6 +299,9 @@ describe('AccountController', function() {
|
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
|
.respond({entry: null, entries:[DEFAULT_ENTRY], balance: 100});
|
|
.respond({entry: null, entries:[DEFAULT_ENTRY], balance: 100});
|
|
|
|
|
|
|
|
|
|
+ $httpBackend.expect('GET', apiRoutes.accounts )
|
|
|
|
|
+ .respond(DEFAULT_ACCOUNTS);
|
|
|
|
|
+
|
|
|
var accountController = createController();
|
|
var accountController = createController();
|
|
|
$httpBackend.flush();
|
|
$httpBackend.flush();
|
|
|
$timeout.flush();
|
|
$timeout.flush();
|
|
@@ -361,6 +399,9 @@ describe('AccountController', function() {
|
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
|
.respond({entry: null, entries:[], balance: 0});
|
|
.respond({entry: null, entries:[], balance: 0});
|
|
|
|
|
|
|
|
|
|
+ $httpBackend.expect('GET', apiRoutes.accounts )
|
|
|
|
|
+ .respond(DEFAULT_ACCOUNTS);
|
|
|
|
|
+
|
|
|
var accountController = createController();
|
|
var accountController = createController();
|
|
|
$httpBackend.flush();
|
|
$httpBackend.flush();
|
|
|
$timeout.flush();
|
|
$timeout.flush();
|
|
@@ -378,6 +419,9 @@ describe('AccountController', function() {
|
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
|
.respond({entry: null, entries:[], balance: 0});
|
|
.respond({entry: null, entries:[], balance: 0});
|
|
|
|
|
|
|
|
|
|
+ $httpBackend.expect('GET', apiRoutes.accounts )
|
|
|
|
|
+ .respond(DEFAULT_ACCOUNTS);
|
|
|
|
|
+
|
|
|
var accountController = createController();
|
|
var accountController = createController();
|
|
|
$httpBackend.flush();
|
|
$httpBackend.flush();
|
|
|
$timeout.flush();
|
|
$timeout.flush();
|
|
@@ -395,6 +439,9 @@ describe('AccountController', function() {
|
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
|
.respond({entry: null, entries:[], balance: 0});
|
|
.respond({entry: null, entries:[], balance: 0});
|
|
|
|
|
|
|
|
|
|
+ $httpBackend.expect('GET', apiRoutes.accounts )
|
|
|
|
|
+ .respond(DEFAULT_ACCOUNTS);
|
|
|
|
|
+
|
|
|
var accountController = createController();
|
|
var accountController = createController();
|
|
|
$httpBackend.flush();
|
|
$httpBackend.flush();
|
|
|
$timeout.flush();
|
|
$timeout.flush();
|
|
@@ -414,6 +461,9 @@ describe('AccountController', function() {
|
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
|
.respond({entry: null, entries:[], balance: 0});
|
|
.respond({entry: null, entries:[], balance: 0});
|
|
|
|
|
|
|
|
|
|
+ $httpBackend.expect('GET', apiRoutes.accounts )
|
|
|
|
|
+ .respond(DEFAULT_ACCOUNTS);
|
|
|
|
|
+
|
|
|
var accountController = createController();
|
|
var accountController = createController();
|
|
|
$httpBackend.flush();
|
|
$httpBackend.flush();
|
|
|
$timeout.flush();
|
|
$timeout.flush();
|
|
@@ -431,6 +481,9 @@ describe('AccountController', function() {
|
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
|
.respond({entry: null, entries:[], balance: 0});
|
|
.respond({entry: null, entries:[], balance: 0});
|
|
|
|
|
|
|
|
|
|
+ $httpBackend.expect('GET', apiRoutes.accounts )
|
|
|
|
|
+ .respond(DEFAULT_ACCOUNTS);
|
|
|
|
|
+
|
|
|
var accountController = createController();
|
|
var accountController = createController();
|
|
|
$httpBackend.flush();
|
|
$httpBackend.flush();
|
|
|
$timeout.flush();
|
|
$timeout.flush();
|
|
@@ -448,6 +501,9 @@ describe('AccountController', function() {
|
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
$httpBackend.expect('GET', apiRoutes.accounts + DEFAULT_ACCOUNT._id + '/entries')
|
|
|
.respond({entry: null, entries:[], balance: 0});
|
|
.respond({entry: null, entries:[], balance: 0});
|
|
|
|
|
|
|
|
|
|
+ $httpBackend.expect('GET', apiRoutes.accounts )
|
|
|
|
|
+ .respond(DEFAULT_ACCOUNTS);
|
|
|
|
|
+
|
|
|
var accountController = createController();
|
|
var accountController = createController();
|
|
|
$httpBackend.flush();
|
|
$httpBackend.flush();
|
|
|
$timeout.flush();
|
|
$timeout.flush();
|