Index: CHANGELOG.md =================================================================== diff -u -N -rbfcb475d0473cb72339447f336a9ca331a40f0df -r77fc7be18e31e95492e9ace84af5ee77fee64324 --- CHANGELOG.md (.../CHANGELOG.md) (revision bfcb475d0473cb72339447f336a9ca331a40f0df) +++ CHANGELOG.md (.../CHANGELOG.md) (revision 77fc7be18e31e95492e9ace84af5ee77fee64324) @@ -6,6 +6,7 @@ New functionality that are backwards-compatible: * [OLMIS-7187](https://openlmis.atlassian.net/browse/OLMIS-7187): Added the ability to cache Lots and Orderable Fulfills in the local storage and Orderables in the local database on login. +* [OLMIS-7204](https://openlmis.atlassian.net/browse/OLMIS-7204): Added the error message when no facilities are available in offline mode. 5.6.4 / 2020-11-17 ================== Index: src/openlmis-permissions/permission.service.spec.js =================================================================== diff -u -N -rf6abbca6430cd521d936c4791def2617623971b4 -r77fc7be18e31e95492e9ace84af5ee77fee64324 --- src/openlmis-permissions/permission.service.spec.js (.../permission.service.spec.js) (revision f6abbca6430cd521d936c4791def2617623971b4) +++ src/openlmis-permissions/permission.service.spec.js (.../permission.service.spec.js) (revision 77fc7be18e31e95492e9ace84af5ee77fee64324) @@ -31,6 +31,8 @@ this.RoleResource = $injector.get('RoleResource'); this.$q = $injector.get('$q'); this.currentUserRolesService = $injector.get('currentUserRolesService'); + this.alertService = $injector.get('alertService'); + this.offlineService = $injector.get('offlineService'); }); this.possessedRightName = 'POSSESSED_RIGHT'; @@ -115,6 +117,7 @@ this.roles[2], this.roles[3] ])); + spyOn(this.offlineService, 'isOffline').andReturn(false); }); @@ -225,6 +228,20 @@ this.$httpBackend.verifyNoOutstandingRequest(); }); + it('will reject if no available cached permissions in offline mode', function() { + spyOn(this.alertService, 'error'); + + this.offlineService.isOffline.andReturn(true); + this.localStorageService.get.andReturn(null); + + this.permissionService.load('userId'); + this.$rootScope.$apply(); + + expect(this.offlineService.isOffline).toHaveBeenCalled(); + expect(this.alertService.error).toHaveBeenCalledWith('openlmisOffline.actionNotAllowedOffline'); + this.$httpBackend.verifyNoOutstandingRequest(); + }); + describe('hasPermission', function() { beforeEach(function() { Index: src/referencedata-facilities-cache/facility.service.decorator.js =================================================================== diff -u -N -rfdf31f320790f5d450e94d975e15b7ba400eef4f -r77fc7be18e31e95492e9ace84af5ee77fee64324 --- src/referencedata-facilities-cache/facility.service.decorator.js (.../facility.service.decorator.js) (revision fdf31f320790f5d450e94d975e15b7ba400eef4f) +++ src/referencedata-facilities-cache/facility.service.decorator.js (.../facility.service.decorator.js) (revision 77fc7be18e31e95492e9ace84af5ee77fee64324) @@ -35,9 +35,9 @@ $provide.decorator('facilityService', decorator); } - decorator.$inject = ['$delegate', '$q', 'LocalDatabase']; + decorator.$inject = ['$delegate', '$q', 'LocalDatabase', 'offlineService', 'alertService']; - function decorator($delegate, $q, LocalDatabase) { + function decorator($delegate, $q, LocalDatabase, offlineService, alertService) { var originalGetAllMinimal = $delegate.getAllMinimal, minimalFacilitiesDatabase = new LocalDatabase('minimalFacilities'), cached = false, @@ -84,6 +84,11 @@ return $q.resolve(); } + if (offlineService.isOffline() && !cached) { + alertService.error('referencedataFacilitiesCache.offlineMessage'); + return $q.reject(); + } + if (!promise) { promise = originalGetAllMinimal.apply($delegate, arguments) .then(function(facilities) { Index: src/referencedata-facilities-cache/facility.service.decorator.spec.js =================================================================== diff -u -N -r39674ffa4ba9f293ef59219457d81ddcb87d4bc1 -r77fc7be18e31e95492e9ace84af5ee77fee64324 --- src/referencedata-facilities-cache/facility.service.decorator.spec.js (.../facility.service.decorator.spec.js) (revision 39674ffa4ba9f293ef59219457d81ddcb87d4bc1) +++ src/referencedata-facilities-cache/facility.service.decorator.spec.js (.../facility.service.decorator.spec.js) (revision 77fc7be18e31e95492e9ace84af5ee77fee64324) @@ -36,6 +36,8 @@ this.facilityService = $injector.get('facilityService'); this.LocalDatabase = $injector.get('LocalDatabase'); this.MinimalFacilityDataBuilder = $injector.get('MinimalFacilityDataBuilder'); + this.alertService = $injector.get('alertService'); + this.offlineService = $injector.get('offlineService'); }); this.minimalFacilities = [ @@ -48,6 +50,7 @@ spyOn(this.LocalDatabase.prototype, 'getAll'); spyOn(this.LocalDatabase.prototype, 'get'); spyOn(this.LocalDatabase.prototype, 'removeAll'); + spyOn(this.offlineService, 'isOffline').andReturn(false); }); describe('cacheAllMinimal', function() { @@ -211,6 +214,18 @@ expect(this.originalGetAllMinimalSpy).toHaveBeenCalled(); }); + it('should reject if data is not cached in offline mode', function() { + spyOn(this.alertService, 'error'); + + this.offlineService.isOffline.andReturn(true); + this.facilityService.cacheAllMinimal(); + this.$rootScope.$apply(); + + expect(this.originalGetAllMinimalSpy).not.toHaveBeenCalled(); + expect(this.offlineService.isOffline).toHaveBeenCalled(); + expect(this.alertService.error).toHaveBeenCalledWith('referencedataFacilitiesCache.offlineMessage'); + }); + }); describe('getAllMinimal', function() { Index: src/referencedata-facilities-cache/messages_en.json =================================================================== diff -u -N --- src/referencedata-facilities-cache/messages_en.json (revision 0) +++ src/referencedata-facilities-cache/messages_en.json (revision 77fc7be18e31e95492e9ace84af5ee77fee64324) @@ -0,0 +1,3 @@ +{ + "referencedataFacilitiesCache.offlineMessage": "Not all facilities are available offline. Please return to online mode." +} \ No newline at end of file