renditions service test improvements

This commit is contained in:
Eugenio Romano
2016-10-12 10:20:31 +01:00
parent 3f662b9d40
commit a962512df0
11 changed files with 182 additions and 115 deletions

View File

@@ -60,6 +60,7 @@
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/router": "3.0.0",
"@angular/upgrade": "2.0.0",
"@types/node": "^6.0.42",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.12",

View File

@@ -27,7 +27,8 @@ import {
AlfrescoTranslationLoader,
AlfrescoTranslationService,
AlfrescoAuthenticationService,
AlfrescoContentService
AlfrescoContentService,
RenditionsService
} from './src/services/index';
import { MATERIAL_DESIGN_DIRECTIVES } from './src/components/material/index';
@@ -44,6 +45,7 @@ export const ALFRESCO_CORE_PROVIDERS: any[] = [
AlfrescoSettingsService,
AlfrescoTranslationLoader,
AlfrescoTranslationService,
RenditionsService,
...CONTEXT_MENU_PROVIDERS
];

View File

@@ -15,7 +15,6 @@
* limitations under the License.
*/
export class AlfrescoApiMock {
login(username: string, password: string) {

View File

@@ -0,0 +1,81 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export var fakeRedition = {
'entry': {
'id': 'pdf',
'content': {'mimeType': 'application/pdf', 'mimeTypeName': 'Adobe PDF Document'},
'status': 'NOT_CREATED'
}
};
export var fakeReditionCreated = {
'entry': {
'id': 'pdf',
'content': {'mimeType': 'application/pdf', 'mimeTypeName': 'Adobe PDF Document'},
'status': 'CREATED'
}
};
export var fakeReditionsList = {
'list': {
'pagination': {
'count': 6,
'hasMoreItems': false,
'totalItems': 6,
'skipCount': 0,
'maxItems': 100
},
'entries': [{
'entry': {
'id': 'avatar',
'content': {'mimeType': 'image/png', 'mimeTypeName': 'PNG Image'},
'status': 'NOT_CREATED'
}
}, {
'entry': {
'id': 'avatar32',
'content': {'mimeType': 'image/png', 'mimeTypeName': 'PNG Image'},
'status': 'NOT_CREATED'
}
}, {
'entry': {
'id': 'doclib',
'content': {'mimeType': 'image/png', 'mimeTypeName': 'PNG Image'},
'status': 'NOT_CREATED'
}
}, {
'entry': {
'id': 'imgpreview',
'content': {'mimeType': 'image/jpeg', 'mimeTypeName': 'JPEG Image'},
'status': 'NOT_CREATED'
}
}, {
'entry': {
'id': 'medium',
'content': {'mimeType': 'image/jpeg', 'mimeTypeName': 'JPEG Image'},
'status': 'NOT_CREATED'
}
}, {
'entry': {
'id': 'pdf',
'content': {'mimeType': 'application/pdf', 'mimeTypeName': 'Adobe PDF Document'},
'status': 'NOT_CREATED'
}
}]
}
};

View File

@@ -46,6 +46,4 @@ describe('AlfrescoSettingsService', () => {
service.bpmHost = address;
expect(service.bpmHost).toBe(address);
});
});

View File

@@ -18,6 +18,11 @@
import { ReflectiveInjector } from '@angular/core';
import { AlfrescoApiService } from './AlfrescoApi.service';
import { RenditionsService } from './renditions.service';
import {
fakeRedition,
fakeReditionCreated,
fakeReditionsList
} from '../assets/renditionsService.mock';
declare let jasmine: any;
declare let AlfrescoApi: any;
@@ -25,62 +30,6 @@ declare let AlfrescoApi: any;
describe('RenditionsService', () => {
let service, injector;
let fakeRedition = {
'entry': {
'id': 'pdf',
'content': {'mimeType': 'application/pdf', 'mimeTypeName': 'Adobe PDF Document'},
'status': 'NOT_CREATED'
}
};
let fakeReditionsList = {
'list': {
'pagination': {
'count': 6,
'hasMoreItems': false,
'totalItems': 6,
'skipCount': 0,
'maxItems': 100
},
'entries': [{
'entry': {
'id': 'avatar',
'content': {'mimeType': 'image/png', 'mimeTypeName': 'PNG Image'},
'status': 'NOT_CREATED'
}
}, {
'entry': {
'id': 'avatar32',
'content': {'mimeType': 'image/png', 'mimeTypeName': 'PNG Image'},
'status': 'NOT_CREATED'
}
}, {
'entry': {
'id': 'doclib',
'content': {'mimeType': 'image/png', 'mimeTypeName': 'PNG Image'},
'status': 'NOT_CREATED'
}
}, {
'entry': {
'id': 'imgpreview',
'content': {'mimeType': 'image/jpeg', 'mimeTypeName': 'JPEG Image'},
'status': 'NOT_CREATED'
}
}, {
'entry': {
'id': 'medium',
'content': {'mimeType': 'image/jpeg', 'mimeTypeName': 'JPEG Image'},
'status': 'NOT_CREATED'
}
}, {
'entry': {
'id': 'pdf',
'content': {'mimeType': 'application/pdf', 'mimeTypeName': 'Adobe PDF Document'},
'status': 'NOT_CREATED'
}
}]
}
};
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
AlfrescoApiService,
@@ -98,9 +47,9 @@ describe('RenditionsService', () => {
jasmine.Ajax.uninstall();
});
it('Get redition list service should call the server with the ID passed', (done) => {
it('Get redition list service should return the list', (done) => {
service.getRenditionsListByNodeId('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');
expect(res.list.entries[0].entry.id).toBe('avatar');
done();
});
@@ -111,34 +60,6 @@ describe('RenditionsService', () => {
});
});
it('Get redition service should call the server with the ID passed', (done) => {
service.getRendition('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/pdf');
expect(res.entry.status).toBe('NOT_CREATED');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeRedition)
});
});
it('isRenditionsAvailable service should call the server with the ID passed and return false if is not created', (done) => {
service.isRenditionAvailable('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/pdf');
expect(res).toBe(false);
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeRedition)
});
});
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');
@@ -165,5 +86,67 @@ describe('RenditionsService', () => {
responseText: 'error'
});
});
});
it('isConversionPossible should return true if is possible convert', (done) => {
service.isConversionPossible('fake-node-id', 'pdf').subscribe((res) => {
expect(res).toBe(true);
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeRedition)
});
});
it('isConversionPossible should return false if is not possible to convert', (done) => {
service.isConversionPossible('fake-node-id', 'pdf').subscribe((res) => {
expect(res).toBe(false);
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 403,
contentType: 'application/json'
});
});
it('isRenditionsAvailable should return true if the conversion exist', (done) => {
service.isRenditionAvailable('fake-node-id', 'pdf').subscribe((res) => {
expect(res).toBe(true);
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeReditionCreated)
});
});
it('isRenditionsAvailable should return false if the conversion not exist', (done) => {
service.isRenditionAvailable('fake-node-id', 'pdf').subscribe((res) => {
expect(res).toBe(false);
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeRedition)
});
});
it('isRenditionsAvailable should return false if the conversion get error', (done) => {
service.isRenditionAvailable('fake-node-id', 'pdf').subscribe((res) => {
expect(res).toBe(false);
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 400,
contentType: 'application/json'
});
});
});

