Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: TT-155 resolve comments & fix user.selectors.spec
  • Loading branch information
thegreatyamori committed Mar 19, 2021
commit 872952eee59440b910a96d60cd26cdd1ccaf7339
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ testem.log
.keys.json
keys.ts
src/environments/keys.ts
debug.log

# System Files
.DS_Store
Expand Down
8 changes: 0 additions & 8 deletions debug.log

This file was deleted.

1 change: 0 additions & 1 deletion src/app/modules/shared/components/user/user.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { AzureAdB2CService } from '../../../login/services/azure.ad.b2c.service';


@Component({
selector: 'app-user',
templateUrl: './user.component.html',
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/user/models/user.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface User {
name: string;
email: string;
roles?: string[];
roles?: string[];
groups?: string[];
id: string;
tenant_id?: string;
Expand Down
7 changes: 3 additions & 4 deletions src/app/modules/user/services/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';
import { User } from '../models/user';

@Injectable({
providedIn: 'root',
Expand All @@ -14,8 +14,7 @@ export class UserService {

baseUrl = `${environment.timeTrackerApiUrl}/users`;

loadUser(userId): Observable<any> {
return this.http.get(`${this.baseUrl}/${userId}`);
loadUser(userId: string): Observable<User> {
return this.http.get<User>(`${this.baseUrl}/${userId}`);
}

}
18 changes: 9 additions & 9 deletions src/app/modules/user/store/user.reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { LoadUser, LoadUserFail, LoadUserSuccess } from './user.actions';
import { User } from '../models/user';

describe('userReducer', () => {
const initState = {
const initialState = {
name: '',
email: '',
roles: [],
groups: [],
}
};

it('on LoadUser, state equal to initState', () => {
it('on LoadUser, state equal to initialState', () => {
const userId = 'dummy_id_load';
const action = new LoadUser(userId);
const state = userReducer(initState, action);
const state = userReducer(initialState, action);

expect(state).toEqual(initState);
expect(state).toEqual(initialState);
});

it('on LoadUserSuccess, userFound is saved in store', () => {
Expand All @@ -30,15 +30,15 @@ describe('userReducer', () => {
};

const action = new LoadUserSuccess(userFound);
const state = userReducer(initState, action);
const state = userReducer(initialState, action);

expect(state).toEqual(userFound);
});

it('on LoadUserFail, state equal to initState', () => {
it('on LoadUserFail, state equal to initialState', () => {
const action = new LoadUserFail('error');
const state = userReducer(initState, action);
const state = userReducer(initialState, action);

expect(state).toEqual(initState);
expect(state).toEqual(initialState);
});
});
29 changes: 15 additions & 14 deletions src/app/modules/user/store/user.selectors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { getUserInfo } from './user.selectors';
import { getUserGroups, getUserInfo } from './user.selectors';
import { User } from '../models/user';

describe('UserSelectors', () => {
const userInfo: User = {
name: 'Unknown Name',
email: '[email protected]',
roles: [],
groups: [],
id: 'dummy_tenant_id_load',
tenant_id: null,
deleted: null
};
const userState: User = {
name: 'Unknown Name',
email: '[email protected]',
roles: [],
groups: [],
id: 'dummy_tenant_id_load',
tenant_id: null,
deleted: null,
};

it('should select user info', () => {
const result = getUserInfo.projector(userInfo);

expect(userInfo.email).toEqual('[email protected]');
it('should select user from store', () => {
expect(getUserInfo.projector(userState)).toEqual(userState);
});

it('should select user groups from store', () => {
expect(getUserGroups.projector(userState)).toEqual(userState.groups);
});
});