mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-26 15:07:38 +00:00
68 lines
2.1 KiB
TypeScript
68 lines
2.1 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 { RemoteVersionService } from './remote-version.service'
|
|
|
|
let httpTestingController: HttpTestingController
|
|
let service: RemoteVersionService
|
|
let subscription: Subscription
|
|
const endpoint = 'remote_version'
|
|
|
|
describe('RemoteVersionService', () => {
|
|
beforeEach(() => {
|
|
TestBed.configureTestingModule({
|
|
imports: [],
|
|
providers: [
|
|
RemoteVersionService,
|
|
provideHttpClient(withInterceptorsFromDi()),
|
|
provideHttpClientTesting(),
|
|
],
|
|
})
|
|
|
|
httpTestingController = TestBed.inject(HttpTestingController)
|
|
service = TestBed.inject(RemoteVersionService)
|
|
})
|
|
|
|
afterEach(() => {
|
|
subscription?.unsubscribe()
|
|
httpTestingController.verify()
|
|
})
|
|
|
|
it('should call correct api endpoint on update check', () => {
|
|
subscription = service.checkForUpdates().subscribe()
|
|
const req = httpTestingController.expectOne(
|
|
`${environment.apiBaseUrl}${endpoint}/`
|
|
)
|
|
expect(req.request.method).toEqual('GET')
|
|
})
|
|
|
|
it('should call release notes endpoint without since', () => {
|
|
subscription = service.getReleaseNotes().subscribe()
|
|
const req = httpTestingController.expectOne(
|
|
`${environment.apiBaseUrl}release_notes/`
|
|
)
|
|
expect(req.request.method).toEqual('GET')
|
|
expect(req.request.params.has('since')).toBe(false)
|
|
})
|
|
|
|
it('should pass since to release notes endpoint', () => {
|
|
subscription = service.getReleaseNotes('3.4.2').subscribe()
|
|
const req = httpTestingController.expectOne(
|
|
`${environment.apiBaseUrl}release_notes/?since=3.4.2`
|
|
)
|
|
expect(req.request.method).toEqual('GET')
|
|
})
|
|
|
|
it('should pass until to release notes endpoint', () => {
|
|
subscription = service.getReleaseNotes('3.5.1', '3.6.0').subscribe()
|
|
httpTestingController.expectOne(
|
|
`${environment.apiBaseUrl}release_notes/?since=3.5.1&until=3.6.0`
|
|
)
|
|
})
|
|
})
|