Refactored components' name and added missing tests

This commit is contained in:
Giuseppe Digilio
2020-01-02 18:21:47 +01:00
parent 972f0dfd60
commit fdd05d2fec
29 changed files with 637 additions and 285 deletions

View File

@@ -18,13 +18,14 @@ import {
LogOutErrorAction,
LogOutSuccessAction,
RefreshTokenErrorAction,
RefreshTokenSuccessAction
RefreshTokenSuccessAction, RetrieveAuthMethodsAction, RetrieveAuthMethodsErrorAction, RetrieveAuthMethodsSuccessAction
} from './auth.actions';
import { AuthServiceStub } from '../../shared/testing/auth-service-stub';
import { authMethodsMock, AuthServiceStub } from '../../shared/testing/auth-service-stub';
import { AuthService } from './auth.service';
import { AuthState } from './auth.reducer';
import { EPersonMock } from '../../shared/testing/eperson-mock';
import { AuthStatus } from './models/auth-status.model';
describe('AuthEffects', () => {
let authEffects: AuthEffects;
@@ -153,6 +154,49 @@ describe('AuthEffects', () => {
})
});
describe('checkTokenCookie$', () => {
describe('when check token succeeded', () => {
it('should return a AUTHENTICATED action in response to a CHECK_AUTHENTICATION_TOKEN_COOKIE action when authenticated is true', () => {
spyOn((authEffects as any).authService, 'checkAuthenticationCookie').and.returnValue(
observableOf(
{ authenticated: true,
token
})
);
actions = hot('--a-', {a: {type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN_COOKIE}});
const expected = cold('--b-', {b: new AuthenticatedAction(token)});
expect(authEffects.checkTokenCookie$).toBeObservable(expected);
});
it('should return a RETRIEVE_AUTH_METHODS action in response to a CHECK_AUTHENTICATION_TOKEN_COOKIE action when authenticated is false', () => {
spyOn((authEffects as any).authService, 'checkAuthenticationCookie').and.returnValue(
observableOf(
{ authenticated: false })
);
actions = hot('--a-', {a: {type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN_COOKIE}});
const expected = cold('--b-', {b: new RetrieveAuthMethodsAction({ authenticated: false } as AuthStatus)});
expect(authEffects.checkTokenCookie$).toBeObservable(expected);
});
});
describe('when check token failed', () => {
it('should return a AUTHENTICATED_ERROR action in response to a CHECK_AUTHENTICATION_TOKEN_COOKIE action', () => {
spyOn((authEffects as any).authService, 'checkAuthenticationCookie').and.returnValue(observableThrow(new Error('Message Error test')));
actions = hot('--a-', {a: {type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN_COOKIE, payload: token}});
const expected = cold('--b-', {b: new AuthenticatedErrorAction(new Error('Message Error test'))});
expect(authEffects.checkTokenCookie$).toBeObservable(expected);
});
})
});
describe('refreshToken$', () => {
describe('when refresh token succeeded', () => {
@@ -204,4 +248,30 @@ describe('AuthEffects', () => {
});
})
});
describe('retrieveMethods$', () => {
describe('when retrieve authentication methods succeeded', () => {
it('should return a RETRIEVE_AUTH_METHODS_SUCCESS action in response to a RETRIEVE_AUTH_METHODS action', () => {
actions = hot('--a-', {a: {type: AuthActionTypes.RETRIEVE_AUTH_METHODS}});
const expected = cold('--b-', {b: new RetrieveAuthMethodsSuccessAction(authMethodsMock)});
expect(authEffects.retrieveMethods$).toBeObservable(expected);
});
});
describe('when retrieve authentication methods failed', () => {
it('should return a RETRIEVE_AUTH_METHODS_ERROR action in response to a RETRIEVE_AUTH_METHODS action', () => {
spyOn((authEffects as any).authService, 'retrieveAuthMethods').and.returnValue(observableThrow(''));
actions = hot('--a-', {a: {type: AuthActionTypes.RETRIEVE_AUTH_METHODS}});
const expected = cold('--b-', {b: new RetrieveAuthMethodsErrorAction()});
expect(authEffects.retrieveMethods$).toBeObservable(expected);
});
})
});
});