e2e improvements part2 (#1728)

* deprecate comments api wrapper, delete sites perf improve

* introduce user actions

* admin actions inherit user actions

* unlock nodes helper

* api improvements

* api improvements

* update code

* api improvements

* deprecate trashcan api wrapper

* shared api improvements
This commit is contained in:
Denys Vuika
2020-10-07 19:06:21 +01:00
committed by GitHub
parent ffa7ca3aa6
commit e9b837462a
35 changed files with 509 additions and 458 deletions

View File

@@ -23,26 +23,14 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { RepoClient } from './repo-client/repo-client';
import { PersonEntry, NodeEntry, PeopleApi } from '@alfresco/js-api';
import {
PersonModel,
SitesApi,
UploadApi,
NodesApi,
FavoritesApi,
SearchApi,
NodeContentTree,
Person,
SharedLinksApi,
TrashcanApi
} from './repo-client/apis';
export class AdminActions {
private adminApi: RepoClient;
import { PersonModel, SitesApi, UploadApi, NodesApi, FavoritesApi, SearchApi, NodeContentTree, Person, SharedLinksApi } from './repo-client/apis';
import { UserActions } from './user-actions';
import { browser } from 'protractor';
export class AdminActions extends UserActions {
constructor() {
this.adminApi = new RepoClient();
super();
}
sites: SitesApi = new SitesApi();
@@ -51,78 +39,81 @@ export class AdminActions {
favorites: FavoritesApi = new FavoritesApi();
search: SearchApi = new SearchApi();
shared: SharedLinksApi = new SharedLinksApi();
trashcan: TrashcanApi = new TrashcanApi();
async login(username?: string, password?: string) {
return super.login(username || browser.params.ADMIN_USERNAME, password || browser.params.ADMIN_PASSWORD);
}
async getDataDictionaryId(): Promise<string> {
return this.adminApi.nodes.getNodeIdFromParent('Data Dictionary', '-root-');
return this.nodes.getNodeIdFromParent('Data Dictionary', '-root-');
}
async getNodeTemplatesFolderId(): Promise<string> {
return this.adminApi.nodes.getNodeIdFromParent('Node Templates', await this.getDataDictionaryId());
return this.nodes.getNodeIdFromParent('Node Templates', await this.getDataDictionaryId());
}
async getSpaceTemplatesFolderId(): Promise<string> {
return this.adminApi.nodes.getNodeIdFromParent('Space Templates', await this.getDataDictionaryId());
return this.nodes.getNodeIdFromParent('Space Templates', await this.getDataDictionaryId());
}
async createUser(user: PersonModel): Promise<PersonEntry> {
const person = new Person(user);
const peopleApi = new PeopleApi(this.adminApi.alfrescoApi);
const peopleApi = new PeopleApi(this.alfrescoApi);
await this.adminApi.apiAuth();
await this.login();
return peopleApi.createPerson(person);
}
async disableUser(username: string): Promise<PersonEntry> {
const peopleApi = new PeopleApi(this.adminApi.alfrescoApi);
const peopleApi = new PeopleApi(this.alfrescoApi);
await this.adminApi.apiAuth();
await this.login();
return peopleApi.updatePerson(username, { enabled: false });
}
async changePassword(username: string, newPassword: string): Promise<PersonEntry> {
const peopleApi = new PeopleApi(this.adminApi.alfrescoApi);
const peopleApi = new PeopleApi(this.alfrescoApi);
await this.adminApi.apiAuth();
await this.login();
return peopleApi.updatePerson(username, { password: newPassword });
}
async createNodeTemplate(name: string, title: string = '', description: string = '', author: string = ''): Promise<NodeEntry> {
const templatesRootFolderId: string = await this.getNodeTemplatesFolderId();
return this.adminApi.nodes.createFile(name, templatesRootFolderId, title, description, author);
return this.nodes.createFile(name, templatesRootFolderId, title, description, author);
}
async createNodeTemplatesHierarchy(hierarchy: NodeContentTree): Promise<any> {
return this.adminApi.nodes.createContent(hierarchy, `Data Dictionary/Node Templates`);
return this.nodes.createContent(hierarchy, `Data Dictionary/Node Templates`);
}
async createSpaceTemplate(name: string, title: string = '', description: string = ''): Promise<NodeEntry> {
const templatesRootFolderId: string = await this.getSpaceTemplatesFolderId();
return this.adminApi.nodes.createFolder(name, templatesRootFolderId, title, description);
return this.nodes.createFolder(name, templatesRootFolderId, title, description);
}
async createSpaceTemplatesHierarchy(hierarchy: NodeContentTree): Promise<any> {
return this.adminApi.nodes.createContent(hierarchy, `Data Dictionary/Space Templates`);
return this.nodes.createContent(hierarchy, `Data Dictionary/Space Templates`);
}
async removeUserAccessOnNodeTemplate(nodeName: string): Promise<NodeEntry> {
const templatesRootFolderId = await this.getNodeTemplatesFolderId();
const nodeId: string = await this.adminApi.nodes.getNodeIdFromParent(nodeName, templatesRootFolderId);
const nodeId: string = await this.nodes.getNodeIdFromParent(nodeName, templatesRootFolderId);
return this.adminApi.nodes.setInheritPermissions(nodeId, false);
return this.nodes.setInheritPermissions(nodeId, false);
}
async removeUserAccessOnSpaceTemplate(nodeName: string): Promise<NodeEntry> {
const templatesRootFolderId = await this.getSpaceTemplatesFolderId();
const nodeId: string = await this.adminApi.nodes.getNodeIdFromParent(nodeName, templatesRootFolderId);
const nodeId: string = await this.nodes.getNodeIdFromParent(nodeName, templatesRootFolderId);
return this.adminApi.nodes.setInheritPermissions(nodeId, false);
return this.nodes.setInheritPermissions(nodeId, false);
}
async cleanupNodeTemplatesFolder(): Promise<void> {
return this.adminApi.nodes.deleteNodeChildren(await this.getNodeTemplatesFolderId());
return this.nodes.deleteNodeChildren(await this.getNodeTemplatesFolderId());
}
async cleanupSpaceTemplatesFolder(): Promise<void> {
@@ -130,14 +121,14 @@ export class AdminActions {
// folder links are deleted automatically when original folder is deleted
// Software Engineering Project is the default folder template coming from ACS, should not be deleted
const nodesToDelete = (await this.adminApi.nodes.getNodeChildren(spaceTemplatesNodeId)).list.entries
const nodesToDelete = (await this.nodes.getNodeChildren(spaceTemplatesNodeId)).list.entries
.filter((node) => node.entry.nodeType !== 'app:folderlink' && node.entry.name !== 'Software Engineering Project')
.map((node) => node.entry.id);
return this.adminApi.nodes.deleteNodesById(nodesToDelete);
return this.nodes.deleteNodesById(nodesToDelete);
}
async createLinkToFileId(originalFileId: string, destinationParentId: string): Promise<NodeEntry> {
return this.adminApi.nodes.createFileLink(originalFileId, destinationParentId);
return this.nodes.createFileLink(originalFileId, destinationParentId);
}
async createLinkToFileName(originalFileName: string, originalFileParentId: string, destinationParentId?: string): Promise<NodeEntry> {
@@ -145,13 +136,13 @@ export class AdminActions {
destinationParentId = originalFileParentId;
}
const nodeId = await this.adminApi.nodes.getNodeIdFromParent(originalFileName, originalFileParentId);
const nodeId = await this.nodes.getNodeIdFromParent(originalFileName, originalFileParentId);
return this.createLinkToFileId(nodeId, destinationParentId);
}
async createLinkToFolderId(originalFolderId: string, destinationParentId: string): Promise<NodeEntry> {
return this.adminApi.nodes.createFolderLink(originalFolderId, destinationParentId);
return this.nodes.createFolderLink(originalFolderId, destinationParentId);
}
async createLinkToFolderName(originalFolderName: string, originalFolderParentId: string, destinationParentId?: string): Promise<NodeEntry> {
@@ -159,7 +150,7 @@ export class AdminActions {
destinationParentId = originalFolderParentId;
}
const nodeId = await this.adminApi.nodes.getNodeIdFromParent(originalFolderName, originalFolderParentId);
const nodeId = await this.nodes.getNodeIdFromParent(originalFolderName, originalFolderParentId);
return this.createLinkToFolderId(nodeId, destinationParentId);
}

View File

@@ -26,5 +26,6 @@
export * from './repo-client/apis';
export * from './repo-client/repo-client';
export * from './admin-actions';
export * from './user-actions';
export * from './browser-utils';
export * from './utils';

View File

@@ -1,45 +0,0 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { RepoApi } from '../repo-api';
import { CommentsApi as AdfCommentsApi } from '@alfresco/js-api';
export class CommentsApi extends RepoApi {
commentsApi = new AdfCommentsApi(this.alfrescoJsApi);
constructor(username?: string, password?: string) {
super(username, password);
}
async addComment(nodeId: string, comment: string) {
try {
await this.apiAuth();
return await this.commentsApi.createComment(nodeId, { content: comment });
} catch (error) {
this.handleError(`${this.constructor.name} ${this.addComment.name}`, error);
return null;
}
}
}

View File

@@ -23,7 +23,6 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
export * from './comments/comments-api';
export * from './favorites/favorites-api';
export * from './nodes/node-body-create';
export * from './nodes/node-content-tree';
@@ -33,6 +32,5 @@ export * from './queries/queries-api';
export * from './search/search-api';
export * from './shared-links/shared-links-api';
export * from './sites/sites-api';
export * from './trashcan/trashcan-api';
export * from './upload/upload-api';
export * from './repo-api';

View File

@@ -480,6 +480,7 @@ export class NodesApi extends RepoApi {
}
}
/* @deprecated check {UserActions.unlockNodes} instead. */
async unlockFile(nodeId: string): Promise<NodeEntry | null> {
try {
await this.apiAuth();

View File

@@ -164,13 +164,12 @@ export class SitesApi extends RepoApi {
}
async deleteSites(siteIds: string[], permanent: boolean = true) {
try {
return siteIds.reduce(async (previous, current) => {
await previous;
return this.deleteSite(current, permanent);
}, Promise.resolve());
} catch (error) {
this.handleError(`SitesApi deleteSites : catch : `, error);
if (siteIds && siteIds.length > 0) {
await this.apiAuth();
for (const siteId of siteIds) {
await this.sitesApi.deleteSite(siteId, { permanent });
}
}
}

View File

@@ -1,113 +0,0 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { RepoApi } from '../repo-api';
import { Logger } from '@alfresco/adf-testing';
import { Utils } from '../../../../utilities/utils';
import { TrashcanApi as AdfTrashcanApi } from '@alfresco/js-api';
export class TrashcanApi extends RepoApi {
trashcanApi = new AdfTrashcanApi(this.alfrescoJsApi);
constructor(username?: string, password?: string) {
super(username, password);
}
async permanentlyDelete(id: string) {
try {
await this.apiAuth();
return await this.trashcanApi.deleteDeletedNode(id);
} catch (error) {
this.handleError(`TrashcanApi permanentlyDelete : catch : `, error);
}
}
async restore(id: string) {
try {
await this.apiAuth();
return await this.trashcanApi.restoreDeletedNode(id);
} catch (error) {
this.handleError(`TrashcanApi restore : catch : `, error);
return null;
}
}
async getDeletedNodes() {
const opts = {
maxItems: 1000
};
try {
await this.apiAuth();
return await this.trashcanApi.listDeletedNodes(opts);
} catch (error) {
this.handleError(`TrashcanApi getDeletedNodes : catch : `, error);
return null;
}
}
async getDeletedNodesTotalItems(): Promise<number> {
const opts = {
maxItems: 1000
};
try {
await this.apiAuth();
return (await this.trashcanApi.listDeletedNodes(opts)).list.pagination.totalItems;
} catch (error) {
this.handleError(`TrashcanApi getDeletedNodesTotalItems : catch : `, error);
return -1;
}
}
async emptyTrash() {
try {
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(`TrashcanApi emptyTrash : catch : `, error);
}
}
async waitForApi(data: { expect: number }) {
try {
const deletedFiles = async () => {
const totalItems = await this.getDeletedNodesTotalItems();
if (totalItems !== data.expect) {
return Promise.reject(totalItems);
} else {
return Promise.resolve(totalItems);
}
};
return await Utils.retryCall(deletedFiles);
} catch (error) {
Logger.error(`TrashcanApi waitForApi : catch : `);
Logger.error(`\tExpected: ${data.expect} items, but found ${error}`);
}
}
}

View File

@@ -24,9 +24,12 @@
*/
import { browser } from 'protractor';
import { NodesApi, CommentsApi, SitesApi, FavoritesApi, QueriesApi, SharedLinksApi, TrashcanApi, SearchApi, UploadApi } from './apis';
import { NodesApi, SitesApi, FavoritesApi, QueriesApi, SharedLinksApi, SearchApi, UploadApi } from './apis';
import { AlfrescoApi } from '@alfresco/js-api';
/**
* @deprecated Use {AdminActions} or {UserActions} instead.
*/
export class RepoClient {
alfrescoApi: AlfrescoApi;
@@ -43,10 +46,6 @@ export class RepoClient {
return new NodesApi(this.username, this.password);
}
get comments(): CommentsApi {
return new CommentsApi(this.username, this.password);
}
get sites(): SitesApi {
return new SitesApi(this.username, this.password);
}
@@ -59,10 +58,6 @@ export class RepoClient {
return new SharedLinksApi(this.username, this.password);
}
get trashcan(): TrashcanApi {
return new TrashcanApi(this.username, this.password);
}
get search(): SearchApi {
return new SearchApi(this.username, this.password);
}

View File

@@ -0,0 +1,165 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { AlfrescoApi, Comment, CommentsApi, NodesApi, TrashcanApi, SitesApi, SharedlinksApi } from '@alfresco/js-api';
import { browser } from 'protractor';
import { Utils } from './utils';
export class UserActions {
protected readonly alfrescoApi: AlfrescoApi;
readonly commentsApi: CommentsApi;
readonly nodesApi: NodesApi;
readonly trashcanApi: TrashcanApi;
readonly sitesApi: SitesApi;
readonly sharedLinksApi: SharedlinksApi;
protected username: string;
protected password: string;
constructor() {
this.alfrescoApi = new AlfrescoApi();
this.alfrescoApi.setConfig(browser.params.config);
this.commentsApi = new CommentsApi(this.alfrescoApi);
this.nodesApi = new NodesApi(this.alfrescoApi);
this.trashcanApi = new TrashcanApi(this.alfrescoApi);
this.sitesApi = new SitesApi(this.alfrescoApi);
this.sharedLinksApi = new SharedlinksApi(this.alfrescoApi);
}
async login(username: string, password: string) {
this.username = username || this.username;
this.password = password || this.password;
return this.alfrescoApi.login(this.username, this.password);
}
async logout(): Promise<any> {
await this.alfrescoApi.login(this.username, this.password);
return this.alfrescoApi.logout();
}
async createComment(nodeId: string, content: string): Promise<Comment> {
const comment = await this.commentsApi.createComment(nodeId, { content });
return comment?.entry;
}
/**
* Delete multiple nodes.
* @param nodeIds The list of node IDs to delete.
* @param permanent Delete permanently, without moving to the trashcan? (default: true)
*/
async deleteNodes(nodeIds: string[], permanent: boolean = true): Promise<any> {
for (const nodeId of nodeIds) {
await this.nodesApi.deleteNode(nodeId, { permanent });
}
}
/**
* Empties the trashcan. Uses multiple batches 1000 nodes each.
*/
async emptyTrashcan(): Promise<any> {
const nodes = await this.trashcanApi.listDeletedNodes({
maxItems: 1000
});
if (nodes?.list?.entries && nodes?.list?.entries?.length > 0) {
const ids = nodes.list.entries.map((entries) => entries.entry.id);
for (const nodeId of ids) {
await this.trashcanApi.deleteDeletedNode(nodeId);
}
await this.emptyTrashcan();
}
}
/**
* Returns the amount of deleted nodes in the trashcan.
* TODO: limited to 1000 items only, needs improvements.
*/
async getTrashcanSize(): Promise<number> {
const response = await this.trashcanApi.listDeletedNodes({
maxItems: 1000
});
return response?.list?.pagination?.totalItems || 0;
}
/**
* Performs multiple calls to retrieve the size of the trashcan until the expectedSize is reached.
* Used with eventual consistency calls.
* @param expectedSize Size of the trashcan to wait for.
*/
async waitForTrashcanSize(expectedSize: number): Promise<number> {
return Utils.retryCall(async () => {
const totalItems = await this.getTrashcanSize();
if (totalItems !== expectedSize) {
return Promise.reject(totalItems);
} else {
return Promise.resolve(totalItems);
}
});
}
/**
* Unlock multiple nodes.
* @param nodeIds The list of node IDs to unlock.
*/
async unlockNodes(nodeIds: string[]): Promise<any> {
for (const nodeId of nodeIds) {
await this.nodesApi.unlockNode(nodeId);
}
}
/**
* Delete multiple sites/libraries.
* @param siteIds The list of the site/library IDs to delete.
* @param permanent Delete permanently, without moving to the trashcan? (default: true)
*/
async deleteSites(siteIds: string[], permanent: boolean = true) {
if (siteIds && siteIds.length > 0) {
for (const siteId of siteIds) {
await this.sitesApi.deleteSite(siteId, { permanent });
}
}
}
/**
* Creates shared links for the given nodes.
* @param nodeIds The list of node IDs to share.
* @param expiresAt (optional) Expiration date.
*/
async shareNodes(nodeIds: string[], expiresAt?: Date): Promise<any> {
for (const nodeId of nodeIds) {
await this.sharedLinksApi.createSharedLink({
nodeId,
expiresAt
});
}
}
}