Skip to content

Commit

Permalink
ANGOLASUP-931: Retrieving facilities from cache on the valid sorce an…
Browse files Browse the repository at this point in the history
…d dastination list, supply line list
  • Loading branch information
saleksandra committed Oct 11, 2024
1 parent b2b205c commit c8cbfd5
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/admin-supply-line-list/admin-supply-line-list.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
controllerAs: 'vm',
accessRights: [ADMINISTRATION_RIGHTS.SUPPLY_LINES_MANAGE],
resolve: {
supplyingFacilities: function(FacilityRepository) {
return new FacilityRepository().query()
supplyingFacilities: function(FacilityResource) {
return new FacilityResource(true).getAll()
.then(function(response) {
return response.content;
return response;
});
},
programs: function(programService) {
Expand Down
137 changes: 137 additions & 0 deletions src/admin-supply-line-list/admin-supply-line-list.routes.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* 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('openlmis.administration.supplyLine', function() {

beforeEach(function() {
module('admin-supply-line-list');

inject(function($injector) {
this.FacilityDataBuilder = $injector.get('FacilityDataBuilder');
this.ProgramDataBuilder = $injector.get('ProgramDataBuilder');
this.SupplyLineDataBuilder = $injector.get('SupplyLineDataBuilder');
this.PageDataBuilder = $injector.get('PageDataBuilder');
this.$location = $injector.get('$location');
this.$rootScope = $injector.get('$rootScope');
this.$state = $injector.get('$state');
this.$q = $injector.get('$q');
this.FacilityResource = $injector.get('FacilityResource');
this.programService = $injector.get('programService');
this.SupplyLineResource = $injector.get('SupplyLineResource');
});

this.facilities = [
new this.FacilityDataBuilder().build(),
new this.FacilityDataBuilder().build()
];

this.programs = [
new this.ProgramDataBuilder().build(),
new this.ProgramDataBuilder().build()
];

this.supplyLines = [
new this.SupplyLineDataBuilder().buildJson(),
new this.SupplyLineDataBuilder().buildJson()
];

this.facilitiesPage = new this.PageDataBuilder()
.withContent(this.facilities)
.build();

this.supplyLinesPage = new this.PageDataBuilder()
.withContent(this.supplyLines)
.build();

this.goToUrl = goToUrl;
this.getResolvedValue = getResolvedValue;

spyOn(this.FacilityResource.prototype, 'getAll').andReturn(this.$q.resolve(this.facilitiesPage));
spyOn(this.programService, 'getAll').andReturn(this.$q.resolve(this.programs));
spyOn(this.SupplyLineResource.prototype, 'query').andReturn(this.$q.resolve(this.supplyLinesPage));
});

it('should be available under "/profile" URI', function() {
expect(this.$state.current.name).not.toEqual('openlmis.administration.supplyLines');

this.goToUrl('/administration/supplyLines');

expect(this.$state.current.name).toEqual('openlmis.administration.supplyLines');
});

it('should retrieve related supplying facilities', function() {
this.goToUrl('/administration/supplyLines');

expect(this.getResolvedValue('supplyingFacilities').content).toEqual(this.facilities);
});

it('should retrieve related programs', function() {
this.goToUrl('/administration/supplyLines');

expect(this.getResolvedValue('programs')).toEqual(this.programs);
});

it('should retrieve supply lines', function() {
this.goToUrl('/administration/supplyLines');

expect(this.SupplyLineResource.prototype.query).toHaveBeenCalledWith({
supplyingFacilityId: undefined,
programId: undefined,
page: 0,
size: 10,
sort: 'supplyingFacility.name',
expand: [
'supervisoryNode.requisitionGroup.memberFacilities',
'supplyingFacility',
'program'
]
});

expect(this.getResolvedValue('supplyLines')).toEqual(this.supplyLines);
});

it('should not change state when fetching supplying facilities fails', function() {
this.FacilityResource.prototype.getAll.andReturn(this.$q.reject());

this.goToUrl('/administration/supplyLines');

expect(this.$state.current.name).not.toEqual('openlmis.administration.supplyLines');
});

it('should not change state when fetching programs fails ', function() {
this.programService.getAll.andReturn(this.$q.reject());

this.goToUrl('/administration/supplyLines');

expect(this.$state.current.name).not.toEqual('openlmis.administration.supplyLines');
});

it('should not change state when fetching supply lines fails', function() {
this.SupplyLineResource.prototype.query.andReturn(this.$q.reject());

this.goToUrl('/administration/supplyLines');

expect(this.$state.current.name).not.toEqual('openlmis.administration.supplyLines');
});

function goToUrl(url) {
this.$location.url(url);
this.$rootScope.$apply();
}

function getResolvedValue(name) {
return this.$state.$current.locals.globals[name];
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
});
},
facilities: function(FacilityResource) {
return new FacilityResource().query()
return new FacilityResource(true).getAll()
.then(function(response) {
return response.content;
return response;
});
},
facilitiesById: function(facilities) {
Expand Down
4 changes: 2 additions & 2 deletions src/admin-valid-source-list/admin-valid-source-list.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
});
},
facilities: function(FacilityResource) {
return new FacilityResource().query()
return new FacilityResource(true).getAll()
.then(function(response) {
return response.content;
return response;
});
},
facilitiesById: function(facilities) {
Expand Down

0 comments on commit c8cbfd5

Please sign in to comment.