Prettier upgrade and e2e type checks (#1522)

* upgrade prettier

* noImplicitAny rule

* fix type

* update tsconfig

* upgrade to 150 print width
This commit is contained in:
Denys Vuika
2020-07-14 10:03:23 +01:00
committed by GitHub
parent 32793ea7b0
commit ddc6f36ab4
339 changed files with 5170 additions and 8763 deletions

View File

@@ -26,7 +26,7 @@
import { RepoApi } from '../repo-api';
export class AuthenticationApi extends RepoApi {
constructor(username?, password?) {
constructor(username?: string, password?: string) {
super(username, password);
}

View File

@@ -29,7 +29,7 @@ import { CommentsApi as AdfCommentsApi } from '@alfresco/js-api';
export class CommentsApi extends RepoApi {
commentsApi = new AdfCommentsApi(this.alfrescoJsApi);
constructor(username?, password?) {
constructor(username?: string, password?: string) {
super(username, password);
}
@@ -38,10 +38,7 @@ export class CommentsApi extends RepoApi {
await this.apiAuth();
return await this.commentsApi.listComments(nodeId);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeComments.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getNodeComments.name}`, error);
return null;
}
}
@@ -51,10 +48,7 @@ export class CommentsApi extends RepoApi {
await this.apiAuth();
return await this.commentsApi.createComment(nodeId, { content: comment });
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.addComment.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.addComment.name}`, error);
return null;
}
}
@@ -64,10 +58,7 @@ export class CommentsApi extends RepoApi {
await this.apiAuth();
return await this.commentsApi.createComment(nodeId, comment);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.addComments.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.addComments.name}`, error);
return null;
}
}

View File

@@ -27,17 +27,13 @@ import { RepoApi } from '../repo-api';
import { Logger } from '@alfresco/adf-testing';
import { RepoClient } from './../../repo-client';
import { Utils } from '../../../../utilities/utils';
import {
FavoritesApi as AdfFavoritesApi,
SitesApi as AdfSiteApi,
FavoriteEntry
} from '@alfresco/js-api';
import { FavoritesApi as AdfFavoritesApi, SitesApi as AdfSiteApi, FavoriteEntry } from '@alfresco/js-api';
export class FavoritesApi extends RepoApi {
favoritesApi = new AdfFavoritesApi(this.alfrescoJsApi);
sitesApi = new AdfSiteApi(this.alfrescoJsApi);
constructor(username?, password?) {
constructor(username?: string, password?: string) {
super(username, password);
}
@@ -53,18 +49,12 @@ export class FavoritesApi extends RepoApi {
};
return await this.favoritesApi.createFavorite('-me-', data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.addFavorite.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.addFavorite.name}`, error);
return null;
}
}
async addFavoriteById(
nodeType: 'file' | 'folder' | 'site',
id: string
): Promise<FavoriteEntry | null> {
async addFavoriteById(nodeType: 'file' | 'folder' | 'site', id: string): Promise<FavoriteEntry | null> {
let guid;
try {
await this.apiAuth();
@@ -82,10 +72,7 @@ export class FavoritesApi extends RepoApi {
};
return await this.favoritesApi.createFavorite('-me-', data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.addFavoriteById.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.addFavoriteById.name}`, error);
return null;
}
}
@@ -97,10 +84,7 @@ export class FavoritesApi extends RepoApi {
await this.addFavoriteById(nodeType, current);
}, Promise.resolve());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.addFavoritesByIds.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.addFavoritesByIds.name}`, error);
}
}
@@ -109,10 +93,7 @@ export class FavoritesApi extends RepoApi {
await this.apiAuth();
return await this.favoritesApi.listFavorites(this.getUsername());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getFavorites.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getFavorites.name}`, error);
return null;
}
}
@@ -122,24 +103,16 @@ export class FavoritesApi extends RepoApi {
await this.apiAuth();
return await this.favoritesApi.getFavorite('-me-', nodeId);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getFavoriteById.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getFavoriteById.name}`, error);
return null;
}
}
async isFavorite(nodeId: string) {
try {
return JSON.stringify((await this.getFavorites()).list.entries).includes(
nodeId
);
return JSON.stringify((await this.getFavorites()).list.entries).includes(nodeId);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.isFavorite.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.isFavorite.name}`, error);
return null;
}
}
@@ -167,10 +140,7 @@ export class FavoritesApi extends RepoApi {
await this.apiAuth();
return await this.favoritesApi.deleteFavorite('-me-', nodeId);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.removeFavoriteById.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.removeFavoriteById.name}`, error);
}
}
@@ -181,18 +151,14 @@ export class FavoritesApi extends RepoApi {
await this.removeFavoriteById(current);
}, Promise.resolve());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.removeFavoritesByIds.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.removeFavoritesByIds.name}`, error);
}
}
async waitForApi(data: { expect: number }) {
try {
const favoriteFiles = async () => {
const totalItems = (await this.getFavorites()).list.pagination
.totalItems;
const totalItems = (await this.getFavorites()).list.pagination.totalItems;
if (totalItems !== data.expect) {
return Promise.reject(totalItems);
} else {

View File

@@ -23,13 +23,7 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import {
NodeBodyCreate,
NODE_TYPE_FILE,
NODE_TYPE_FOLDER,
NODE_TITLE,
NODE_DESCRIPTION
} from './node-body-create';
import { NodeBodyCreate, NODE_TYPE_FILE, NODE_TYPE_FOLDER, NODE_TITLE, NODE_DESCRIPTION } from './node-body-create';
export interface NodeContentTree {
name?: string;
@@ -39,10 +33,7 @@ export interface NodeContentTree {
description?: string;
}
export function flattenNodeContentTree(
content: NodeContentTree,
relativePath: string = '/'
): NodeBodyCreate[] {
export function flattenNodeContentTree(content: NodeContentTree, relativePath: string = '/'): NodeBodyCreate[] {
const { name, files, folders, title, description } = content;
const aspectNames: string[] = ['cm:versionable'];
let data: NodeBodyCreate[] = [];
@@ -63,23 +54,17 @@ export function flattenNodeContentTree(
}
]);
relativePath =
relativePath === '/' ? `/${name}` : `${relativePath}/${name}`;
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;
const folderData: NodeContentTree = typeof folder === 'string' ? { name: folder } : folder;
return flattenNodeContentTree(folderData, relativePath);
})
.reduce(
(nodesData: NodeBodyCreate[], folderData: NodeBodyCreate[]) =>
nodesData.concat(folderData),
[]
);
.reduce((nodesData: NodeBodyCreate[], folderData: NodeBodyCreate[]) => nodesData.concat(folderData), []);
data = data.concat(foldersData);
}

View File

@@ -26,18 +26,13 @@
import { RepoApi } from '../repo-api';
import { NodeBodyCreate } from './node-body-create';
import { NodeContentTree, flattenNodeContentTree } from './node-content-tree';
import {
NodesApi as AdfNodeApi,
NodeBodyLock,
NodeEntry,
NodeChildAssociationPaging
} from '@alfresco/js-api';
import { NodesApi as AdfNodeApi, NodeBodyLock, NodeEntry, NodeChildAssociationPaging } from '@alfresco/js-api';
import { Utils } from '../../../../utilities/utils';
export class NodesApi extends RepoApi {
nodesApi = new AdfNodeApi(this.alfrescoJsApi);
constructor(username?, password?) {
constructor(username?: string, password?: string) {
super(username, password);
}
@@ -46,10 +41,7 @@ export class NodesApi extends RepoApi {
await this.apiAuth();
return await this.nodesApi.getNode('-my-', { relativePath });
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeByPath.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getNodeByPath.name}`, error);
return null;
}
}
@@ -60,10 +52,7 @@ export class NodesApi extends RepoApi {
const node = await this.nodesApi.getNode(id);
return node;
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeById.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getNodeById.name}`, error);
return null;
}
}
@@ -71,12 +60,9 @@ export class NodesApi extends RepoApi {
async getNodeIdFromParent(name: string, parentId: string): Promise<string> {
try {
const children = (await this.getNodeChildren(parentId)).list.entries;
return children.find(elem => elem.entry.name === name).entry.id || '';
return children.find((elem) => elem.entry.name === name).entry.id || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeIdFromParent.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getNodeIdFromParent.name}`, error);
return '';
}
}
@@ -84,16 +70,9 @@ export class NodesApi extends RepoApi {
async getNodeDescription(name: string, parentId: string): Promise<string> {
try {
const children = (await this.getNodeChildren(parentId)).list.entries;
return (
children.find(elem => elem.entry.name === name).entry.properties[
'cm:description'
] || ''
);
return children.find((elem) => elem.entry.name === name).entry.properties['cm:description'] || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeDescription.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getNodeDescription.name}`, error);
return '';
}
}
@@ -101,16 +80,9 @@ export class NodesApi extends RepoApi {
async getNodeTitle(name: string, parentId: string): Promise<string> {
try {
const children = (await this.getNodeChildren(parentId)).list.entries;
return (
children.find(elem => elem.entry.name === name).entry.properties[
'cm:title'
] || ''
);
return children.find((elem) => elem.entry.name === name).entry.properties['cm:title'] || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeTitle.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getNodeTitle.name}`, error);
return '';
}
}
@@ -120,10 +92,7 @@ export class NodesApi extends RepoApi {
const node = await this.getNodeById(nodeId);
return (node.entry.properties && node.entry.properties[property]) || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeProperty.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getNodeProperty.name}`, error);
return '';
}
}
@@ -133,10 +102,7 @@ export class NodesApi extends RepoApi {
const prop = await this.getNodeProperty(nodeId, 'cm:versionType');
return prop || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getFileVersionType.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getFileVersionType.name}`, error);
return '';
}
}
@@ -146,10 +112,7 @@ export class NodesApi extends RepoApi {
const prop = await this.getNodeProperty(nodeId, 'cm:versionLabel');
return prop || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getFileVersionLabel.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getFileVersionLabel.name}`, error);
return '';
}
}
@@ -159,26 +122,17 @@ export class NodesApi extends RepoApi {
const sharedId = await this.getNodeProperty(nodeId, 'qshare:sharedId');
return sharedId || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getSharedId.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getSharedId.name}`, error);
return '';
}
}
async getSharedExpiryDate(nodeId: string): Promise<string> {
try {
const expiryDate = await this.getNodeProperty(
nodeId,
'qshare:expiryDate'
);
const expiryDate = await this.getNodeProperty(nodeId, 'qshare:expiryDate');
return expiryDate || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getSharedExpiryDate.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getSharedExpiryDate.name}`, error);
return '';
}
}
@@ -188,10 +142,7 @@ export class NodesApi extends RepoApi {
const sharedId = await this.getSharedId(nodeId);
return sharedId !== '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.isFileShared.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.isFileShared.name}`, error);
return null;
}
}
@@ -201,69 +152,42 @@ export class NodesApi extends RepoApi {
await this.apiAuth();
await this.nodesApi.deleteNode(id, { permanent });
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteNodeById.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.deleteNodeById.name}`, error);
}
}
async deleteNodeByPath(
path: string,
permanent: boolean = true
): Promise<void> {
async deleteNodeByPath(path: string, permanent: boolean = true): Promise<void> {
try {
const id = (await this.getNodeByPath(path)).entry.id;
await this.deleteNodeById(id, permanent);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteNodeByPath.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.deleteNodeByPath.name}`, error);
}
}
async deleteNodes(
names: string[],
relativePath: string = '',
permanent: boolean = true
): Promise<void> {
async deleteNodes(names: string[], relativePath: string = '', permanent: boolean = true): Promise<void> {
try {
await names.reduce(async (previous, current) => {
await previous;
const req = await this.deleteNodeByPath(
`${relativePath}/${current}`,
permanent
);
const req = await this.deleteNodeByPath(`${relativePath}/${current}`, permanent);
return req;
}, Promise.resolve());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteNodes.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.deleteNodes.name}`, error);
}
}
async deleteNodesById(
ids: string[],
permanent: boolean = true
): Promise<void> {
async deleteNodesById(ids: string[], permanent: boolean = true): Promise<void> {
try {
for (const id of ids) {
await this.deleteNodeById(id, permanent);
}
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteNodesById.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.deleteNodesById.name}`, error);
}
}
async getNodeChildren(
nodeId: string
): Promise<NodeChildAssociationPaging | null> {
async getNodeChildren(nodeId: string): Promise<NodeChildAssociationPaging | null> {
try {
const opts = {
include: ['properties']
@@ -271,61 +195,35 @@ export class NodesApi extends RepoApi {
await this.apiAuth();
return await this.nodesApi.listNodeChildren(nodeId, opts);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeChildren.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getNodeChildren.name}`, error);
return null;
}
}
async deleteNodeChildren(
parentId: string,
exceptNodesNamed?: string[]
): Promise<void> {
async deleteNodeChildren(parentId: string, exceptNodesNamed?: string[]): Promise<void> {
try {
const listEntries = (await this.getNodeChildren(parentId)).list.entries;
let nodeIds: string[];
if (exceptNodesNamed) {
nodeIds = listEntries
.filter(entries => !exceptNodesNamed.includes(entries.entry.name))
.map(entries => entries.entry.id);
nodeIds = listEntries.filter((entries) => !exceptNodesNamed.includes(entries.entry.name)).map((entries) => entries.entry.id);
} else {
nodeIds = listEntries.map(entries => entries.entry.id);
nodeIds = listEntries.map((entries) => entries.entry.id);
}
await this.deleteNodesById(nodeIds);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteNodeChildren.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.deleteNodeChildren.name}`, error);
}
}
async createImageNode(
name: string,
parentId: string = '-my-',
title: string = '',
description: string = ''
): Promise<NodeEntry | null> {
async createImageNode(name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<NodeEntry | null> {
const imageProps = {
'exif:pixelXDimension': 1000,
'exif:pixelYDimension': 1200
};
try {
return await this.createNode(
'cm:content',
name,
parentId,
title,
description,
imageProps
);
return await this.createNode('cm:content', name, parentId, title, description, imageProps);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createImageNode.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.createImageNode.name}`, error);
return null;
}
}
@@ -364,10 +262,7 @@ export class NodesApi extends RepoApi {
majorVersion
});
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createNode.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.createNode.name}`, error);
return null;
}
}
@@ -382,39 +277,18 @@ export class NodesApi extends RepoApi {
aspectNames: string[] = null
): Promise<NodeEntry> {
try {
return await this.createNode(
'cm:content',
name,
parentId,
title,
description,
null,
author,
majorVersion,
aspectNames
);
return await this.createNode('cm:content', name, parentId, title, description, null, author, majorVersion, aspectNames);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createFile.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.createFile.name}`, error);
return null;
}
}
async createImage(
name: string,
parentId: string = '-my-',
title: string = '',
description: string = ''
): Promise<NodeEntry | null> {
async createImage(name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<NodeEntry | null> {
try {
return await this.createImageNode(name, parentId, title, description);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createImage.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.createImage.name}`, error);
return null;
}
}
@@ -428,22 +302,9 @@ export class NodesApi extends RepoApi {
aspectNames: string[] = null
): Promise<NodeEntry | null> {
try {
return await this.createNode(
'cm:folder',
name,
parentId,
title,
description,
null,
author,
null,
aspectNames
);
return await this.createNode('cm:folder', name, parentId, title, description, null, author, null, aspectNames);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createFolder.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.createFolder.name}`, error);
return null;
}
}
@@ -453,54 +314,31 @@ export class NodesApi extends RepoApi {
await this.apiAuth();
return await this.nodesApi.createNode('-my-', data as any);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createChildren.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.createChildren.name}`, error);
}
}
async createContent(
content: NodeContentTree,
relativePath: string = '/'
): Promise<NodeEntry | any> {
async createContent(content: NodeContentTree, relativePath: string = '/'): Promise<NodeEntry | any> {
try {
return await this.createChildren(
flattenNodeContentTree(content, relativePath)
);
return await this.createChildren(flattenNodeContentTree(content, relativePath));
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createContent.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.createContent.name}`, error);
}
}
async createFolders(
names: string[],
relativePath: string = '/'
): Promise<NodeEntry | any> {
async createFolders(names: string[], relativePath: string = '/'): Promise<NodeEntry | any> {
try {
return await this.createContent({ folders: names }, relativePath);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createFolders.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.createFolders.name}`, error);
}
}
async createFiles(
names: string[],
relativePath: string = '/'
): Promise<NodeEntry | any> {
async createFiles(names: string[], relativePath: string = '/'): Promise<NodeEntry | any> {
try {
return await this.createContent({ files: names }, relativePath);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createFiles.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.createFiles.name}`, error);
}
}
@@ -509,18 +347,12 @@ export class NodesApi extends RepoApi {
await this.apiAuth();
return this.nodesApi.updateNode(nodeId, { aspectNames });
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.addAspects.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.addAspects.name}`, error);
return null;
}
}
async createFileLink(
originalNodeId: string,
destinationId: string
): Promise<NodeEntry | null> {
async createFileLink(originalNodeId: string, destinationId: string): Promise<NodeEntry | null> {
const name = (await this.getNodeById(originalNodeId)).entry.name;
const nodeBody = {
name: `Link to ${name}.url`,
@@ -536,18 +368,12 @@ export class NodesApi extends RepoApi {
await this.addAspects(originalNodeId, ['app:linked']);
return link;
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createFileLink.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.createFileLink.name}`, error);
return null;
}
}
async createFolderLink(
originalNodeId: string,
destinationId: string
): Promise<NodeEntry | null> {
async createFolderLink(originalNodeId: string, destinationId: string): Promise<NodeEntry | null> {
const name = (await this.getNodeById(originalNodeId)).entry.name;
const nodeBody = {
name: `Link to ${name}.url`,
@@ -566,10 +392,7 @@ export class NodesApi extends RepoApi {
await this.addAspects(originalNodeId, ['app:linked']);
return link;
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createFolderLink.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.createFolderLink.name}`, error);
return null;
}
}
@@ -580,25 +403,16 @@ export class NodesApi extends RepoApi {
await this.apiAuth();
return await this.nodesApi.getNodeContent(nodeId);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeContent.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getNodeContent.name}`, error);
}
}
async editNodeContent(
nodeId: string,
content: string
): Promise<NodeEntry | null> {
async editNodeContent(nodeId: string, content: string): Promise<NodeEntry | null> {
try {
await this.apiAuth();
return await this.nodesApi.updateNodeContent(nodeId, content);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.editNodeContent.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.editNodeContent.name}`, error);
return null;
}
}
@@ -608,19 +422,13 @@ export class NodesApi extends RepoApi {
await this.apiAuth();
return this.nodesApi.updateNode(nodeId, { name: newName });
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.renameNode.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.renameNode.name}`, error);
return null;
}
}
// node permissions
async setInheritPermissions(
nodeId: string,
inheritPermissions: boolean
): Promise<NodeEntry | null> {
async setInheritPermissions(nodeId: string, inheritPermissions: boolean): Promise<NodeEntry | null> {
const data = {
permissions: {
isInheritanceEnabled: inheritPermissions
@@ -631,20 +439,12 @@ export class NodesApi extends RepoApi {
await this.apiAuth();
return await this.nodesApi.updateNode(nodeId, data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.setGranularPermission.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.setGranularPermission.name}`, error);
return null;
}
}
async setGranularPermission(
nodeId: string,
inheritPermissions: boolean = false,
username: string,
role: string
): Promise<NodeEntry | null> {
async setGranularPermission(nodeId: string, inheritPermissions: boolean = false, username: string, role: string): Promise<NodeEntry | null> {
const data = {
permissions: {
isInheritanceEnabled: inheritPermissions,
@@ -661,19 +461,13 @@ export class NodesApi extends RepoApi {
await this.apiAuth();
return await this.nodesApi.updateNode(nodeId, data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.setGranularPermission.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.setGranularPermission.name}`, error);
return null;
}
}
// lock node
async lockFile(
nodeId: string,
lockType: string = 'ALLOW_OWNER_CHANGES'
): Promise<NodeEntry | null> {
async lockFile(nodeId: string, lockType: string = 'ALLOW_OWNER_CHANGES'): Promise<NodeEntry | null> {
const data = {
type: lockType
} as NodeBodyLock;
@@ -692,10 +486,7 @@ export class NodesApi extends RepoApi {
await this.apiAuth();
return await this.nodesApi.unlockNode(nodeId);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.unlockFile.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.unlockFile.name}`, error);
return null;
}
}
@@ -705,10 +496,7 @@ export class NodesApi extends RepoApi {
const lockType = await this.getNodeProperty(nodeId, 'cm:lockType');
return lockType || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getLockType.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getLockType.name}`, error);
return '';
}
}
@@ -718,10 +506,7 @@ export class NodesApi extends RepoApi {
const lockOwner = await this.getNodeProperty(nodeId, 'cm:lockOwner');
return lockOwner || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getLockOwner.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getLockOwner.name}`, error);
return '';
}
}
@@ -730,18 +515,12 @@ export class NodesApi extends RepoApi {
try {
return (await this.getLockType(nodeId)) === 'WRITE_LOCK';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.isFileLockedWrite.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.isFileLockedWrite.name}`, error);
return null;
}
}
async isFileLockedWriteWithRetry(
nodeId: string,
expect: boolean
): Promise<boolean> {
async isFileLockedWriteWithRetry(nodeId: string, expect: boolean): Promise<boolean> {
const data = {
expect: expect,
retry: 5
@@ -758,26 +537,17 @@ export class NodesApi extends RepoApi {
};
return await Utils.retryCall(locked, data.retry);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.isFileLockedWriteWithRetry.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.isFileLockedWriteWithRetry.name}`, error);
}
return isLocked;
}
async isFileLockedByName(
fileName: string,
parentId: string
): Promise<boolean> {
async isFileLockedByName(fileName: string, parentId: string): Promise<boolean> {
try {
const id = await this.getNodeIdFromParent(fileName, parentId);
return await this.isFileLockedWrite(id);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.isFileLockedByName.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.isFileLockedByName.name}`, error);
return null;
}
}

View File

@@ -40,10 +40,7 @@ export class PeopleApi extends RepoApi {
await this.apiAuth();
return await this.peopleApi.createPerson(person);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createUser.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.createUser.name}`, error);
return null;
}
}
@@ -63,10 +60,7 @@ export class PeopleApi extends RepoApi {
await this.apiAuth();
return this.peopleApi.updatePerson(username, userDetails);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.updateUser.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.updateUser.name}`, error);
return null;
}
}
@@ -75,10 +69,7 @@ export class PeopleApi extends RepoApi {
try {
return await this.updateUser(username, { enabled: false });
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.disableUser.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.disableUser.name}`, error);
return null;
}
}
@@ -87,10 +78,7 @@ export class PeopleApi extends RepoApi {
try {
return await this.updateUser(username, { password: newPassword });
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.changePassword.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.changePassword.name}`, error);
return null;
}
}

View File

@@ -45,10 +45,7 @@ export class QueriesApi extends RepoApi {
await this.apiAuth();
return this.queriesApi.findSites(searchTerm, data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.findSites.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.findSites.name}`, error);
return null;
}
}
@@ -63,10 +60,7 @@ export class QueriesApi extends RepoApi {
await this.apiAuth();
return this.queriesApi.findNodes(searchTerm, data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.findNodes.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.findNodes.name}`, error);
return null;
}
}
@@ -74,8 +68,7 @@ export class QueriesApi extends RepoApi {
async waitForSites(searchTerm: string, data: { expect: number }) {
try {
const sites = async () => {
const totalItems = (await this.findSites(searchTerm)).list.pagination
.totalItems;
const totalItems = (await this.findSites(searchTerm)).list.pagination.totalItems;
if (totalItems !== data.expect) {
return Promise.reject(totalItems);
} else {
@@ -85,9 +78,7 @@ export class QueriesApi extends RepoApi {
return await Utils.retryCall(sites);
} catch (error) {
Logger.error(
`${this.constructor.name} ${this.waitForSites.name} catch: `
);
Logger.error(`${this.constructor.name} ${this.waitForSites.name} catch: `);
Logger.error(`\tExpected: ${data.expect} items, but found ${error}`);
}
}
@@ -95,8 +86,7 @@ export class QueriesApi extends RepoApi {
async waitForFilesAndFolders(searchTerm: string, data: { expect: number }) {
try {
const nodes = async () => {
const totalItems = (await this.findNodes(searchTerm)).list.pagination
.totalItems;
const totalItems = (await this.findNodes(searchTerm)).list.pagination.totalItems;
if (totalItems !== data.expect) {
return Promise.reject(totalItems);
} else {
@@ -106,9 +96,7 @@ export class QueriesApi extends RepoApi {
return await Utils.retryCall(nodes);
} catch (error) {
Logger.error(
`${this.constructor.name} ${this.waitForFilesAndFolders.name} catch: `
);
Logger.error(`${this.constructor.name} ${this.waitForFilesAndFolders.name} catch: `);
Logger.error(`\tExpected: ${data.expect} items, but found ${error}`);
}
}

View File

@@ -30,10 +30,7 @@ import { Logger } from '@alfresco/adf-testing';
export abstract class RepoApi {
alfrescoJsApi = new AlfrescoApi();
constructor(
private username: string = browser.params.ADMIN_USERNAME,
private password: string = browser.params.ADMIN_PASSWORD
) {
constructor(private username: string = browser.params.ADMIN_USERNAME, private password: string = browser.params.ADMIN_PASSWORD) {
this.alfrescoJsApi.setConfig(browser.params.config);
}

View File

@@ -31,7 +31,7 @@ import { SearchApi as AdfSearchApi } from '@alfresco/js-api';
export class SearchApi extends RepoApi {
searchApi = new AdfSearchApi(this.alfrescoJsApi);
constructor(username?, password?) {
constructor(username?: string, password?: string) {
super(username, password);
}
@@ -52,10 +52,7 @@ export class SearchApi extends RepoApi {
await this.apiAuth();
return this.searchApi.search(data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.queryRecentFiles.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.queryRecentFiles.name}`, error);
return null;
}
}
@@ -73,10 +70,7 @@ export class SearchApi extends RepoApi {
await this.apiAuth();
return this.searchApi.search(data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.queryNodesNames.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.queryNodesNames.name}`, error);
return null;
}
}
@@ -94,10 +88,7 @@ export class SearchApi extends RepoApi {
await this.apiAuth();
return this.searchApi.search(data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.queryNodesExactNames.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.queryNodesExactNames.name}`, error);
return null;
}
}
@@ -105,8 +96,7 @@ export class SearchApi extends RepoApi {
async waitForApi(username: string, data: { expect: number }) {
try {
const recentFiles = async () => {
const totalItems = (await this.queryRecentFiles(username)).list
.pagination.totalItems;
const totalItems = (await this.queryRecentFiles(username)).list.pagination.totalItems;
if (totalItems !== data.expect) {
return Promise.reject(totalItems);
} else {
@@ -124,8 +114,7 @@ export class SearchApi extends RepoApi {
async waitForNodes(searchTerm: string, data: { expect: number }) {
try {
const nodes = async () => {
const totalItems = (await this.queryNodesNames(searchTerm)).list
.pagination.totalItems;
const totalItems = (await this.queryNodesNames(searchTerm)).list.pagination.totalItems;
if (totalItems !== data.expect) {
return Promise.reject(totalItems);
} else {
@@ -135,9 +124,7 @@ export class SearchApi extends RepoApi {
return await Utils.retryCall(nodes);
} catch (error) {
Logger.error(
`${this.constructor.name} ${this.waitForNodes.name} catch: `
);
Logger.error(`${this.constructor.name} ${this.waitForNodes.name} catch: `);
Logger.error(`\tExpected: ${data.expect} items, but found ${error}`);
}
}

View File

@@ -26,22 +26,16 @@
import { RepoApi } from '../repo-api';
import { Logger } from '@alfresco/adf-testing';
import { Utils } from '../../../../utilities/utils';
import {
SharedlinksApi as AdfSharedlinksApi,
SharedLinkEntry
} from '@alfresco/js-api';
import { SharedlinksApi as AdfSharedlinksApi, SharedLinkEntry } from '@alfresco/js-api';
export class SharedLinksApi extends RepoApi {
sharedlinksApi = new AdfSharedlinksApi(this.alfrescoJsApi);
constructor(username?, password?) {
constructor(username?: string, password?: string) {
super(username, password);
}
async shareFileById(
id: string,
expireDate?: Date
): Promise<SharedLinkEntry | null> {
async shareFileById(id: string, expireDate?: Date): Promise<SharedLinkEntry | null> {
try {
await this.apiAuth();
const data = {
@@ -50,10 +44,7 @@ export class SharedLinksApi extends RepoApi {
};
return await this.sharedlinksApi.createSharedLink(data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.shareFileById.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.shareFileById.name}`, error);
return null;
}
}
@@ -65,25 +56,17 @@ export class SharedLinksApi extends RepoApi {
return this.shareFileById(current);
}, Promise.resolve());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.shareFilesByIds.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.shareFilesByIds.name}`, error);
}
}
async getSharedIdOfNode(name: string) {
try {
const sharedLinks = (await this.getSharedLinks()).list.entries;
const found = sharedLinks.find(
sharedLink => sharedLink.entry.name === name
);
const found = sharedLinks.find((sharedLink) => sharedLink.entry.name === name);
return (found || { entry: { id: null } }).entry.id;
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getSharedIdOfNode.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getSharedIdOfNode.name}`, error);
return null;
}
}
@@ -93,10 +76,7 @@ export class SharedLinksApi extends RepoApi {
const id = await this.getSharedIdOfNode(name);
return await this.sharedlinksApi.deleteSharedLink(id);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.unshareFile.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.unshareFile.name}`, error);
}
}
@@ -105,10 +85,7 @@ export class SharedLinksApi extends RepoApi {
await this.apiAuth();
return await this.sharedlinksApi.listSharedLinks();
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getSharedLinks.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getSharedLinks.name}`, error);
return null;
}
}
@@ -116,8 +93,7 @@ export class SharedLinksApi extends RepoApi {
async waitForApi(data: { expect: number }) {
try {
const sharedFiles = async () => {
const totalItems = (await this.getSharedLinks()).list.pagination
.totalItems;
const totalItems = (await this.getSharedLinks()).list.pagination.totalItems;
if (totalItems !== data.expect) {
return Promise.reject(totalItems);
} else {

View File

@@ -40,7 +40,7 @@ import { Utils } from '../../../../utilities/utils';
export class SitesApi extends RepoApi {
sitesApi = new AdfSiteApi(this.alfrescoJsApi);
constructor(username?, password?) {
constructor(username?: string, password?: string) {
super(username, password);
}
@@ -57,9 +57,7 @@ export class SitesApi extends RepoApi {
async getSites() {
try {
await this.apiAuth();
return await this.sitesApi.listSiteMembershipsForPerson(
this.getUsername()
);
return await this.sitesApi.listSiteMembershipsForPerson(this.getUsername());
} catch (error) {
this.handleError(`${this.constructor.name} ${this.getSites.name}`, error);
return null;
@@ -69,13 +67,9 @@ export class SitesApi extends RepoApi {
async getDocLibId(siteId: string) {
try {
await this.apiAuth();
return (await this.sitesApi.listSiteContainers(siteId)).list.entries[0]
.entry.id;
return (await this.sitesApi.listSiteContainers(siteId)).list.entries[0].entry.id;
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getDocLibId.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getDocLibId.name}`, error);
return null;
}
}
@@ -85,10 +79,7 @@ export class SitesApi extends RepoApi {
const site = await this.getSite(siteId);
return site.entry.visibility;
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getVisibility.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getVisibility.name}`, error);
return null;
}
}
@@ -98,10 +89,7 @@ export class SitesApi extends RepoApi {
const site = await this.getSite(siteId);
return site.entry.description;
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getDescription.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getDescription.name}`, error);
return null;
}
}
@@ -116,12 +104,7 @@ export class SitesApi extends RepoApi {
}
}
async createSite(
title: string,
visibility?: string,
description?: string,
siteId?: string
): Promise<SiteEntry | null> {
async createSite(title: string, visibility?: string, description?: string, siteId?: string): Promise<SiteEntry | null> {
const site = {
title,
visibility: visibility || SITE_VISIBILITY.PUBLIC,
@@ -133,33 +116,17 @@ export class SitesApi extends RepoApi {
await this.apiAuth();
return await this.sitesApi.createSite(site);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createSite.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.createSite.name}`, error);
return null;
}
}
async createSitePrivate(
title: string,
description?: string,
siteId?: string
): Promise<SiteEntry> {
async createSitePrivate(title: string, description?: string, siteId?: string): Promise<SiteEntry> {
return this.createSite(title, SITE_VISIBILITY.PRIVATE, description, siteId);
}
async createSiteModerated(
title: string,
description?: string,
siteId?: string
): Promise<SiteEntry> {
return this.createSite(
title,
SITE_VISIBILITY.MODERATED,
description,
siteId
);
async createSiteModerated(title: string, description?: string, siteId?: string): Promise<SiteEntry> {
return this.createSite(title, SITE_VISIBILITY.MODERATED, description, siteId);
}
async createSites(titles: string[], visibility?: string): Promise<any> {
@@ -169,10 +136,7 @@ export class SitesApi extends RepoApi {
return this.createSite(current, visibility);
}, Promise.resolve());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createSites.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.createSites.name}`, error);
}
}
@@ -185,10 +149,7 @@ export class SitesApi extends RepoApi {
await this.apiAuth();
return await this.sitesApi.deleteSite(siteId, { permanent });
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteSite.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.deleteSite.name}`, error);
}
}
@@ -199,28 +160,20 @@ export class SitesApi extends RepoApi {
return this.deleteSite(current, permanent);
}, Promise.resolve());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteSites.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.deleteSites.name}`, error);
}
}
async deleteAllUserSites(permanent: boolean = true) {
try {
const siteIds = (await this.getSites()).list.entries.map(
entries => entries.entry.id
);
const siteIds = (await this.getSites()).list.entries.map((entries) => entries.entry.id);
return await siteIds.reduce(async (previous, current) => {
await previous;
return this.deleteSite(current, permanent);
}, Promise.resolve());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteAllUserSites.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.deleteAllUserSites.name}`, error);
}
}
@@ -233,10 +186,7 @@ export class SitesApi extends RepoApi {
await this.apiAuth();
return await this.sitesApi.updateSiteMembership(siteId, userId, siteRole);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.updateSiteMember.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.updateSiteMember.name}`, error);
return null;
}
}
@@ -251,43 +201,24 @@ export class SitesApi extends RepoApi {
await this.apiAuth();
return await this.sitesApi.createSiteMembership(siteId, memberBody);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.addSiteMember.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.addSiteMember.name}`, error);
return null;
}
}
async addSiteConsumer(
siteId: string,
userId: string
): Promise<SiteMemberEntry> {
async addSiteConsumer(siteId: string, userId: string): Promise<SiteMemberEntry> {
return this.addSiteMember(siteId, userId, SITE_ROLES.SITE_CONSUMER.ROLE);
}
async addSiteContributor(
siteId: string,
userId: string
): Promise<SiteMemberEntry> {
async addSiteContributor(siteId: string, userId: string): Promise<SiteMemberEntry> {
return this.addSiteMember(siteId, userId, SITE_ROLES.SITE_CONTRIBUTOR.ROLE);
}
async addSiteCollaborator(
siteId: string,
userId: string
): Promise<SiteMemberEntry> {
return this.addSiteMember(
siteId,
userId,
SITE_ROLES.SITE_COLLABORATOR.ROLE
);
async addSiteCollaborator(siteId: string, userId: string): Promise<SiteMemberEntry> {
return this.addSiteMember(siteId, userId, SITE_ROLES.SITE_COLLABORATOR.ROLE);
}
async addSiteManager(
siteId: string,
userId: string
): Promise<SiteMemberEntry> {
async addSiteManager(siteId: string, userId: string): Promise<SiteMemberEntry> {
return this.addSiteMember(siteId, userId, SITE_ROLES.SITE_MANAGER.ROLE);
}
@@ -296,31 +227,20 @@ export class SitesApi extends RepoApi {
await this.apiAuth();
return await this.sitesApi.deleteSiteMembership(siteId, userId);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteSiteMember.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.deleteSiteMember.name}`, error);
}
}
async requestToJoin(
siteId: string
): Promise<SiteMembershipRequestEntry | null> {
async requestToJoin(siteId: string): Promise<SiteMembershipRequestEntry | null> {
const body = {
id: siteId
};
try {
await this.apiAuth();
return await this.sitesApi.createSiteMembershipRequestForPerson(
'-me-',
body
);
return await this.sitesApi.createSiteMembershipRequestForPerson('-me-', body);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.requestToJoin.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.requestToJoin.name}`, error);
return null;
}
}
@@ -328,15 +248,10 @@ export class SitesApi extends RepoApi {
async hasMembershipRequest(siteId: string) {
try {
await this.apiAuth();
const requests = (
await this.sitesApi.getSiteMembershipRequests('-me-')
).list.entries.map(e => e.entry.id);
const requests = (await this.sitesApi.getSiteMembershipRequests('-me-')).list.entries.map((e) => e.entry.id);
return requests.includes(siteId);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.hasMembershipRequest.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.hasMembershipRequest.name}`, error);
return null;
}
}