View File

@@ -40,6 +40,21 @@ export class RenditionsService {
}
observer.next(isAvailable);
observer.complete();
}, () => {
observer.next(false);
observer.complete();
});
});
}
isConversionPossible(nodeId: string, encoding: string) {
return Observable.create((observer) => {
this.getRendition(nodeId, encoding).subscribe(() => {
observer.next(true);
observer.complete();
}, () => {
observer.next(false);
observer.complete();
});
});
}
@@ -55,7 +70,7 @@ export class RenditionsService {
}
createRendition(nodeId: string, encoding: string) {
return Observable.fromPromise(this.apiService.getInstance().core.renditionsApi.createRendition(nodeId, {id: 'pdf'}))
return Observable.fromPromise(this.apiService.getInstance().core.renditionsApi.createRendition(nodeId, {id: encoding}))
.catch(this.handleError);
}

View File

@@ -35,7 +35,7 @@
"no-arg": true,
"no-bitwise": false,
"no-conditional-assignment": true,
"no-consecutive-blank-lines": false,
"no-consecutive-blank-lines": true,
"no-console": [
true,
"debug",

View File

@@ -6,7 +6,7 @@
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"scripts": {
"clean": "rimraf dist node_modules",
"clean": "npm install rimraf && rimraf dist node_modules typings",
"build": "npm run tslint && rimraf dist && tsc && npm run copy-dist && license-check",
"build:w": "npm run tslint && rimraf dist && npm run watch-task",
"watch-task": "concurrently \"npm run tsc:w\" \"npm run copy-dist:w\" \"license-check\"",

View File

@@ -4,19 +4,19 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
for PACKAGE in \
ng2-activiti-analytics \
ng2-activiti-form \
ng2-activiti-processlist \
ng2-activiti-tasklist \
ng2-alfresco-core \
ng2-alfresco-datatable \
ng2-alfresco-documentlist \
ng2-activiti-form \
ng2-alfresco-login \
ng2-activiti-processlist \
ng2-alfresco-search \
ng2-activiti-tasklist \
ng2-alfresco-tag \
ng2-alfresco-upload \
ng2-alfresco-userinfo \
ng2-alfresco-viewer \
ng2-alfresco-webscript \
ng2-alfresco-userinfo
ng2-alfresco-webscript
do
echo "====== clean component: ${PACKAGE} ====="
cd "$DIR/../ng2-components/${PACKAGE}"

View File

@@ -56,27 +56,15 @@ npm link ng2-activiti-tasklist
npm link
npm run build
#LINK VIEWER
echo "====== linking component: ng2-alfresco-viewer ====="
cd "$DIR/../ng2-components/ng2-alfresco-viewer"
npm link ng2-alfresco-core
npm link
npm run build
#LINK TAG
echo "====== linking component: ng2-alfresco-tag ====="
cd "$DIR/../ng2-components/ng2-alfresco-tag"
npm link ng2-alfresco-core
npm link
npm run build
#LINK ALL THE OTHERS COMPONENTS
for PACKAGE in \
ng2-activiti-analytics \
ng2-alfresco-login \
ng2-alfresco-search \
ng2-alfresco-userinfo \
ng2-alfresco-upload \
ng2-activiti-analytics \
ng2-alfresco-userinfo
ng2-alfresco-tag \
ng2-alfresco-viewer
do
DESTDIR="$DIR/../ng2-components/${PACKAGE}"
echo "====== linking component: ${PACKAGE} ====="