From c8cbfd576879dcd625581eec9cd7106ceb175c22 Mon Sep 17 00:00:00 2001 From: saleksandra Date: Fri, 11 Oct 2024 14:17:29 +0200 Subject: [PATCH] ANGOLASUP-931: Retrieving facilities from cache on the valid sorce and dastination list, supply line list --- .../admin-supply-line-list.routes.js | 6 +- .../admin-supply-line-list.routes.spec.js | 137 ++++++++++++++++++ .../admin-valid-destination-list.routes.js | 4 +- .../admin-valid-source-list.routes.js | 4 +- 4 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 src/admin-supply-line-list/admin-supply-line-list.routes.spec.js diff --git a/src/admin-supply-line-list/admin-supply-line-list.routes.js b/src/admin-supply-line-list/admin-supply-line-list.routes.js index e1e2142..673b46f 100644 --- a/src/admin-supply-line-list/admin-supply-line-list.routes.js +++ b/src/admin-supply-line-list/admin-supply-line-list.routes.js @@ -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) { diff --git a/src/admin-supply-line-list/admin-supply-line-list.routes.spec.js b/src/admin-supply-line-list/admin-supply-line-list.routes.spec.js new file mode 100644 index 0000000..6775c22 --- /dev/null +++ b/src/admin-supply-line-list/admin-supply-line-list.routes.spec.js @@ -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 info@OpenLMIS.org.  + */ + +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]; + } +}); \ No newline at end of file diff --git a/src/admin-valid-destination-list/admin-valid-destination-list.routes.js b/src/admin-valid-destination-list/admin-valid-destination-list.routes.js index 23cbcd0..64a50a9 100644 --- a/src/admin-valid-destination-list/admin-valid-destination-list.routes.js +++ b/src/admin-valid-destination-list/admin-valid-destination-list.routes.js @@ -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) { diff --git a/src/admin-valid-source-list/admin-valid-source-list.routes.js b/src/admin-valid-source-list/admin-valid-source-list.routes.js index 0b86ed0..d6e3adf 100644 --- a/src/admin-valid-source-list/admin-valid-source-list.routes.js +++ b/src/admin-valid-source-list/admin-valid-source-list.routes.js @@ -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) {