-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from OpenLMIS-Angola/OAM-290
OAM-290: Made issue work offline
- Loading branch information
Showing
4 changed files
with
188 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* This program is part of the OpenLMIS logistics management information system platform software. | ||
* Copyright © 2017 VillageReach | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Affero General Public License as published by the Free Software Foundation, either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Affero General Public License for more details. You should have received a copy of | ||
* the GNU Affero General Public License along with this program. If not, see | ||
* http://www.gnu.org/licenses. For additional information contact [email protected]. | ||
*/ | ||
|
||
(function() { | ||
|
||
'use strict'; | ||
|
||
angular | ||
.module('stock-valid-sources') | ||
.run(routes); | ||
|
||
routes.$inject = ['loginService', 'sourceDestinationService', 'facilityFactory', '$q', 'programService', | ||
'authorizationService']; | ||
|
||
function routes(loginService, sourceDestinationService, facilityFactory, $q, programService, | ||
authorizationService) { | ||
|
||
loginService.registerPostLoginAction(function() { | ||
var userId = authorizationService.getUser().user_id; | ||
var userProgramsPromise = programService.getUserPrograms(userId); | ||
var homeFacilityPromise = facilityFactory.getUserHomeFacility(); | ||
|
||
$q.all([userProgramsPromise, homeFacilityPromise]).then(function(responses) { | ||
var userProgramsIds = responses[0].map(function(program) { | ||
return program.id; | ||
}); | ||
var homeFacility = responses[1]; | ||
sourceDestinationService.cacheDestinationsAndSources(userProgramsIds, homeFacility.id); | ||
}); | ||
}); | ||
|
||
loginService.registerPostLogoutAction(function() { | ||
return $q.all([ | ||
sourceDestinationService.clearSourcesCache(), | ||
sourceDestinationService.clearDestinationsCache() | ||
]); | ||
}); | ||
} | ||
})(); |
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,91 @@ | ||
/* | ||
* This program is part of the OpenLMIS logistics management information system platform software. | ||
* Copyright © 2017 VillageReach | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Affero General Public License as published by the Free Software Foundation, either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Affero General Public License for more details. You should have received a copy of | ||
* the GNU Affero General Public License along with this program. If not, see | ||
* http://www.gnu.org/licenses. For additional information contact [email protected]. | ||
*/ | ||
|
||
describe('source-cache run', function() { | ||
|
||
beforeEach(function() { | ||
var context = this; | ||
module('stock-valid-sources'); | ||
module('referencedata-user', function($provide) { | ||
context.loginServiceSpy = jasmine.createSpyObj('loginService', [ | ||
'registerPostLoginAction', 'registerPostLogoutAction' | ||
]); | ||
$provide.value('loginService', context.loginServiceSpy); | ||
}); | ||
|
||
inject(function($injector) { | ||
this.$rootScope = $injector.get('$rootScope'); | ||
this.$q = $injector.get('$q'); | ||
this.sourceDestinationService = $injector.get('sourceDestinationService'); | ||
this.facilityFactory = $injector.get('facilityFactory'); | ||
this.ProgramDataBuilder = $injector.get('ProgramDataBuilder'); | ||
this.FacilityDataBuilder = $injector.get('FacilityDataBuilder'); | ||
this.UserDataBuilder = $injector.get('UserDataBuilder'); | ||
}); | ||
|
||
this.program1 = new this.ProgramDataBuilder().build(); | ||
this.program2 = new this.ProgramDataBuilder().build(); | ||
|
||
this.programs = [ | ||
this.program1, | ||
this.program2 | ||
]; | ||
|
||
this.homeFacility = new this.FacilityDataBuilder() | ||
.withSupportedPrograms(this.programs) | ||
.build(); | ||
|
||
this.user = new this.UserDataBuilder().build(); | ||
|
||
this.sourceAssignments = [{ | ||
id: 'source-one', | ||
facilityTypeId: 'fac-type-id-one', | ||
programid: 'program-id-one' | ||
}, { | ||
id: 'source-two', | ||
facilityTypeId: 'fac-type-id-two', | ||
programid: 'program-id-two' | ||
}]; | ||
|
||
this.postLoginAction = getLastCall(this.loginServiceSpy.registerPostLoginAction).args[0]; | ||
|
||
spyOn(this.facilityFactory, 'getUserHomeFacility').andReturn(this.$q.resolve(this.homeFacility)); | ||
spyOn(this.sourceDestinationService, 'cacheDestinationsAndSources') | ||
.andReturn(this.$q.resolve(this.sourceAssignments)); | ||
spyOn(this.sourceDestinationService, 'clearSourcesCache'); | ||
}); | ||
|
||
describe('run block', function() { | ||
|
||
it('should register post login action', function() { | ||
expect(this.loginServiceSpy.registerPostLoginAction).toHaveBeenCalled(); | ||
}); | ||
|
||
}); | ||
|
||
describe('post login action', function() { | ||
it('should get user home facility', function() { | ||
this.postLoginAction(this.user); | ||
this.$rootScope.$apply(); | ||
|
||
expect(this.facilityFactory.getUserHomeFacility).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
function getLastCall(method) { | ||
return method.calls[method.calls.length - 1]; | ||
} | ||
|
||
}); |