-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f7f7dc
commit 59fb6a9
Showing
15 changed files
with
236 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ | |
}, | ||
"FRONTEND": { | ||
"PORT": 9091, | ||
"SESSION_SECRET": "DevelopmentSecret" | ||
"SESSION_SECRET": "DevelopmentSecret", | ||
"BACKEND_ADDRESS": "http://127.0.0.1:9090" | ||
}, | ||
"DB": { | ||
"CLIENT_URL": "postgres://admin:[email protected]:5432", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
src/modules/frontend/api/authentication.interceptor.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { AutoMap } from '@automapper/classes'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsString } from 'class-validator'; | ||
|
||
export class LoginParams { | ||
@AutoMap() | ||
@IsString() | ||
@ApiProperty({ name: 'username', required: true }) | ||
public readonly username!: string; | ||
|
||
@AutoMap() | ||
@IsString() | ||
@ApiProperty({ name: 'password', required: true }) | ||
public readonly password!: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import { HttpModule } from '@nestjs/axios'; | ||
import { Module } from '@nestjs/common'; | ||
import { AuthenticatedGuard } from './api/authentication.guard.js'; | ||
import { AuthenticationInterceptor } from './api/authentication.interceptor.js'; | ||
import { FrontendController } from './api/frontend.controller.js'; | ||
import { HttpModule } from '@nestjs/axios'; | ||
import { LoginService } from './outbound/login.service.js'; | ||
|
||
@Module({ | ||
imports: [HttpModule], | ||
providers: [], | ||
providers: [LoginService, AuthenticationInterceptor, AuthenticatedGuard], | ||
controllers: [FrontendController], | ||
}) | ||
export class FrontendApiModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { DeepMocked, createMock } from '@golevelup/ts-jest'; | ||
import { HttpService } from '@nestjs/axios'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
|
||
import { ConfigTestModule } from '../../../../test/utils/index.js'; | ||
import { LoginService } from './login.service.js'; | ||
|
||
describe('LoginService', () => { | ||
let module: TestingModule; | ||
let sut: LoginService; | ||
let httpService: DeepMocked<HttpService>; | ||
|
||
beforeAll(async () => { | ||
module = await Test.createTestingModule({ | ||
imports: [ConfigTestModule], | ||
providers: [LoginService, { provide: HttpService, useValue: createMock<HttpService>() }], | ||
}).compile(); | ||
|
||
sut = module.get(LoginService); | ||
httpService = module.get(HttpService); | ||
}); | ||
|
||
afterAll(async () => { | ||
await module.close(); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(sut).toBeDefined(); | ||
}); | ||
|
||
describe('login', () => { | ||
it('should call backend', () => { | ||
const username: string = faker.internet.userName(); | ||
const password: string = faker.internet.password(); | ||
|
||
sut.login(username, password); | ||
|
||
expect(httpService.post).toHaveBeenCalledWith(expect.stringContaining('/api/login'), { | ||
username, | ||
password, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { HttpService } from '@nestjs/axios'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { AxiosResponse } from 'axios'; | ||
import { TokenSet } from 'openid-client'; | ||
import { Observable } from 'rxjs'; | ||
import { FrontendConfig, ServerConfig } from '../../../shared/config/index.js'; | ||
|
||
@Injectable() | ||
export class LoginService { | ||
private backend: string; | ||
|
||
public constructor(private httpService: HttpService, config: ConfigService<ServerConfig>) { | ||
this.backend = config.getOrThrow<FrontendConfig>('FRONTEND').BACKEND_ADDRESS; | ||
} | ||
|
||
public login(username: string, password: string): Observable<AxiosResponse<TokenSet>> { | ||
return this.httpService.post<TokenSet>(`${this.backend}/api/login`, { username, password }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters