e2e tests

This commit is contained in:
Denys Vuika
2017-10-19 13:47:25 +01:00
parent aba476c15f
commit 7f12841e5a
45 changed files with 3213 additions and 26 deletions

View File

@@ -0,0 +1,34 @@
/*!
* @license
* Copyright 2017 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.
*/
import { browser } from 'protractor';
declare var window;
export class LocalStorageUtility {
static clear(): Promise<any> {
return browser.executeScript(() => {
return window.localStorage.clear();
});
}
static getTicket(): Promise<any> {
return browser.executeScript(() => {
return window.localStorage.getItem('ticket-ECM');
});
}
}

View File

@@ -0,0 +1,30 @@
/*!
* @license
* Copyright 2017 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 const NODE_TYPE_FILE = 'cm:content';
export const NODE_TYPE_FOLDER = 'cm:folder';
export const NODE_TITLE = 'cm:title';
export const NODE_DESCRIPTION = 'cm:description';
export class NodeBodyCreate {
constructor(
public name: string,
public nodeType: string,
public relativePath: string = '/',
public properties?: any[]
) {}
}

View File

@@ -0,0 +1,77 @@
/*!
* @license
* Copyright 2017 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.
*/
import { NodeBodyCreate, NODE_TYPE_FILE, NODE_TYPE_FOLDER, NODE_TITLE, NODE_DESCRIPTION } from './node-body-create';
export interface NodeContentTree {
name?: string;
files?: string[];
folders?: (string|NodeContentTree)[];
title?: string;
description?: string;
}
export function flattenNodeContentTree(content: NodeContentTree, relativePath: string = '/'): NodeBodyCreate[] {
const { name, files, folders, title, description } = content;
let data: NodeBodyCreate[] = [];
let properties: any;
properties = {
[NODE_TITLE]: title,
[NODE_DESCRIPTION]: description
};
if (name) {
data = data.concat([{
nodeType: NODE_TYPE_FOLDER,
name,
relativePath,
properties
}]);
relativePath = (relativePath === '/')
? `/${name}`
: `${relativePath}/${name}`;
}
if (folders) {
const foldersData: NodeBodyCreate[] = folders
.map((folder: (string|NodeContentTree)): NodeBodyCreate[] => {
const folderData: NodeContentTree = (typeof folder === 'string')
? { name: folder }
: folder;
return flattenNodeContentTree(folderData, relativePath);
})
.reduce((nodesData: NodeBodyCreate[], folderData: NodeBodyCreate[]) => nodesData.concat(folderData), []);
data = data.concat(foldersData);
}
if (files) {
const filesData: NodeBodyCreate[] = files
.map((filename: string): NodeBodyCreate => ({
nodeType: NODE_TYPE_FILE,
name: filename,
relativePath
}));
data = data.concat(filesData);
}
return data;
}

View File

@@ -0,0 +1,96 @@
/*!
* @license
* Copyright 2017 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.
*/
import { RepoApi } from '../repo-api';
import { NodeBodyCreate, NODE_TYPE_FILE, NODE_TYPE_FOLDER } from './node-body-create';
import { NodeContentTree, flattenNodeContentTree } from './node-content-tree';
export class NodesApi extends RepoApi {
// nodes
getNodeByPath(relativePath: string = '/'): Promise<any> {
return this
.get(`/nodes/-my-`, { parameters: { relativePath } })
.catch(this.handleError);
}
getNodeById(id: string): Promise<any> {
return this
.get(`/nodes/${id}`)
.catch(this.handleError);
}
deleteNodeById(id: string): Promise<any> {
return this
.delete(`/nodes/${id}`)
.catch(this.handleError);
}
deleteNodeByPath(path: string): Promise<any> {
return this
.getNodeByPath(path)
.then((response: any): string => response.data.entry.id)
.then((id: string): any => this.deleteNodeById(id))
.catch(this.handleError);
}
getNodeDescription(name: string): Promise<string> {
let description = 'cm:description';
return this
.getNodeByPath(name)
.then((response: any): string => response.data.entry.properties[description])
.catch(this.handleError);
}
deleteNodes(names: string[], relativePath: string = ''): Promise<any> {
const deletions = names
.map((name: string): any => {
return this.deleteNodeByPath(`${relativePath}/${name}`);
});
return Promise.all(deletions);
}
// children
getNodeChildren(nodeId: string): Promise<any> {
return this
.get(`/nodes/${nodeId}/children`)
.catch(this.handleError);
}
createChildren(data: NodeBodyCreate[]): Promise<any> {
return this
.post(`/nodes/-my-/children`, { data })
.catch(this.handleError);
}
createContent(content: NodeContentTree, relativePath: string = '/'): Promise<any> {
return this.createChildren(flattenNodeContentTree(content, relativePath));
}
createNodeWithProperties(name: string, title?: string, description?: string, relativePath: string = '/'): Promise<any> {
return this.createContent({ name, title, description }, relativePath);
}
createFolders(names: string[], relativePath: string = '/'): Promise<any> {
return this.createContent({ folders: names }, relativePath);
}
createFiles(names: string[], relativePath: string = '/'): Promise<any> {
return this.createContent({ files: names }, relativePath);
}
}

