Skip to content

Commit

Permalink
playwright: updated entity spec with custom property test (#16621)
Browse files Browse the repository at this point in the history
* playwright: updated entity spec with custom property test

* optimise the code

* fixed playwright failure

* addressing comment
  • Loading branch information
ShaileshParmar11 authored Jun 12, 2024
1 parent cc2d581 commit af88b61
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* limitations under the License.
*/
import { test } from '@playwright/test';
import { CustomPropertySupportedEntityList } from '../../constant/customProperty';
import { DatabaseClass } from '../../support/entity/DatabaseClass';
import { DatabaseSchemaClass } from '../../support/entity/DatabaseSchemaClass';
import { EntityDataClass } from '../../support/entity/EntityDataClass';
Expand All @@ -27,6 +28,7 @@ import {
getToken,
redirectToHomePage,
} from '../../utils/common';
import { CustomPropertyTypeByName } from '../../utils/customProperty';

const entities = [
DatabaseServiceClass,
Expand All @@ -53,6 +55,7 @@ entities.forEach((EntityClass) => {

await EntityDataClass.preRequisitesForTests(apiContext);
await entity.create(apiContext);
await entity.prepareForTests(apiContext);
await afterAction();
});

Expand Down Expand Up @@ -112,12 +115,44 @@ entities.forEach((EntityClass) => {
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 }) => {
await entity.renameEntity(page, entity.entity.name);
});

test.afterAll('Cleanup', async ({ browser }) => {
const { apiContext, afterAction } = await createNewPage(browser);
await entity.cleanup(apiContext);
await entity.delete(apiContext);
await EntityDataClass.postRequisitesForTests(apiContext);
await afterAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { EntityTypeEndpoint, ENTITY_PATH } from './Entity.interface';
export class EntityClass {
type: string;
endpoint: EntityTypeEndpoint;
cleanupUser: (apiContext: APIRequestContext) => Promise<void>;

customPropertyValue: Record<
string,
Expand Down Expand Up @@ -78,13 +79,15 @@ export class EntityClass {
this.endpoint
);

this.customPropertyValue = data;
this.customPropertyValue = data.customProperties;
this.cleanupUser = data.cleanupUser;
}
}

async cleanup(apiContext: APIRequestContext) {
// Delete custom property only for supported entities
if (CustomPropertySupportedEntityList.includes(this.endpoint)) {
await this.cleanupUser(apiContext);
const entitySchemaResponse = await apiContext.get(
`/api/v1/metadata/types/name/${ENTITY_PATH[this.endpoint]}`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
EntityTypeEndpoint,
ENTITY_PATH,
} from '../support/entity/Entity.interface';
import { UserClass } from '../support/user/UserClass';
import { uuid } from './common';

export enum CustomPropertyType {
Expand Down Expand Up @@ -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) {
case 'integer':
return {
Expand Down Expand Up @@ -272,14 +276,14 @@ export const getPropertyValues = (type: string) => {
};
case 'entityReference':
return {
value: 'Adam Matthews',
newValue: 'Aaron Singh',
value: users.user1,
newValue: users.user2,
};

case 'entityReferenceList':
return {
value: 'Aaron Johnson,Organization',
newValue: 'Aaron Warren',
value: `${users.user3},Organization`,
newValue: users.user4,
};

default:
Expand Down Expand Up @@ -315,6 +319,27 @@ export const createCustomPropertyForEntity = async (
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) {
const customPropertyResponse = await apiContext.put(
Expand Down Expand Up @@ -357,12 +382,12 @@ export const createCustomPropertyForEntity = async (
return {
...prev,
[propertyTypeName]: {
...getPropertyValues(propertyTypeName),
...getPropertyValues(propertyTypeName, userNames),
property: curr,
},
};
}, {});
}

return customProperties;
return { customProperties, cleanupUser };
};

0 comments on commit af88b61

Please sign in to comment.