paperless-ngx/src-ui/src/app/services/rest/log.service.spec.ts
2024-12-13 00:45:20 -08:00

53 lines
1.5 KiB
TypeScript

import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'
import {
HttpTestingController,
provideHttpClientTesting,
} from '@angular/common/http/testing'
import { TestBed } from '@angular/core/testing'
import { Subscription } from 'rxjs'
import { environment } from 'src/environments/environment'
import { LogService } from './log.service'
let httpTestingController: HttpTestingController
let service: LogService
let subscription: Subscription
const endpoint = 'logs'
describe('LogService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [],
providers: [
LogService,
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(),
],
})
httpTestingController = TestBed.inject(HttpTestingController)
service = TestBed.inject(LogService)
})
afterEach(() => {
subscription?.unsubscribe()
httpTestingController.verify()
})
it('should call correct api endpoint on logs list', () => {
subscription = service.list().subscribe()
const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}${endpoint}/`
)
expect(req.request.method).toEqual('GET')
})
it('should call correct api endpoint on logs get', () => {
const id: string = 'mail'
subscription = service.get(id).subscribe()
const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}${endpoint}/${id}/`
)
expect(req.request.method).toEqual('GET')
})
})