View File

@@ -0,0 +1,35 @@
/*!
* @license
* Copyright 2017 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 class Person {
id?: string;
password?: string;
firstName?: string;
lastName?: string;
email?: string;
properties?: any;
constructor(username: string, password: string, details: Person) {
this.id = username;
this.password = password || username;
this.firstName = username;
this.lastName = username;
this.email = `${username}@alfresco.com`;
Object.assign(this, details);
}
}

View File

@@ -0,0 +1,52 @@
/*!
* @license
* Copyright 2017 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.
*/
import { RepoApi } from '../repo-api';
import { Person } from './people-api-models';
export class PeopleApi extends RepoApi {
getUser(username: string) {
return this
.get(`/people/${username}`)
.catch(this.handleError);
}
updateUser(username: string, details?: Person): Promise<any> {
if (details.id) {
delete details.id;
}
return this
.put(`/people/${username}`, { data: details })
.catch(this.handleError);
}
createUser(username: string, password: string, details?: Person): Promise<any> {
const person: Person = new Person(username, password, details);
const onSuccess = (response) => response;
const onError = (response) => {
return (response.statusCode === 409)
? Promise.resolve(this.updateUser(username, person))
: Promise.reject(response);
};
return this
.post(`/people`, { data: person })
.then(onSuccess, onError)
.catch(this.handleError);
}
}

View File

@@ -0,0 +1,63 @@
/*!
* @license
* Copyright 2017 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.
*/
import { RestClient, RestClientArgs, RestClientResponse } from '../../rest-client/rest-client';
import { RepoClientAuth, RepoClientConfig } from '../repo-client-models';
export abstract class RepoApi {
private client: RestClient;
private defaults: RepoClientConfig = new RepoClientConfig();
constructor(
auth: RepoClientAuth = new RepoClientAuth(),
private config?: RepoClientConfig
) {
const { username, password } = auth;
this.client = new RestClient(username, password);
}
private createEndpointUri(endpoint: string): string {
const { defaults, config } = this;
const { host, tenant } = Object.assign(defaults, config);
return `${host}/alfresco/api/${tenant}/public/alfresco/versions/1${endpoint}`;
}
protected handleError(response: RestClientResponse) {
const { request: { method, path, data }, data: error } = response;
console.log(`ERROR on ${method}\n${path}\n${data}`);
console.log(error);
}
protected get(endpoint: string, args: RestClientArgs = {}) {
return this.client.get(this.createEndpointUri(endpoint), args);
}
protected post(endpoint: string, args: RestClientArgs = {}) {
return this.client.post(this.createEndpointUri(endpoint), args);
}
protected put(endpoint: string, args: RestClientArgs = {}) {
return this.client.put(this.createEndpointUri(endpoint), args);
}
protected delete(endpoint: string, args: RestClientArgs = {}) {
return this.client.delete(this.createEndpointUri(endpoint), args);
}
}

View File

@@ -0,0 +1,34 @@
/*!
* @license
* Copyright 2017 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.
*/
import { SITE_VISIBILITY } from '../../../../configs';
export class Site {
title?: string;
visibility?: string = SITE_VISIBILITY.PUBLIC;
id?: string;
description?: string;
constructor(title: string, visibility: string, details: Site) {
this.title = title;
this.visibility = visibility;
this.id = title;
this.description = `${title} description`;
Object.assign(this, details);
}
}

View File

