[ADF-5191] move reusable actions to testing package (#5842)

* [ADF-5191] move reusable actions to testing package

* * tenant added

* * improved logic

* fix circular deps error and warns

* fix unit test
This commit is contained in:
dhrn
2020-07-08 13:41:30 +05:30
committed by GitHub
parent 529aea77b1
commit d7dc6d7230
142 changed files with 777 additions and 467 deletions

View File

@@ -18,6 +18,7 @@
export * from './identity/public-api';
export * from './api.service';
export * from './drop.actions';
export * from './users.actions';
export * from './api';
export * from './api.util';
export * from './e2e-request-api.helper';

View File

@@ -0,0 +1,118 @@
/*!
* @license
* Copyright 2019 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 * as path from 'path';
import * as fs from 'fs';
import * as remote from 'selenium-webdriver/remote';
import { browser } from 'protractor';
import { ImageUploadRepresentation, UserRepresentation } from '@alfresco/js-api';
import { IdentityService } from './identity/identity.service';
import { UserModel } from '../models/user.model';
import { ApiService } from './api.service';
import { Logger } from '../utils/logger';
import { Tenant } from '../models/tenant';
export class UsersActions {
api: ApiService;
identityService: IdentityService;
constructor(alfrescoApi: ApiService) {
this.api = alfrescoApi;
if (this.api.apiService.isOauthConfiguration()) {
this.identityService = new IdentityService(this.api);
}
}
async createUser(userModel?: UserModel): Promise<UserModel> {
const user = new UserModel({ ...(userModel ? userModel : {}) });
try {
if (this.api.apiService.isEcmConfiguration() || (this.api.apiService.isEcmBpmConfiguration())) {
Logger.log('Create user ECM');
await this.api.apiService.core.peopleApi.addPerson({
id: user.email,
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
password: user.password
});
}
if (this.api.apiService.isBpmConfiguration() || (this.api.apiService.isEcmBpmConfiguration())) {
Logger.log('Create user BPM');
if (user.tenantId) {
const apsUser = await this.createApsUser(user.tenantId, user.email, user.firstName, user.lastName, user.password);
user.id = apsUser.id;
} else {
const apsUser = await this.createTenantAndUser(user.email, user.firstName, user.lastName, user.password);
user.tenantId = apsUser.tenantId;
user.id = apsUser.id;
}
}
if (this.api.apiService.isOauthConfiguration()) {
Logger.log('Create user identity');
const identityUser = await this.identityService.createIdentityUser(user);
user.idIdentityService = identityUser.idIdentityService;
}
} catch (e) {
Logger.error('Error create user' + JSON.stringify(e));
}
return user;
}
async createTenantAndUser(email?: string, firstName?: string, lastName?: string, password?: string): Promise<UserRepresentation> {
const newTenant = await this.api.apiService.activiti.adminTenantsApi.createTenant(new Tenant());
const user = new UserModel({
tenantId: newTenant.id,
email,
firstName,
lastName,
password
});
return this.api.apiService.activiti.adminUsersApi.createNewUser(user.getAPSModel());
}
async createApsUser(tenantId?: number, email?: string, firstName?: string, lastName?: string, password?: string): Promise<UserRepresentation> {
const user = new UserModel({
tenantId,
email,
firstName,
lastName,
password
});
return this.api.apiService.activiti.adminUsersApi.createNewUser(user.getAPSModel());
}
async changeProfilePictureAps(fileLocation: string): Promise<ImageUploadRepresentation> {
browser.setFileDetector(new remote.FileDetector());
const pathFile = path.join(browser.params.testConfig.main.rootPath + fileLocation);
const file = fs.createReadStream(pathFile);
return this.api.apiService.activiti.profileApi.uploadProfilePicture(file);
}
}

View File

@@ -17,3 +17,4 @@
export * from './user.model';
export * from './application-model';
export * from './tenant';

View File

@@ -0,0 +1,38 @@
/*!
* @license
* Copyright 2019 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 { StringUtil } from '../utils/string.util';
/**
* Create tenant JSON Object
*
* @param details - JSON object used to overwrite the default values
* @constructor
*/
export class Tenant {
active = true;
configuration = 'DefaultConfig';
domain = 'DefaultDomain';
maxUsers = 10;
name = StringUtil.generateRandomString();
constructor(details?: any) {
Object.assign(this, details);
}
}

View File

@@ -28,8 +28,8 @@ export class UserModel {
username?: string;
idIdentityService?: string;
type = 'enterprise';
tenantId;
company;
tenantId?: number;
company?: string;
id: number;
constructor(details: any = {}) {

View File

@@ -17,7 +17,7 @@
import { BrowserActions } from '../utils/browser-actions';
import { element, by } from 'protractor';
import { BrowserVisibility } from '../public-api';
import { BrowserVisibility } from '../utils/browser-visibility';
export class ContextMenuPage {
contextMenu = element(by.id('adf-context-menu-content'));