[ADF-4371] Versioning - revert upload version on delete (#4572)

* revert upload version on delete

* methods return type
This commit is contained in:
Cilibiu Bogdan
2019-04-10 18:30:50 +03:00
committed by Denys Vuika
parent 1f6e868464
commit 8975d4b6a6
8 changed files with 300 additions and 65 deletions

View File

@@ -17,7 +17,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslationService, FileUploadStatus, NodesApiService, UploadService,
setupTestBed, CoreModule, AlfrescoApiService, AlfrescoApiServiceMock
setupTestBed, CoreModule, AlfrescoApiService, AlfrescoApiServiceMock, FileModel, FileUploadOptions
} from '@alfresco/adf-core';
import { of, throwError } from 'rxjs';
import { UploadModule } from '../upload.module';
@@ -30,6 +30,7 @@ describe('FileUploadingListComponent', () => {
let uploadService: UploadService;
let nodesApiService: NodesApiService;
let translateService: TranslationService;
let alfrescoApiService: AlfrescoApiService;
let file: any;
beforeEach(() => {
@@ -55,6 +56,7 @@ describe('FileUploadingListComponent', () => {
translateService = TestBed.get(TranslationService);
fixture = TestBed.createComponent(FileUploadingListComponent);
alfrescoApiService = TestBed.get(AlfrescoApiService);
component = fixture.componentInstance;
spyOn(translateService, 'get').and.returnValue(of('some error message'));
@@ -106,6 +108,30 @@ describe('FileUploadingListComponent', () => {
expect(uploadService.cancelUpload).toHaveBeenCalled();
});
it('should delete node version', () => {
spyOn(alfrescoApiService.versionsApi, 'deleteVersion').and.returnValue(of(file));
file = new FileModel(<File> { name: 'fake-name' });
file.options = <FileUploadOptions> { newVersion: true };
file.data = { entry: { id: 'nodeId', properties: { 'cm:versionLabel': '1' } } };
component.removeFile(file);
expect(alfrescoApiService.versionsApi.deleteVersion).toHaveBeenCalled();
});
it('should throw error when delete node version fails', (done) => {
spyOn(alfrescoApiService.versionsApi, 'deleteVersion').and.returnValue(throwError(file));
file = new FileModel(<File> { name: 'fake-name' });
file.options = <FileUploadOptions> { newVersion: true };
file.data = { entry: { id: 'nodeId', properties: { 'cm:versionLabel': '1' } } };
component.error.subscribe(() => {
done();
});
component.removeFile(file);
});
describe('Events', () => {
it('should throw an error event if delete file goes wrong', (done) => {