@@ -0,0 +1,84 @@
/*!
* @license
* Copyright 2017 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.
*/
import { RepoApi } from '../repo-api';
import { Site } from './sites-api-models';
export class SitesApi extends RepoApi {
getSite(id: string) {
return this
.get(`/sites/${id}`)
.catch(this.handleError);
}
updateSite(id: string, details?: Site): Promise<any> {
if (details.id) {
delete details.id;
}
return this
.put(`/sites/${id}`, { data: details })
.catch(this.handleError);
}
createSite(title: string, visibility: string, details?: Site): Promise<any> {
const site: Site = new Site(title, visibility, details);
const onSuccess = (response) => response;
const onError = (response) => {
return (response.statusCode === 409)
? Promise.resolve(this.updateSite(site.id, site))
: Promise.reject(response);
};
return this
.post(`/sites`, { data: site })
.then(onSuccess, onError)
.catch(this.handleError);
}
deleteSite(id: string, permanent: boolean = true): Promise<any> {
return this
.delete(`/sites/${id}?permanent=${permanent}`)
.catch(this.handleError);
}
updateSiteMember(siteId: string, userId: string, role: string): Promise<any> {
return this
.put(`/sites/${siteId}/members/${userId}`, { data: { role } })
.catch(this.handleError);
}
addSiteMember(siteId: string, userId: string, role: string): Promise<any> {
const onSuccess = (response) => response;
const onError = (response) => {
return (response.statusCode === 409)
? Promise.resolve(this.updateSiteMember(siteId, userId, role))
: Promise.reject(response);
};
return this
.post(`/sites/${siteId}/members`, { data: { role, id: userId } })
.then(onSuccess, onError)
.catch(this.handleError);
}
deleteSiteMember(siteId: string, userId: string): Promise<any> {
return this
.delete(`/sites/${siteId}/members/${userId}`)
.catch(this.handleError);
}
}

View File

@@ -0,0 +1,38 @@
/*!
* @license
* Copyright 2017 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.
*/
import {
ADMIN_USERNAME,
ADMIN_PASSWORD,
REPO_API_HOST,
REPO_API_TENANT
} from '../../configs';
export class RepoClientAuth {
static DEFAULT_USERNAME: string = ADMIN_USERNAME;
static DEFAULT_PASSWORD: string = ADMIN_PASSWORD;
constructor(
public username: string = RepoClientAuth.DEFAULT_USERNAME,
public password: string = RepoClientAuth.DEFAULT_PASSWORD
) {}
}
export class RepoClientConfig {
host?: string = REPO_API_HOST;
tenant?: string = REPO_API_TENANT;
}

View File

@@ -0,0 +1,45 @@
/*!
* @license
* Copyright 2017 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.
*/
import { RepoClientAuth, RepoClientConfig } from './repo-client-models';
import { PeopleApi } from './apis/people/people-api';
import { NodesApi } from './apis/nodes/nodes-api';
import { SitesApi } from './apis/sites/sites-api';
export class RepoClient {
public people: PeopleApi = new PeopleApi(this.auth, this.config);
public nodes: NodesApi = new NodesApi(this.auth, this.config);
public sites: SitesApi = new SitesApi(this.auth, this.config);
// public favorites: FavoritesApi = new FavoritesApi(this.auth, this.config);
// public shared: SharedLinksApi = new SharedLinksApi(this.auth, this.config);
constructor(
private username: string = RepoClientAuth.DEFAULT_USERNAME,
private password: string = RepoClientAuth.DEFAULT_PASSWORD,
private config?: RepoClientConfig
) {}
private get auth(): RepoClientAuth {
const { username, password } = this;
return { username, password };
}
}
export * from './apis/nodes/node-body-create';
export * from './apis/nodes/node-content-tree';
export * from './apis/nodes/nodes-api';

View File

@@ -0,0 +1,71 @@
/*!
* @license
* Copyright 2017 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.
*/
/* tslint:disable */
const chalk = require('chalk');
/* tslint:enable */
export const log = {
i: 0,
get indentation(): string {
return new Array(this.i).fill(' ').join('');
},
indent() {
this.i++;
return this;
},
dedent() {
this.i--;
return this;
},
log(message: string = '', options: any = { ignoreIndentation: false }) {
const indentation = (!options.ignoreIndentation)
? this.indentation
: '';
console.log(`${indentation}${message}`);
return this;
},
blank() {
return this.log();
},
info(message: string = '', options: any = { bold: false, title: false }) {
const { bold } = options;
const style = (bold ? chalk.bold : chalk).gray;
return this.log(style(message), options);
},
success(message: string = '', options: any = { bold: false }) {
const style = options.bold ? chalk.bold.green : chalk.green;
return this.log(style(message), options);
},
error(message: string = '', options: any = { bold: false }) {
const style = options.bold ? chalk.bold.red : chalk.red;
return this.log(style(message), options);
}
};

