Commit 8a3c8b1b authored by Tifenn Guillas's avatar Tifenn Guillas

Add header comments => DONE, Add auth tests => DONE

parent 621c2ceb
/*
* This file is part of Anis Client.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
......
/*
* This file is part of Anis Client.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { NgModule } from '@angular/core';
import { KeycloakAngularModule } from 'keycloak-angular';
......
/*
* This file is part of Anis Client.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { APP_INITIALIZER } from '@angular/core';
import { from } from 'rxjs';
import { KeycloakService, KeycloakEventType } from 'keycloak-angular';
import { Store } from '@ngrx/store';
import { from } from 'rxjs';
import { KeycloakService, KeycloakEventType } from 'keycloak-angular';
import * as keycloakActions from './store/auth.action';
import * as fromKeycloak from './store/auth.reducer';
......
import * as authActions from './auth.action';
import { UserProfile } from './user-profile.model';
describe('[Auth] Action', () => {
it('should create LoginAction', () => {
const action = new authActions.LoginAction();
expect(action.type).toEqual(authActions.LOGIN);
});
it('should create LogoutAction', () => {
const action = new authActions.LogoutAction();
expect(action.type).toEqual(authActions.LOGOUT);
});
it('should create AuthSuccessAction', () => {
const action = new authActions.AuthSuccessAction();
expect(action.type).toEqual(authActions.AUTH_SUCCESS);
});
it('should create LoadUserProfileSuccessAction', () => {
const userProfile: UserProfile = { id: 'toto@mail.com', username: 'toto' };
const action = new authActions.LoadUserProfileSuccessAction(userProfile);
expect(action.type).toEqual(authActions.LOAD_USER_PROFILE_SUCCESS);
expect(action.payload).toEqual(userProfile);
});
it('should create OpenEditProfileAction', () => {
const action = new authActions.OpenEditProfileAction();
expect(action.type).toEqual(authActions.OPEN_EDIT_PROFILE);
});
});
/*
* This file is part of Anis Client.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { Action } from '@ngrx/store';
import { UserProfile } from './user-profile.model';
......
/*
* This file is part of Anis Client.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { Injectable } from '@angular/core';
import { from } from 'rxjs';
import { switchMap, map, tap } from 'rxjs/operators';
......
import * as fromAuth from './auth.reducer';
import * as authActions from './auth.action';
import { UserProfile } from './user-profile.model';
describe('[Auth] Reducer', () => {
it('should return init state', () => {
const { initialState } = fromAuth;
const action = {} as authActions.Actions;
const state = fromAuth.reducer(undefined, action);
expect(state).toBe(initialState);
});
it('should set isAuthenticated to true', () => {
const { initialState } = fromAuth;
const action = new authActions.AuthSuccessAction();
const state = fromAuth.reducer(initialState, action);
expect(state.isAuthenticated).toBeTruthy();
expect(state.userProfile).toBeNull();
expect(state).not.toEqual(initialState);
});
it('should set userProfile', () => {
const userProfile: UserProfile = { id: 'toto@mail.com', username: 'toto' };
const { initialState } = fromAuth;
const action = new authActions.LoadUserProfileSuccessAction(userProfile);
const state = fromAuth.reducer(initialState, action);
expect(state.isAuthenticated).toBeFalsy();
expect(state.userProfile).toEqual(userProfile);
expect(state).not.toEqual(initialState);
});
it('should get isAuthenticated', () => {
const action = {} as authActions.Actions;
const state = fromAuth.reducer(undefined, action);
expect(fromAuth.isAuthenticated(state)).toBeFalsy();
});
it('should get userProfile', () => {
const action = {} as authActions.Actions;
const state = fromAuth.reducer(undefined, action);
expect(fromAuth.getUserProfile(state)).toBeNull();
});
});
/*
* This file is part of Anis Client.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import * as actions from './auth.action';
import { UserProfile } from './user-profile.model';
export interface State {
isAuthenticated: boolean;
userProfile: any;
userProfile: UserProfile;
}
export const initialState: State = {
......@@ -19,11 +29,9 @@ export function reducer(state: State = initialState, action: actions.Actions): S
};
case actions.LOAD_USER_PROFILE_SUCCESS:
const userProfile = action.payload;
return {
...state,
userProfile
userProfile: action.payload
}
default:
......
import * as authSelector from './auth.selector';
import * as fromAuth from './auth.reducer';
describe('[Auth] Selector', () => {
it('should get isAuthenticated', () => {
const state = { auth: { ...fromAuth.initialState }};
expect(authSelector.isAuthenticated(state)).toBeFalsy();
});
it('should get userProfile', () => {
const state = { auth: { ...fromAuth.initialState }};
expect(authSelector.getUserProfile(state)).toBeNull();
});
});
\ No newline at end of file
/*
* This file is part of Anis Client.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { createSelector, createFeatureSelector } from '@ngrx/store';
import * as auth from './auth.reducer';
......
/*
* This file is part of Anis Client.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
export interface UserProfile {
id?: string;
username?: string;
......
/*
* This file is part of Anis Client.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
.dropdown-up {
top: 80% !important;
right: 5px !important;
......
/*
* This file is part of Anis Client.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { Instance } from '../../metamodel/model';
......
/*
* This file is part of Anis Client.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
main {
margin-top: 100px;
}
\ No newline at end of file
/*
* This file is part of Anis Client.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { Component, ViewEncapsulation, OnInit } from '@angular/core';
import { Store } from '@ngrx/store';
......
/*
* This file is part of Anis Client.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { Component, OnInit } from '@angular/core';
import { Store } from '@ngrx/store';
......
/*
* This file is part of Anis Client.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { NgModule } from '@angular/core';
import { SharedModule } from '../shared/shared.module';
......
/*
* This file is part of Anis Client.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment