Browse Source

test: async routine for duplicate trigger

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
test/pw-duplicate-check
Raju Udava 1 year ago
parent
commit
018637e3b6
  1. 6
      tests/playwright/tests/db/projectOperations.spec.ts
  2. 6
      tests/playwright/tests/utils/objectCompareUtil.ts

6
tests/playwright/tests/db/projectOperations.spec.ts

@ -109,7 +109,7 @@ test.describe('Project operations', () => {
const projectInfoOp: ProjectInfoApiUtil = new ProjectInfoApiUtil(context.token); const projectInfoOp: ProjectInfoApiUtil = new ProjectInfoApiUtil(context.token);
const orginal: Promise<ProjectInfo> = projectInfoOp.extractProjectInfo(testProjectId.id); const orginal: Promise<ProjectInfo> = projectInfoOp.extractProjectInfo(testProjectId.id);
const duplicate: Promise<ProjectInfo> = projectInfoOp.extractProjectInfo(dupeProjectId.id); const duplicate: Promise<ProjectInfo> = projectInfoOp.extractProjectInfo(dupeProjectId.id);
await Promise.all([orginal, duplicate]).then(arr => { await Promise.all([orginal, duplicate]).then(async arr => {
const ignoredFields: Set<string> = new Set([ const ignoredFields: Set<string> = new Set([
'id', 'id',
'prefix', 'prefix',
@ -149,7 +149,9 @@ test.describe('Project operations', () => {
]); ]);
const orginalProjectInfo: ProjectInfo = arr[0]; const orginalProjectInfo: ProjectInfo = arr[0];
const duplicateProjectInfo: ProjectInfo = arr[1]; const duplicateProjectInfo: ProjectInfo = arr[1];
expect(deepCompare(orginalProjectInfo, duplicateProjectInfo, ignoredFields, ignoredKeys)).toBeTruthy(); await expect(
await deepCompare(orginalProjectInfo, duplicateProjectInfo, ignoredFields, ignoredKeys)
).toBeTruthy();
}); });
// cleanup test-data // cleanup test-data

6
tests/playwright/tests/utils/objectCompareUtil.ts

@ -15,14 +15,14 @@
* @param breakAtFirstMismatch : default true. returns false on first field mismatch * @param breakAtFirstMismatch : default true. returns false on first field mismatch
* @returns * @returns
*/ */
export function deepCompare( export async function deepCompare(
obj1: any, obj1: any,
obj2: any, obj2: any,
ignoredFields?: Set<string>, ignoredFields?: Set<string>,
ignoredKeys?: Set<string>, ignoredKeys?: Set<string>,
keyId = '', keyId = '',
breakAtFirstMismatch = true breakAtFirstMismatch = true
): boolean { ): Promise<boolean> {
if (ignoredKeys !== undefined && ignoredKeys.has(keyId)) { if (ignoredKeys !== undefined && ignoredKeys.has(keyId)) {
return true; return true;
} }
@ -56,7 +56,7 @@ export function deepCompare(
// console.log(`${keyId} ignored in comparison`) // console.log(`${keyId} ignored in comparison`)
} else { } else {
keyId = keyId + '.' + key; keyId = keyId + '.' + key;
if (!deepCompare(obj1[key], obj2[key], ignoredFields, ignoredKeys, keyId, breakAtFirstMismatch)) { if (!(await deepCompare(obj1[key], obj2[key], ignoredFields, ignoredKeys, keyId, breakAtFirstMismatch))) {
return !breakAtFirstMismatch; return !breakAtFirstMismatch;
// return false; // return false;
} }

Loading…
Cancel
Save