Skip to content

Commit

Permalink
Adjusted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoff-kiefer committed Oct 18, 2023
1 parent 3994673 commit ad967b8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/modules/frontend/api/frontend.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('FrontendController', () => {

describe('Login', () => {
it('should not throw', () => {
const loginResponse: string = frontendController.login();
const loginResponse: Promise<string> = frontendController.login();

expect(loginResponse).toBe('Login!');
});
Expand Down
35 changes: 35 additions & 0 deletions src/modules/frontend/backend.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { BackendConfig } from '../../shared/config/BackendConfig.js';
import { ConfigService } from '@nestjs/config';
import { HttpService } from '@nestjs/axios';
import { UserParams } from '../ui-backend/api/user.params.js';
import { catchError, firstValueFrom, map } from 'rxjs';
import { AxiosError, AxiosResponse } from 'axios';
import { Injectable, UnauthorizedException } from '@nestjs/common';

@Injectable()
export class BackendService {
private backendConfig: BackendConfig;

private backendServerBasePath: string;

public constructor(configService: ConfigService, private httpService: HttpService) {
this.backendConfig = configService.getOrThrow<BackendConfig>('BACKEND');
this.backendServerBasePath = `http://${this.backendConfig.SERVER}:${this.backendConfig.PORT}`;
}

public login(userParams: UserParams): Promise<string> {
return firstValueFrom(
this.httpService
.post(`${this.backendServerBasePath}/api/login`, userParams)
.pipe(
catchError((e: AxiosError) => {
if ((e.status == 404)) {

Check warning on line 26 in src/modules/frontend/backend.service.ts

View workflow job for this annotation

GitHub Actions / nest_lint / Nest Lint

Replace `(e.status·==·404)` with `e.status·==·404`
throw new UnauthorizedException();
}
throw e;
}),
)
.pipe(map((v: AxiosResponse<string>) => v.data)),
);
}
}
1 change: 1 addition & 0 deletions src/modules/health/health.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('HealthController', () => {
BASE_URL: 'http://keycloak.test',
REALM_NAME: '',
CLIENT_ID: '',
SECRET: '',
};
let configService: DeepMocked<ConfigService>;

Expand Down
11 changes: 11 additions & 0 deletions src/shared/config/BackendConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {IsInt, IsNotEmpty, IsString, Min} from 'class-validator';

Check warning on line 1 in src/shared/config/BackendConfig.ts

View workflow job for this annotation

GitHub Actions / nest_lint / Nest Lint

Replace `IsInt,·IsNotEmpty,·IsString,·Min` with `·IsInt,·IsNotEmpty,·IsString,·Min·`

export class BackendConfig {
@IsString()
@IsNotEmpty()
public readonly SERVER!: string;

@IsInt()
@Min(1)
public readonly PORT!: number;
}
2 changes: 1 addition & 1 deletion src/shared/config/config.loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('configloader', () => {

const secrets: DeepPartial<JsonConfig> = {
DB: { SECRET: 'SuperSecretSecret' },
KEYCLOAK: { ADMIN_SECRET: 'ClientSecret' },
KEYCLOAK: { ADMIN_SECRET: 'AdminSecret', SECRET: 'ClientSecret' },
};

beforeAll(() => {
Expand Down

0 comments on commit ad967b8

Please sign in to comment.