View File

@@ -40,10 +40,7 @@ export class TrashcanApi extends RepoApi {
await this.apiAuth();
return await this.trashcanApi.deleteDeletedNode(id);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.permanentlyDelete.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.permanentlyDelete.name}`, error);
}
}
@@ -65,37 +62,28 @@ export class TrashcanApi extends RepoApi {
await this.apiAuth();
return await this.trashcanApi.listDeletedNodes(opts);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getDeletedNodes.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.getDeletedNodes.name}`, error);
return null;
}
}
async emptyTrash() {
try {
const ids = (await this.getDeletedNodes()).list.entries.map(
entries => entries.entry.id
);
const ids = (await this.getDeletedNodes()).list.entries.map((entries) => entries.entry.id);
return await ids.reduce(async (previous, current) => {
await previous;
return this.permanentlyDelete(current);
}, Promise.resolve());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.emptyTrash.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.emptyTrash.name}`, error);
}
}
async waitForApi(data: { expect: number }) {
try {
const deletedFiles = async () => {
const totalItems = (await this.getDeletedNodes()).list.pagination
.totalItems;
const totalItems = (await this.getDeletedNodes()).list.pagination.totalItems;
if (totalItems !== data.expect) {
return Promise.reject(totalItems);
} else {

View File

@@ -26,23 +26,20 @@
import { RepoApi } from '../repo-api';
import { UploadApi as AdfUploadApi } from '@alfresco/js-api';
import { browser } from 'protractor';
const fs = require('fs');
import * as fs from 'fs';
export class UploadApi extends RepoApi {
upload = new AdfUploadApi(this.alfrescoJsApi);
e2eRootPath = browser.params.e2eRootPath;
constructor(username?, password?) {
constructor(username?: string, password?: string) {
super(username, password);
}
async uploadFile(fileName: string, parentFolderId: string = '-my-') {
const file = fs.createReadStream(
`${this.e2eRootPath}/resources/test-files/${fileName}`
);
const file = fs.createReadStream(`${this.e2eRootPath}/resources/test-files/${fileName}`);
const opts = {
name: file.name,
name: fileName,
nodeType: 'cm:content'
};
@@ -50,23 +47,12 @@ export class UploadApi extends RepoApi {
await this.apiAuth();
return await this.upload.uploadFile(file, '', parentFolderId, null, opts);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.uploadFile.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.uploadFile.name}`, error);
}
}
async uploadFileWithRename(
fileName: string,
parentId: string = '-my-',
newName: string,
title: string = '',
description: string = ''
) {
const file = fs.createReadStream(
`${this.e2eRootPath}/resources/test-files/${fileName}`
);
async uploadFileWithRename(fileName: string, parentId: string = '-my-', newName: string, title: string = '', description: string = '') {
const file = fs.createReadStream(`${this.e2eRootPath}/resources/test-files/${fileName}`);
const nodeProps = {
properties: {
'cm:title': title,
@@ -83,10 +69,7 @@ export class UploadApi extends RepoApi {
await this.apiAuth();
return await this.upload.uploadFile(file, '', parentId, nodeProps, opts);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.uploadFileWithRename.name}`,
error
);
this.handleError(`${this.constructor.name} ${this.uploadFileWithRename.name}`, error);
}
}
}