-
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 #143 from OpenLMIS-Angola/feature/OAM-218
OAM-218: merge requests on preload
- Loading branch information
Showing
14 changed files
with
1,691 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/referencedata-orderable-fulfills/orderable-fulfills.run.js
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,54 @@ | ||
/* | ||
* 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('referencedata-orderable-fulfills') | ||
.run(run); | ||
|
||
run.$inject = ['loginService', 'orderableFulfillsService', 'facilityFactory', '$q']; | ||
|
||
function run(loginService, orderableFulfillsService, facilityFactory, $q) { | ||
|
||
loginService.registerPostLoginAction(function() { | ||
orderableFulfillsService.clearOrderableFulfillsOffline(); | ||
var homeFacility; | ||
|
||
return facilityFactory.getUserHomeFacility() | ||
.then(function(facility) { | ||
homeFacility = facility; | ||
var programs = homeFacility.supportedPrograms; | ||
|
||
var supportedProgramsIds = programs.map(function(program) { | ||
return program.id ? program.id : program; | ||
}); | ||
|
||
var orderableFulfills = orderableFulfillsService.query({ | ||
facilityId: homeFacility.id ? homeFacility.id : homeFacility, | ||
programId: supportedProgramsIds | ||
}); | ||
|
||
return orderableFulfills; | ||
}) | ||
.catch(function() { | ||
return $q.resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
})(); |
108 changes: 108 additions & 0 deletions
108
src/referencedata-orderable-fulfills/orderable-fulfills.run.spec.js
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,108 @@ | ||
/* | ||
* 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('referencedata-orderable-fulfills run', function() { | ||
|
||
beforeEach(function() { | ||
var context = this; | ||
module('referencedata-orderable-fulfills'); | ||
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.orderableFulfillsService = $injector.get('orderableFulfillsService'); | ||
this.PageDataBuilder = $injector.get('PageDataBuilder'); | ||
this.facilityFactory = $injector.get('facilityFactory'); | ||
this.programService = $injector.get('programService'); | ||
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.orderableFulfills = { | ||
idOne: { | ||
canFulfillForMe: [1, 2], | ||
canBeFulfilledByMe: [] | ||
}, | ||
idTwo: { | ||
canFulfillForMe: [], | ||
canBeFulfilledByMe: [] | ||
} | ||
}; | ||
|
||
this.user = new this.UserDataBuilder().build(); | ||
|
||
this.postLoginAction = getLastCall(this.loginServiceSpy.registerPostLoginAction).args[0]; | ||
|
||
spyOn(this.facilityFactory, 'getUserHomeFacility').andReturn(this.$q.resolve(this.homeFacility)); | ||
spyOn(this.orderableFulfillsService, 'query').andReturn(this.$q.resolve(this.orderableFulfills)); | ||
spyOn(this.orderableFulfillsService, 'clearOrderableFulfillsOffline'); | ||
}); | ||
|
||
describe('run block', function() { | ||
|
||
it('should register post login action', function() { | ||
expect(this.loginServiceSpy.registerPostLoginAction).toHaveBeenCalled(); | ||
}); | ||
|
||
}); | ||
|
||
describe('post login action', function() { | ||
|
||
it('should clear orderable fulfills cache', function() { | ||
this.postLoginAction(this.user); | ||
this.$rootScope.$apply(); | ||
|
||
expect(this.orderableFulfillsService.clearOrderableFulfillsOffline).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should get user home facility', function() { | ||
this.postLoginAction(this.user); | ||
this.$rootScope.$apply(); | ||
|
||
expect(this.facilityFactory.getUserHomeFacility).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should get orderable fulfills', function() { | ||
this.postLoginAction(this.user); | ||
this.$rootScope.$apply(); | ||
|
||
expect(this.orderableFulfillsService.query).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
function getLastCall(method) { | ||
return method.calls[method.calls.length - 1]; | ||
} | ||
|
||
}); |
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,46 @@ | ||
/* | ||
* 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('referencedata-orderable') | ||
.run(routes); | ||
|
||
routes.$inject = ['loginService', 'OrderableResource', 'programService']; | ||
|
||
function routes(loginService, OrderableResource, programService) { | ||
|
||
loginService.registerPostLoginAction(function(user) { | ||
return programService.getUserPrograms(user.userId) | ||
.then(function(programs) { | ||
var supportedProgramsCodes = programs.map(function(program) { | ||
return program.code; | ||
}); | ||
|
||
return new OrderableResource() | ||
.getAll({ | ||
program: supportedProgramsCodes | ||
}) | ||
.then(function(orderables) { | ||
return orderables; | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
})(); |
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,89 @@ | ||
/* | ||
* 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('orderable run', function() { | ||
|
||
beforeEach(function() { | ||
var context = this; | ||
module('referencedata-user'); | ||
module('referencedata-orderable', 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.OrderableResource = $injector.get('OrderableResource'); | ||
this.OrderableDataBuilder = $injector.get('OrderableDataBuilder'); | ||
this.programService = $injector.get('programService'); | ||
this.ProgramDataBuilder = $injector.get('ProgramDataBuilder'); | ||
this.UserDataBuilder = $injector.get('UserDataBuilder'); | ||
}); | ||
|
||
this.program1 = new this.ProgramDataBuilder().build(); | ||
this.program2 = new this.ProgramDataBuilder().build(); | ||
|
||
this.programs = [ | ||
this.program1, | ||
this.program2 | ||
]; | ||
|
||
this.orderables = [ | ||
new this.OrderableDataBuilder().build(), | ||
new this.OrderableDataBuilder().build() | ||
]; | ||
|
||
this.user = new this.UserDataBuilder().build(); | ||
|
||
this.postLoginAction = getLastCall(this.loginServiceSpy.registerPostLoginAction).args[0]; | ||
|
||
spyOn(this.programService, 'getUserPrograms').andReturn(this.$q.resolve(this.programs)); | ||
spyOn(this.OrderableResource.prototype, 'getAll').andReturn(this.$q.when(this.orderables)); | ||
}); | ||
|
||
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 programs', function() { | ||
this.user.userId = this.user.id; | ||
this.postLoginAction(this.user); | ||
this.$rootScope.$apply(); | ||
|
||
expect(this.programService.getUserPrograms).toHaveBeenCalledWith(this.user.id); | ||
}); | ||
|
||
it('should get orderables', function() { | ||
this.postLoginAction(this.user); | ||
this.$rootScope.$apply(); | ||
|
||
expect(this.OrderableResource.prototype.getAll).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
function getLastCall(method) { | ||
return method.calls[method.calls.length - 1]; | ||
} | ||
|
||
}); |
Oops, something went wrong.