Skip to content
Snippets Groups Projects
Commit 9d2ec16f authored by hugcubi's avatar hugcubi
Browse files

Corrección de ciertos fallos en angular

parent ed81c7ff
Branches
Tags
1 merge request!36Develop
Showing
with 55 additions and 218 deletions
......@@ -20,16 +20,16 @@ lint:
disabled:
- git-diff-check
enabled:
- checkov@3.2.341
- checkov@3.2.344
- dotenv-linter@3.3.0
- hadolint@2.12.1-beta
- markdownlint@0.43.0
- osv-scanner@1.9.1
- osv-scanner@1.9.2
- prettier@3.4.2
- shellcheck@0.10.0
- shfmt@3.6.0
- svgo@3.3.2
- trufflehog@3.86.1
- trufflehog@3.88.0
- yamllint@1.35.1
actions:
disabled:
......
import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { ReactiveFormsModule } from '@angular/forms';
describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AppComponent, ReactiveFormsModule],
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
it(`should have the 'RestClient' title`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('RestClient');
});
it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, RestClient');
});
});
import { HotelListComponent } from './features/hotels/hotel-list/hotel-list.component';
import { BookingComponent } from './features/bookings/booking/booking.component';
import { HotelRegisterComponent } from './features/hotels/hotel-register/hotel-register.component';
import { MainPageComponent } from './features/users/main-page/main-page.component';
import { UserBookingListComponent } from './features/bookings/user-booking-list/user-booking-list.component';
import { UserFormComponent } from './features/users/user-form/user-form.component';
import { UnauthorizedComponent } from './page/unauthorized/unauthorized.component';
import { AppRoute, UserRolesArray } from './core/models';
import { AppRoute } from './core/models';
import { rolGuard, rolGuardChild } from '@core/guards';
export const routes: AppRoute[] = [
// Auth
{
......@@ -40,9 +33,9 @@ export const routes: AppRoute[] = [
path: 'unauthorized',
component: UnauthorizedComponent,
},
{
path: '**',
redirectTo: '/login',
pathMatch: 'full',
},
// {
// path: '**',
// redirectTo: '/login',
// pathMatch: 'full',
// },
];
import { TestBed } from '@angular/core/testing';
import { CanActivateFn } from '@angular/router';
import { rolGuard } from './rol.guard';
describe('rolGuard', () => {
const executeGuard: CanActivateFn = (...guardParameters) =>
TestBed.runInInjectionContext(() => rolGuard(...guardParameters));
beforeEach(() => {
TestBed.configureTestingModule({});
});
it('should be created', () => {
expect(executeGuard).toBeTruthy();
});
});
......@@ -36,21 +36,27 @@ function verifyRol(expectedRole: UserRol) {
router.navigate(['/login']);
return false;
}
if (!expectedRole) {
console.log('any rol required');
return true;
}
return sessionService.getSession().pipe(
map((session: Session | null) => {
if (!session) return false;
if (
Array.isArray(expectedRole) &&
(expectedRole as UserRol[]).includes(session.rol)
!(expectedRole as UserRol[]).includes(session.rol)
) {
console.log('Rol in Rol arry');
console.log('Rol in Rol array');
return true;
} else if (session.rol === expectedRole) {
console.log('Rol valido');
return true;
}
console.log('Unautorizado');
console.log('Unauthorized');
// Redirige si el usuario no tiene el rol necesario
router.navigate(['/unauthorized']);
......
import { TestBed } from '@angular/core/testing';
import { HttpInterceptorFn } from '@angular/common/http';
import { authInterceptor } from './auth.interceptor';
describe('authInterceptor', () => {
const interceptor: HttpInterceptorFn = (req, next) =>
TestBed.runInInjectionContext(() => authInterceptor(req, next));
beforeEach(() => {
TestBed.configureTestingModule({});
});
it('should be created', () => {
expect(interceptor).toBeTruthy();
});
});
......@@ -3,8 +3,8 @@ import { User } from './User.interface';
export interface Booking {
id: number;
startDate: Date;
endDate: Date;
start: Date;
end: Date;
userId: User;
roomId: Room;
}
import { Route } from '@angular/router';
import { UserRol } from './User.interface';
interface RouteData {
expectedRole: UserRol | UserRol[];
}
type RolledRoute = {
expectedRole?: UserRol | UserRol[];
};
export type AppRoute = Omit<Route, 'data'> & {
data?: RouteData;
export type AppRoute<T = {}> = Omit<Route, 'data'> & {
data?: RolledRoute & T;
};
import { TestBed } from '@angular/core/testing';
import { AuthClientService } from './auth-client.service';
import { Session } from '@core/models';
describe('AuthClientService', () => {
let service: AuthClientService;
let s: Session;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(AuthClientService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import { TestBed } from '@angular/core/testing';
import { BookingClientService } from './booking-client.service';
describe('BookingClientService', () => {
let service: BookingClientService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(BookingClientService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
......@@ -14,9 +14,9 @@ export class BookingClientService {
// Método para crear una nueva reserva
createBooking(bookingRequest: Booking): Observable<Booking> {
const { startDate, endDate } = bookingRequest;
const end = endDate.toISOString();
console.log({ bookingRequest, end });
const { start, end } = bookingRequest;
const endDate = end.toISOString();
console.log({ bookingRequest, end: endDate });
return this.http.post<Booking>(this.URI, bookingRequest);
}
......
import { TestBed } from '@angular/core/testing';
import { HotelClientService } from './hotel-client.service';
describe('HotelClientService', () => {
let service: HotelClientService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(HotelClientService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import { TestBed } from '@angular/core/testing';
import { UserClientService } from './user-client.service';
describe('UserClientService', () => {
let service: UserClientService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(UserClientService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import { TestBed } from '@angular/core/testing';
import { SessionService } from './session.service';
describe('SessionService', () => {
let service: SessionService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(SessionService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
......@@ -8,7 +8,7 @@ import { AuthClientService } from '../api/auth/auth-client.service';
import { Router } from '@angular/router';
interface JWTDecoded {
userId: number;
id: number;
rol: UserRol;
name: string;
email: string;
......@@ -41,7 +41,8 @@ export class SessionService {
private setSession(resp: any) {
const decoded = jwtDecode<JWTDecoded>(resp.token);
const user: Session = { ...decoded, id: decoded.userId };
const user: Session = { ...decoded };
console.log({ user, decoded, resp });
this.session$.next(user);
this.storage.save(this.tokenKey, { ...resp, session: user });
const mainPage = this.getMainPage(user.rol as UserRol);
......
import { TestBed } from '@angular/core/testing';
import { LocalStorageService } from './local-storage.service';
describe('LocalStorageService', () => {
let service: LocalStorageService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(LocalStorageService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
@NgModule({
declarations: [],
imports: [
CommonModule
]
})
export class AdminModule { }
import { AppRoute } from '@core/models';
import { UserFormComponent } from 'app/features/users';
import { UserFormRoute } from 'app/features/users/types/UserFormData';
export const AUTH_ROUTES: AppRoute[] = [
export const AUTH_ROUTES: UserFormRoute[] = [
{
path: 'login',
data: {
mode: {
formMode: 'LOGIN',
},
},
component: UserFormComponent,
},
{
path: 'register',
data: {
mode: {
formMode: 'REGISTER',
},
},
component: UserFormComponent,
},
];
export * from './auth.routes';
export * from './login/login.component';
export * from './register/register.component';
.container {
max-width: 600px;
margin-top: 2rem;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f9f9f9;
}
h2 {
text-align: center;
margin-bottom: 20px;
}
.form-group {
margin-bottom: 15px;
}
label {
font-weight: bold;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment