Skip to content

Commit

Permalink
Merge branch 'main' into update-user
Browse files Browse the repository at this point in the history
  • Loading branch information
auumgn committed Feb 7, 2024
2 parents 0f68970 + d5a6ccf commit 40005c8
Show file tree
Hide file tree
Showing 19 changed files with 5,703 additions and 959 deletions.
4 changes: 3 additions & 1 deletion ui/src/app/account/account.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { SettingsComponent } from './settings/settings.component'
import { SharedModule } from '../shared/shared.module'
import { PasswordComponent } from './password/password.component'
import { PasswordStrengthComponent } from './password/password-strength.component';
import { PasswordResetFinishComponent } from './password/password-reset-finish.component'
import { PasswordResetFinishComponent } from './password/password-reset-finish.component';
import { ActivationComponent } from './activation/activation.component'

@NgModule({
declarations: [
Expand All @@ -19,6 +20,7 @@ import { PasswordResetFinishComponent } from './password/password-reset-finish.c
PasswordComponent,
PasswordStrengthComponent,
PasswordResetFinishComponent,
ActivationComponent,
],
imports: [SharedModule, CommonModule, ReactiveFormsModule, RouterModule.forChild(routes)],
})
Expand Down
13 changes: 11 additions & 2 deletions ui/src/app/account/account.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SettingsComponent } from './settings/settings.component'
import { AuthGuard } from './auth.guard'
import { PasswordComponent } from './password/password.component'
import { PasswordResetFinishComponent } from './password/password-reset-finish.component'
import { ActivationComponent } from './activation/activation.component'

export const routes: Routes = [
{
Expand All @@ -24,8 +25,8 @@ export const routes: Routes = [
component: PasswordResetFinishComponent,
data: {
authorities: [],
pageTitle: 'global.menu.account.password.string'
}
pageTitle: 'global.menu.account.password.string',
},
},
{
path: 'settings',
Expand All @@ -45,4 +46,12 @@ export const routes: Routes = [
},
canActivate: [AuthGuard],
},
{
path: 'activate',
component: ActivationComponent,
data: {
authorities: [],
pageTitle: 'activate.title.string',
},
},
]
12 changes: 12 additions & 0 deletions ui/src/app/account/activation/activate.route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Route } from '@angular/router'

import { ActivationComponent } from './activation.component'

export const activationRoute: Route = {
path: 'activate',
component: ActivationComponent,
data: {
authorities: [],
pageTitle: 'activate.title.string',
},
}
1 change: 1 addition & 0 deletions ui/src/app/account/activation/activation.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>activation works!</p>
Empty file.
55 changes: 55 additions & 0 deletions ui/src/app/account/activation/activation.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'

Check warning on line 1 in ui/src/app/account/activation/activation.component.spec.ts

View workflow job for this annotation

GitHub Actions / format

'fakeAsync' is defined but never used

Check warning on line 1 in ui/src/app/account/activation/activation.component.spec.ts

View workflow job for this annotation

GitHub Actions / format

'tick' is defined but never used

import { ActivationComponent } from './activation.component'
import { ActivationService } from './activation.service'
import { ActivatedRoute } from '@angular/router'
import { async, of, throwError } from 'rxjs'

Check warning on line 6 in ui/src/app/account/activation/activation.component.spec.ts

View workflow job for this annotation

GitHub Actions / format

'async' is defined but never used
import { RouterTestingModule } from '@angular/router/testing'

describe('ActivationComponent', () => {
let component: ActivationComponent
let fixture: ComponentFixture<ActivationComponent>
let activationServiceSpy: jasmine.SpyObj<ActivationService>

beforeEach(() => {
activationServiceSpy = jasmine.createSpyObj('ActivationService', ['get'])

TestBed.configureTestingModule({
declarations: [ActivationComponent],
imports: [RouterTestingModule],
providers: [{ provide: ActivationService, useValue: activationServiceSpy }],
}).compileComponents()

fixture = TestBed.createComponent(ActivationComponent)
component = fixture.componentInstance
fixture.detectChanges()

activationServiceSpy = TestBed.inject(ActivationService) as jasmine.SpyObj<ActivationService>
})

it('should create', () => {
expect(component).toBeTruthy()
})

it('non-error response from server when sending key should indicate success', () => {
activationServiceSpy.get.and.returnValue(of({}))
component.ngOnInit()
expect(component.success).toBeTruthy()
expect(component.error).toBeFalsy()
})

it('error response from server when sending key should indicate failure', () => {
activationServiceSpy.get.and.returnValue(throwError(() => new Error('error')))
component.ngOnInit()

expect(component.success).toBeFalsy()
expect(component.error).toBeTruthy()
})
})

export class MockActivatedRoute extends ActivatedRoute {
constructor() {
super()
this.queryParams = of({ key: 'key' })
}
}
38 changes: 38 additions & 0 deletions ui/src/app/account/activation/activation.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Component, OnInit } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import { ActivationService } from './activation.service'

@Component({
selector: 'app-activation',
templateUrl: './activation.component.html',
styleUrls: ['./activation.component.scss'],
})
export class ActivationComponent implements OnInit {
error: string | null = null
success: string | null = null

constructor(
private activationService: ActivationService,
private route: ActivatedRoute,
private router: Router
) {}

ngOnInit() {
this.route.queryParams.subscribe((params) => {
this.activationService.get(params['key']).subscribe({
next: () => {
this.error = null
this.success = 'OK'
},
error: () => {
this.success = null
this.error = 'ERROR'
},
})
})
}

login() {
this.router.navigate(['/login'])
}
}
14 changes: 14 additions & 0 deletions ui/src/app/account/activation/activation.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Injectable } from '@angular/core'
import { HttpClient, HttpParams } from '@angular/common/http'
import { Observable } from 'rxjs'

@Injectable({ providedIn: 'root' })
export class ActivationService {
constructor(private http: HttpClient) {}

get(key: string): Observable<any> {

Check warning on line 9 in ui/src/app/account/activation/activation.service.ts

View workflow job for this annotation

GitHub Actions / format

Unexpected any. Specify a different type
return this.http.get('/services/userservice/api/activate', {
params: new HttpParams().set('key', key),
})
}
}
Loading

0 comments on commit 40005c8

Please sign in to comment.