Only send version when needed for metadata too

This commit is contained in:
shamoon
2026-02-12 11:34:23 -08:00
parent 472021b803
commit e5d7abc8f9
2 changed files with 28 additions and 2 deletions

View File

@@ -1216,7 +1216,32 @@ describe('DocumentDetailComponent', () => {
const metadataSpy = jest.spyOn(documentService, 'getMetadata')
metadataSpy.mockReturnValue(of({ has_archive_version: true }))
initNormally()
expect(metadataSpy).toHaveBeenCalled()
expect(metadataSpy).toHaveBeenCalledWith(doc.id, null)
})
it('should pass metadata version only for non-latest selected versions', () => {
const metadataSpy = jest.spyOn(documentService, 'getMetadata')
metadataSpy.mockReturnValue(of({ has_archive_version: true }))
initNormally()
httpTestingController.expectOne(component.previewUrl).flush('preview')
expect(metadataSpy).toHaveBeenCalledWith(doc.id, null)
metadataSpy.mockClear()
component.document.versions = [
{ id: doc.id, is_root: true },
{ id: 10, is_root: false },
] as any
jest.spyOn(documentService, 'getPreviewUrl').mockReturnValue('preview-root')
jest.spyOn(documentService, 'getThumbUrl').mockReturnValue('thumb-root')
jest
.spyOn(documentService, 'get')
.mockReturnValue(of({ content: 'root' } as Document))
component.selectVersion(doc.id)
httpTestingController.expectOne('preview-root').flush('root')
expect(metadataSpy).toHaveBeenCalledWith(doc.id, doc.id)
})
it('should show an error if failed metadata retrieval', () => {

View File

@@ -379,8 +379,9 @@ export class DocumentDetailComponent
}
private loadMetadataForSelectedVersion() {
const selectedVersionId = this.getSelectedNonLatestVersionId()
this.documentsService
.getMetadata(this.documentId, this.selectedVersionId)
.getMetadata(this.documentId, selectedVersionId)
.pipe(
first(),
takeUntil(this.unsubscribeNotifier),