View File

@@ -0,0 +1,82 @@
/*!
* @license
* Copyright 2017 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.
*/
import { log } from './console-logger';
const errors = [];
export const consoleReporter = {
jasmineStarted(suiteInfo) {
log.blank().info(
`Running ${suiteInfo.totalSpecsDefined} tests`,
{ bold: true, title: true }
).blank();
},
suiteStarted(suite) {
log.info(suite.description).indent();
},
specDone: (spec) => {
const {
status,
description,
failedExpectations
} = spec;
if (status === 'passed') {
log.success(`${description}`);
}
if (status === 'failed') {
log.error(`${description}`, { bold: true });
errors.push(spec);
failedExpectations.forEach((failed) => {
log.error(` ${failed.message}`);
});
}
},
suiteDone: (result) => {
log.dedent();
},
jasmineDone: (result) => {
if (!!errors.length) {
log .blank()
.blank()
.info(`${errors.length} failing tests`, { bold: true, title: true });
errors.forEach(error => {
log .blank()
.error(`${error.fullName}`, { bold: true });
error.failedExpectations.forEach(failed => {
log .info(`${failed.message}`)
.blank()
.error(`${failed.stack}`);
});
});
} else {
log.success(`All tests passed!`, { bold: true });
}
log.blank().blank();
}
};

View File

@@ -0,0 +1,55 @@
/*!
* @license
* Copyright 2017 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.
*/
interface RequestConfig {
timeout?: number;
noDelay?: boolean;
keepAlive?: boolean;
keepAliveDelay?: number;
}
interface ResponseConfig {
timeout?: number;
}
interface ResponseRequest {
method: string;
path: string;
data: string;
}
export interface NodeRestClient {
get(uri: string, callback: Function): Function;
post(uri: string, callback: Function): Function;
put(uri: string, callback: Function): Function;
delete(uri: string, callback: Function): Function;
}
export interface RestClientArgs {
data?: any;
parameters?: any;
headers?: any;
requestConfig?: RequestConfig;
responseConfig?: ResponseConfig;
}
export interface RestClientResponse {
request: ResponseRequest;
data: any;
statusMessage: string;
statusCode: number;
}

View File

@@ -0,0 +1,81 @@
/*!
* @license
* Copyright 2017 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.
*/
import { Client } from 'node-rest-client';
import { NodeRestClient, RestClientArgs, RestClientResponse } from './rest-client-models';
export * from './rest-client-models';
export class RestClient {
private static DEFAULT_HEADERS = {
'Content-Type': 'application/json',
'Accept': 'application/json'
};
private client: NodeRestClient;
constructor(user: string, password: string) {
this.client = <NodeRestClient>(new Client({ user, password }));
}
get(uri: string, args: RestClientArgs = {}): Promise<RestClientResponse> {
return this.promisify('get', uri, args);
}
post(uri: string, args: RestClientArgs = {}): Promise<RestClientResponse> {
return this.promisify('post', uri, args);
}
put(uri: string, args: RestClientArgs = {}): Promise<RestClientResponse> {
return this.promisify('put', uri, args);
}
delete(uri: string, args: RestClientArgs = {}): Promise<RestClientResponse> {
return this.promisify('delete', uri, args);
}
private createArgs(args: RestClientArgs = {}): RestClientArgs {
const data = JSON.stringify(args.data);
return Object.assign({}, RestClient.DEFAULT_HEADERS, args, { data });
}
private promisify(fnName: string, uri: string, args: RestClientArgs): Promise<RestClientResponse> {
const fn: Function = this.client[fnName];
const fnArgs = [ encodeURI(uri), this.createArgs(args) ];
return new Promise((resolve, reject) => {
const fnCallback = (data, rawResponse) => {
const {
statusCode, statusMessage,
req: { method, path }
} = rawResponse;
const response: RestClientResponse = {
data, statusCode, statusMessage,
request: { method, path, data: args.data }
};
(response.statusCode >= 400)
? reject(response)
: resolve(response);
};
fn(...fnArgs, fnCallback);
});
}
}