mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-30 18:27:45 -05:00
Feature: update user profile (#4678)
This commit is contained in:
54
src-ui/src/app/services/profile.service.spec.ts
Normal file
54
src-ui/src/app/services/profile.service.spec.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
|
||||
import { ProfileService } from './profile.service'
|
||||
import {
|
||||
HttpClientTestingModule,
|
||||
HttpTestingController,
|
||||
} from '@angular/common/http/testing'
|
||||
import { environment } from 'src/environments/environment'
|
||||
|
||||
describe('ProfileService', () => {
|
||||
let httpTestingController: HttpTestingController
|
||||
let service: ProfileService
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ProfileService],
|
||||
imports: [HttpClientTestingModule],
|
||||
})
|
||||
|
||||
httpTestingController = TestBed.inject(HttpTestingController)
|
||||
service = TestBed.inject(ProfileService)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
httpTestingController.verify()
|
||||
})
|
||||
|
||||
it('calls get profile endpoint', () => {
|
||||
service.get().subscribe()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}profile/`
|
||||
)
|
||||
expect(req.request.method).toEqual('GET')
|
||||
})
|
||||
|
||||
it('calls patch on update', () => {
|
||||
service.update({ email: 'foo@bar.com' }).subscribe()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}profile/`
|
||||
)
|
||||
expect(req.request.method).toEqual('PATCH')
|
||||
expect(req.request.body).toEqual({
|
||||
email: 'foo@bar.com',
|
||||
})
|
||||
})
|
||||
|
||||
it('supports generating new auth token', () => {
|
||||
service.generateAuthToken().subscribe()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}profile/generate_auth_token/`
|
||||
)
|
||||
expect(req.request.method).toEqual('POST')
|
||||
})
|
||||
})
|
34
src-ui/src/app/services/profile.service.ts
Normal file
34
src-ui/src/app/services/profile.service.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { Observable } from 'rxjs'
|
||||
import { PaperlessUserProfile } from '../data/user-profile'
|
||||
import { environment } from 'src/environments/environment'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ProfileService {
|
||||
private endpoint = 'profile'
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
get(): Observable<PaperlessUserProfile> {
|
||||
return this.http.get<PaperlessUserProfile>(
|
||||
`${environment.apiBaseUrl}${this.endpoint}/`
|
||||
)
|
||||
}
|
||||
|
||||
update(profile: PaperlessUserProfile): Observable<PaperlessUserProfile> {
|
||||
return this.http.patch<PaperlessUserProfile>(
|
||||
`${environment.apiBaseUrl}${this.endpoint}/`,
|
||||
profile
|
||||
)
|
||||
}
|
||||
|
||||
generateAuthToken(): Observable<string> {
|
||||
return this.http.post<string>(
|
||||
`${environment.apiBaseUrl}${this.endpoint}/generate_auth_token/`,
|
||||
{}
|
||||
)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user