[CORD-1504] Handling XOSPermissionDenied errors
Change-Id: Icc1c796505207469d7416457802a3b9090031f72
diff --git a/src/app/datasources/rest/auth.rest.spec.ts b/src/app/datasources/rest/auth.rest.spec.ts
index 35732a3..7a406db 100644
--- a/src/app/datasources/rest/auth.rest.spec.ts
+++ b/src/app/datasources/rest/auth.rest.spec.ts
@@ -87,4 +87,37 @@
// httpBackend.flush();
});
});
+
+ describe('the handleUnauthenticatedRequest method', () => {
+
+ beforeEach(() => {
+ spyOn(service, 'clearUser');
+ });
+
+ it('should logout the user and redirect to login', () => {
+ service.handleUnauthenticatedRequest({
+ error: 'XOSPermissionDenied',
+ fields: {},
+ specific_error: 'test'
+ });
+ expect(service.clearUser).toHaveBeenCalled();
+ });
+
+ it('should catch errors from strings', () => {
+ service.handleUnauthenticatedRequest('{"fields": {}, "specific_error": "failed to authenticate token g09et150o2s25kdzg8t2n9wotvds9jyl", "error": "XOSPermissionDenied"}');
+ expect(service.clearUser).toHaveBeenCalled();
+ });
+
+ it('should not catch other errors', () => {
+ service.handleUnauthenticatedRequest({
+ error: 'XOSProgrammingError',
+ fields: {},
+ specific_error: 'test'
+ });
+ expect(service.clearUser).not.toHaveBeenCalled();
+
+ service.handleUnauthenticatedRequest('some error');
+ expect(service.clearUser).not.toHaveBeenCalled();
+ });
+ });
});