[CORD-2827] Fixed unauthorized error handling
Change-Id: I6ddef7f869c17db4d8479f23f6e8734f6002d8fc
diff --git a/src/app/datasources/rest/auth.rest.spec.ts b/src/app/datasources/rest/auth.rest.spec.ts
index 8ba77d3..044cf88 100644
--- a/src/app/datasources/rest/auth.rest.spec.ts
+++ b/src/app/datasources/rest/auth.rest.spec.ts
@@ -106,36 +106,36 @@
});
});
- describe('the handleUnauthenticatedRequest method', () => {
+ describe('the isAuthError method', () => {
beforeEach(() => {
spyOn(service, 'clearUser');
});
it('should logout the user and redirect to login', () => {
- service.handleUnauthenticatedRequest({
+ let res = service.isAuthError({
error: 'XOSPermissionDenied',
fields: {},
specific_error: 'test'
});
- expect(service.clearUser).toHaveBeenCalled();
+ expect(res).toBeTruthy();
});
it('should catch errors from strings', () => {
- service.handleUnauthenticatedRequest('{"fields": {}, "specific_error": "failed to authenticate token g09et150o2s25kdzg8t2n9wotvds9jyl", "error": "XOSPermissionDenied"}');
- expect(service.clearUser).toHaveBeenCalled();
+ let res = service.isAuthError('{"fields": {}, "specific_error": "failed to authenticate token g09et150o2s25kdzg8t2n9wotvds9jyl", "error": "XOSPermissionDenied"}');
+ expect(res).toBeTruthy();
});
it('should not catch other errors', () => {
- service.handleUnauthenticatedRequest({
+ let res = service.isAuthError({
error: 'XOSProgrammingError',
fields: {},
specific_error: 'test'
});
- expect(service.clearUser).not.toHaveBeenCalled();
+ expect(res).toBeFalsy();
- service.handleUnauthenticatedRequest('some error');
- expect(service.clearUser).not.toHaveBeenCalled();
+ res = service.isAuthError('some error');
+ expect(res).toBeFalsy();
});
});
});