Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NoQA] Add performance tests for getMemberAccountIDsForWorkspace #38271

Merged
merged 16 commits into from
Mar 18, 2024
Merged
37 changes: 37 additions & 0 deletions tests/perf-test/PolicyUtils.perf-test.js
ShridharGoel marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {measureFunction} from 'reassure';
import {getMemberAccountIDsForWorkspace} from '@libs/PolicyUtils';
import PolicyMember from '@src/types/onyx/PolicyMember';
ShridharGoel marked this conversation as resolved.
Show resolved Hide resolved
import createCollection from '../utils/collections/createCollection';
import createPersonalDetails from '../utils/collections/personalDetails';
import createRandomPolicy from '../utils/collections/policies';
import createRandomPolicyMember from '../utils/collections/policyMembers';

describe('[PolicyUtils] Performance tests for getMemberAccountIDsForWorkspace', () => {
test('With multiple members with personal details and policy members', async () => {
const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index)}));
ShridharGoel marked this conversation as resolved.
Show resolved Hide resolved
const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, createPersonalDetails(i)]));
ShridharGoel marked this conversation as resolved.
Show resolved Hide resolved

await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails));
});

test('With multiple members with empty personal details and with errors in policy members', async () => {
const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index), errors: {someError: true}}));
ShridharGoel marked this conversation as resolved.
Show resolved Hide resolved
const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {}]));
ShridharGoel marked this conversation as resolved.
Show resolved Hide resolved

await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails));
});

test('With multiple members with personal details and with errors in policy members', async () => {
const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicy(index), errors: {someError: true}}));
const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, createPersonalDetails(i)]));
ShridharGoel marked this conversation as resolved.
Show resolved Hide resolved

await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails));
});

test('With multiple members with empty personal details and with policy members', async () => {
const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index)}));
const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {}]));
ShridharGoel marked this conversation as resolved.
Show resolved Hide resolved

await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails));
});
});
9 changes: 9 additions & 0 deletions tests/utils/collections/policyMembers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {randWord} from '@ngneat/falso';
import type PolicyMember from '@src/types/onyx/PolicyMember';
ShridharGoel marked this conversation as resolved.
Show resolved Hide resolved

export default function createRandomPolicyMember(): PolicyMember {
return {
role: randWord(),
errors: {},
};
}
Loading