playwright: updated entity spec with custom property test (#16621)

* playwright: updated entity spec with custom property test

* optimise the code

* fixed playwright failure

* addressing comment
This commit is contained in:
Shailesh Parmar 2024-06-12 18:51:40 +05:30 committed by GitHub
parent cc2d581eb0
commit af88b61aca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 71 additions and 8 deletions

View File

@ -11,6 +11,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { test } from '@playwright/test'; import { test } from '@playwright/test';
import { CustomPropertySupportedEntityList } from '../../constant/customProperty';
import { DatabaseClass } from '../../support/entity/DatabaseClass'; import { DatabaseClass } from '../../support/entity/DatabaseClass';
import { DatabaseSchemaClass } from '../../support/entity/DatabaseSchemaClass'; import { DatabaseSchemaClass } from '../../support/entity/DatabaseSchemaClass';
import { EntityDataClass } from '../../support/entity/EntityDataClass'; import { EntityDataClass } from '../../support/entity/EntityDataClass';
@ -27,6 +28,7 @@ import {
getToken, getToken,
redirectToHomePage, redirectToHomePage,
} from '../../utils/common'; } from '../../utils/common';
import { CustomPropertyTypeByName } from '../../utils/customProperty';
const entities = [ const entities = [
DatabaseServiceClass, DatabaseServiceClass,
@ -53,6 +55,7 @@ entities.forEach((EntityClass) => {
await EntityDataClass.preRequisitesForTests(apiContext); await EntityDataClass.preRequisitesForTests(apiContext);
await entity.create(apiContext); await entity.create(apiContext);
await entity.prepareForTests(apiContext);
await afterAction(); await afterAction();
}); });
@ -112,12 +115,44 @@ entities.forEach((EntityClass) => {
await entity.inactiveAnnouncement(page); await entity.inactiveAnnouncement(page);
}); });
// Create custom property only for supported entities
if (CustomPropertySupportedEntityList.includes(entity.endpoint)) {
const properties = Object.values(CustomPropertyTypeByName);
const titleText = properties.join(', ');
test(`Set & Update ${titleText} Custom Property `, async ({ page }) => {
// increase timeout as it using single test for multiple steps
test.slow(true);
await test.step(`Set ${titleText} Custom Property`, async () => {
for (const type of properties) {
await entity.setCustomProperty(
page,
entity.customPropertyValue[type].property,
entity.customPropertyValue[type].value
);
}
});
await test.step(`Update ${titleText} Custom Property`, async () => {
for (const type of properties) {
await entity.updateCustomProperty(
page,
entity.customPropertyValue[type].property,
entity.customPropertyValue[type].newValue
);
}
});
});
}
test(`Update displayName`, async ({ page }) => { test(`Update displayName`, async ({ page }) => {
await entity.renameEntity(page, entity.entity.name); await entity.renameEntity(page, entity.entity.name);
}); });
test.afterAll('Cleanup', async ({ browser }) => { test.afterAll('Cleanup', async ({ browser }) => {
const { apiContext, afterAction } = await createNewPage(browser); const { apiContext, afterAction } = await createNewPage(browser);
await entity.cleanup(apiContext);
await entity.delete(apiContext); await entity.delete(apiContext);
await EntityDataClass.postRequisitesForTests(apiContext); await EntityDataClass.postRequisitesForTests(apiContext);
await afterAction(); await afterAction();

View File

@ -50,6 +50,7 @@ import { EntityTypeEndpoint, ENTITY_PATH } from './Entity.interface';
export class EntityClass { export class EntityClass {
type: string; type: string;
endpoint: EntityTypeEndpoint; endpoint: EntityTypeEndpoint;
cleanupUser: (apiContext: APIRequestContext) => Promise<void>;
customPropertyValue: Record< customPropertyValue: Record<
string, string,
@ -78,13 +79,15 @@ export class EntityClass {
this.endpoint this.endpoint
); );
this.customPropertyValue = data; this.customPropertyValue = data.customProperties;
this.cleanupUser = data.cleanupUser;
} }
} }
async cleanup(apiContext: APIRequestContext) { async cleanup(apiContext: APIRequestContext) {
// Delete custom property only for supported entities // Delete custom property only for supported entities
if (CustomPropertySupportedEntityList.includes(this.endpoint)) { if (CustomPropertySupportedEntityList.includes(this.endpoint)) {
await this.cleanupUser(apiContext);
const entitySchemaResponse = await apiContext.get( const entitySchemaResponse = await apiContext.get(
`/api/v1/metadata/types/name/${ENTITY_PATH[this.endpoint]}` `/api/v1/metadata/types/name/${ENTITY_PATH[this.endpoint]}`
); );

View File

@ -15,6 +15,7 @@ import {
EntityTypeEndpoint, EntityTypeEndpoint,
ENTITY_PATH, ENTITY_PATH,
} from '../support/entity/Entity.interface'; } from '../support/entity/Entity.interface';
import { UserClass } from '../support/user/UserClass';
import { uuid } from './common'; import { uuid } from './common';
export enum CustomPropertyType { export enum CustomPropertyType {
@ -221,7 +222,10 @@ export const validateValueForProperty = async (data: {
} }
}; };
export const getPropertyValues = (type: string) => { export const getPropertyValues = (
type: string,
users: Record<string, string>
) => {
switch (type) { switch (type) {
case 'integer': case 'integer':
return { return {
@ -272,14 +276,14 @@ export const getPropertyValues = (type: string) => {
}; };
case 'entityReference': case 'entityReference':
return { return {
value: 'Adam Matthews', value: users.user1,
newValue: 'Aaron Singh', newValue: users.user2,
}; };
case 'entityReferenceList': case 'entityReferenceList':
return { return {
value: 'Aaron Johnson,Organization', value: `${users.user3},Organization`,
newValue: 'Aaron Warren', newValue: users.user4,
}; };
default: default:
@ -315,6 +319,27 @@ export const createCustomPropertyForEntity = async (
property: CustomProperty; property: CustomProperty;
} }
>; >;
const users: UserClass[] = [];
// Loop to create and add 4 new users to the users array
for (let i = 0; i < 4; i++) {
const user = new UserClass();
await user.create(apiContext);
users.push(user);
}
// Reduce the users array to a userNames object with keys as user1, user2, etc., and values as the user's names
const userNames = users.reduce((acc, user, index) => {
acc[`user${index + 1}`] = user.getUserName();
return acc;
}, {});
// Define an asynchronous function to clean up (delete) all users in the users array
const cleanupUser = async (apiContext: APIRequestContext) => {
for (const user of users) {
await user.delete(apiContext);
}
};
for (const item of propertyList) { for (const item of propertyList) {
const customPropertyResponse = await apiContext.put( const customPropertyResponse = await apiContext.put(
@ -357,12 +382,12 @@ export const createCustomPropertyForEntity = async (
return { return {
...prev, ...prev,
[propertyTypeName]: { [propertyTypeName]: {
...getPropertyValues(propertyTypeName), ...getPropertyValues(propertyTypeName, userNames),
property: curr, property: curr,
}, },
}; };
}, {}); }, {});
} }
return customProperties; return { customProperties, cleanupUser };
}; };