58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import { AuthRepository, AuthResponse } from '@app/domain/authentification/auth.repository';
|
|
import { Observable, of } from 'rxjs';
|
|
import { User } from '@app/domain/users/user.model';
|
|
import { LoginDto } from '@app/domain/authentification/dto/login-dto';
|
|
import { RegisterDto } from '@app/domain/authentification/dto/register-dto';
|
|
import { fakeUsers } from '@app/testing/user.mock';
|
|
|
|
export class FakeAuthRepository implements AuthRepository {
|
|
confirmPasswordReset(
|
|
resetToken: string,
|
|
newPassword: string,
|
|
confirmPassword: string
|
|
): Observable<boolean> {
|
|
return of(
|
|
resetToken === 'fakeToken' && newPassword === confirmPassword && fakeUsers[0].verified
|
|
);
|
|
}
|
|
|
|
get(): User | undefined {
|
|
return fakeUsers[0];
|
|
}
|
|
|
|
isAuthenticated(): boolean {
|
|
return fakeUsers[0] !== undefined;
|
|
}
|
|
|
|
isEmailVerified(): boolean {
|
|
return fakeUsers[0].verified;
|
|
}
|
|
|
|
login(loginDto: LoginDto): Observable<AuthResponse> {
|
|
const user = fakeUsers.find((u) => u.email === loginDto.email);
|
|
return of({ isValid: true, record: user, token: 'fakeToken' } as AuthResponse);
|
|
}
|
|
|
|
logout(): void {
|
|
fakeUsers.pop();
|
|
}
|
|
|
|
register(registerDto: RegisterDto): Observable<User> {
|
|
const user = {
|
|
...fakeUsers[0],
|
|
id: 'fakeId',
|
|
email: registerDto.email,
|
|
};
|
|
fakeUsers.push(user);
|
|
return of(user);
|
|
}
|
|
|
|
sendRequestPasswordReset(email: string): Observable<boolean> {
|
|
return of(fakeUsers[0].email === email);
|
|
}
|
|
|
|
sendVerificationEmail(email: string): Observable<boolean> {
|
|
return of(fakeUsers[0].email === email);
|
|
}
|
|
}
|