[MNT-24950] Preview a file from APS doesn't work in ADW (#11439)

This commit is contained in:
Mykyta Maliarchuk
2025-12-08 11:37:27 +01:00
committed by GitHub
parent 22baef7955
commit de62fe181a
2 changed files with 57 additions and 3 deletions

View File

@@ -198,4 +198,58 @@ describe('ProcessContentService', () => {
done();
});
});
describe('getContentPreview', () => {
it('should return preview rendition when available', (done) => {
const contentId = 999;
const fakeBlob = createFakeBlob();
spyOn(service.contentApi, 'getRawContent').and.returnValue(Promise.resolve(fakeBlob));
service.getContentPreview(contentId).subscribe((result) => {
expect(service.contentApi.getRawContent).toHaveBeenCalledWith(contentId, 'preview');
expect(service.contentApi.getRawContent).toHaveBeenCalledTimes(1);
expect(result).toEqual(fakeBlob);
done();
});
});
it('should fallback to raw content when preview fails', (done) => {
const contentId = 999;
const fakeBlob = createFakeBlob();
spyOn(service.contentApi, 'getRawContent').and.returnValues(
Promise.reject(new Error('Preview not available')),
Promise.resolve(fakeBlob)
);
service.getContentPreview(contentId).subscribe((result) => {
expect(service.contentApi.getRawContent).toHaveBeenCalledWith(contentId, 'preview');
expect(service.contentApi.getRawContent).toHaveBeenCalledWith(contentId);
expect(service.contentApi.getRawContent).toHaveBeenCalledTimes(2);
expect(result).toEqual(fakeBlob);
done();
});
});
it('should return error when both preview and raw content fail', (done) => {
const contentId = 999;
const errorMessage = 'Content not found';
spyOn(service.contentApi, 'getRawContent').and.returnValues(
Promise.reject(new Error('Preview not available')),
Promise.reject(new Error(errorMessage))
);
service.getContentPreview(contentId).subscribe({
next: () => {
fail('Should have thrown an error');
},
error: (error) => {
expect(service.contentApi.getRawContent).toHaveBeenCalledWith(contentId, 'preview');
expect(service.contentApi.getRawContent).toHaveBeenCalledWith(contentId);
expect(service.contentApi.getRawContent).toHaveBeenCalledTimes(2);
expect(error.message).toEqual(errorMessage);
done();
}
});
});
});
});

View File

@@ -79,7 +79,7 @@ export class ProcessContentService {
*/
getContentPreview(contentId: number): Observable<Blob> {
return new Observable((observer) => {
this.contentApi.getRawContent(contentId).then(
this.contentApi.getRawContent(contentId, 'preview').then(
(result) => {
observer.next(result);
observer.complete();
@@ -244,8 +244,8 @@ export class ProcessContentService {
errMsg = error.message
? error.message
: error.status
? `${error.status} - ${error.statusText}`
: ProcessContentService.GENERIC_ERROR_MESSAGE;
? `${error.status} - ${error.statusText}`
: ProcessContentService.GENERIC_ERROR_MESSAGE;
}
return throwError(errMsg);
}