get and create renditions

This commit is contained in:
Eugenio Romano
2016-09-07 11:25:35 +02:00
parent 03933f4c04
commit f64883cc4b
2 changed files with 49 additions and 4 deletions

View File

@@ -16,7 +16,6 @@
*/
import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
import { EventEmitter } from '@angular/core';
import { RenditionsService } from './renditions.service';
import { AlfrescoSettingsService, AlfrescoApiService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
@@ -35,7 +34,7 @@ describe('RenditionsService', () => {
];
});
beforeEach( inject([RenditionsService, AlfrescoApiService], (renditionsService: RenditionsService, apiService: AlfrescoApiService) => {
beforeEach(inject([RenditionsService, AlfrescoApiService], (renditionsService: RenditionsService, apiService: AlfrescoApiService) => {
jasmine.Ajax.install();
service = renditionsService;
apiService.setInstance(new AlfrescoApi({}));
@@ -45,7 +44,41 @@ describe('RenditionsService', () => {
jasmine.Ajax.uninstall();
});
it('', (done) => {
it('Get redition service should call the server with the ID passed', (done) => {
service.getRenditionsByNodeId('fake-node-id').subscribe((res) => {
expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/renditions');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200,
contentType: 'application/json'
});
});
it('Create redition service should call the server with the ID passed and the asked encoding', (done) => {
service.createRendition('fake-node-id', 'pdf').subscribe((res) => {
expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/renditions');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200,
contentType: 'application/json'
});
});
it('Get redition service should catch the error', (done) => {
service.getRenditionsByNodeId('fake-node-id').subscribe((res) => {
}, (res) => {
done();
}
);
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 403,
contentType: 'application/json'
});
});
});

View File

@@ -16,6 +16,7 @@
*/
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { AlfrescoApiService } from 'ng2-alfresco-core';
/**
@@ -30,7 +31,18 @@ export class RenditionsService {
}
private getRenditionsByNodeId(nodeId: string) {
getRenditionsByNodeId(nodeId: string) {
return Observable.fromPromise(this.apiService.getInstance().core.renditionsApi.getRenditions(nodeId))
.catch(this.handleError);
}
createRendition(nodeId: string, encoding: string) {
return Observable.fromPromise(this.apiService.getInstance().core.renditionsApi.createRendition(nodeId, encoding))
.catch(this.handleError);
}
private handleError(error: any): Observable<any> {
console.error(error);
return Observable.throw(error || 'Server error');
}
}