Skip to content

Commit

Permalink
use async
Browse files Browse the repository at this point in the history
  • Loading branch information
nkdengineer committed Jan 13, 2025
1 parent 5c05791 commit 0e7beb3
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions tests/unit/PolicyUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import createCollection from '../utils/collections/createCollection';
import createRandomPolicy from '../utils/collections/policies';
import createRandomReport from '../utils/collections/reports';
import createRandomTransaction from '../utils/collections/transaction';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates';

Check failure on line 11 in tests/unit/PolicyUtilsTest.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Replace `rapOnyxWithWaitForBatchedUpdates·from·'../utils/wrapOnyxWithWaitForBatchedUpdates` with `aitForBatchedUpdatesWithAct·from·'../utils/waitForBatchedUpdatesWithAct`

Check failure on line 11 in tests/unit/PolicyUtilsTest.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Replace `rapOnyxWithWaitForBatchedUpdates·from·'../utils/wrapOnyxWithWaitForBatchedUpdates` with `aitForBatchedUpdatesWithAct·from·'../utils/waitForBatchedUpdatesWithAct`
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';

Check failure on line 12 in tests/unit/PolicyUtilsTest.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Replace `aitForBatchedUpdatesWithAct·from·'../utils/waitForBatchedUpdatesWithAct` with `rapOnyxWithWaitForBatchedUpdates·from·'../utils/wrapOnyxWithWaitForBatchedUpdates`

Check failure on line 12 in tests/unit/PolicyUtilsTest.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Replace `aitForBatchedUpdatesWithAct·from·'../utils/waitForBatchedUpdatesWithAct` with `rapOnyxWithWaitForBatchedUpdates·from·'../utils/wrapOnyxWithWaitForBatchedUpdates`

function toLocaleDigitMock(dot: string): string {
return dot;
Expand Down Expand Up @@ -230,11 +231,12 @@ describe('PolicyUtils', () => {

describe('getSubmitToAccountID', () => {
beforeEach(() => {
wrapOnyxWithWaitForBatchedUpdates(Onyx);
Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails);
return waitForBatchedUpdates();
});
afterEach(() => {
Onyx.clear();
afterEach(async () => {
await Onyx.clear();
await waitForBatchedUpdatesWithAct();
});
describe('Has no rule approver', () => {
it('should return the policy approver/owner if the policy use the optional or basic workflow', () => {
Expand Down Expand Up @@ -270,14 +272,15 @@ describe('PolicyUtils', () => {
});
});
describe('Has category/tag approver', () => {
it('should return the first category approver if has any transaction category match with category approver rule', () => {
it('should return the first category approver if has any transaction category match with category approver rule', async() => {

Check failure on line 275 in tests/unit/PolicyUtilsTest.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `·`

Check failure on line 275 in tests/unit/PolicyUtilsTest.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Insert `·`
const policy: Policy = {
...createRandomPolicy(0),
approver: '[email protected]',
owner: '[email protected]',
type: 'team',
employeeList,
rules,
approvalMode: CONST.POLICY.APPROVAL_MODE.ADVANCED,
};
const expenseReport: Report = {
...createRandomReport(0),
Expand All @@ -294,21 +297,21 @@ describe('PolicyUtils', () => {
category: '',
reportID: expenseReport.reportID,
};
Onyx.set(ONYXKEYS.COLLECTION.TRANSACTION, {
await Onyx.set(ONYXKEYS.COLLECTION.TRANSACTION, {
[transaction1.transactionID]: transaction1,
[transaction2.transactionID]: transaction2,
}).then(() => {
expect(PolicyUtils.getSubmitToAccountID(policy, expenseReport)).toBe(categoryapprover1AccountID);
});
expect(PolicyUtils.getSubmitToAccountID(policy, expenseReport)).toBe(categoryapprover1AccountID);
});
it('should return the category approver of the first transaction sorted by created if we have many transaction categories match with the category approver rule', () => {
it('should return the category approver of the first transaction sorted by created if we have many transaction categories match with the category approver rule', async() => {

Check failure on line 306 in tests/unit/PolicyUtilsTest.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `·`

Check failure on line 306 in tests/unit/PolicyUtilsTest.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Insert `·`
const policy: Policy = {
...createRandomPolicy(0),
approver: '[email protected]',
owner: '[email protected]',
type: 'team',
employeeList,
rules,
approvalMode: CONST.POLICY.APPROVAL_MODE.ADVANCED,
};
const expenseReport: Report = {
...createRandomReport(0),
Expand All @@ -327,22 +330,22 @@ describe('PolicyUtils', () => {
created: '2',
reportID: expenseReport.reportID,
};
Onyx.set(ONYXKEYS.COLLECTION.TRANSACTION, {
await Onyx.set(ONYXKEYS.COLLECTION.TRANSACTION, {
[transaction1.transactionID]: transaction1,
[transaction2.transactionID]: transaction2,
}).then(() => {
expect(PolicyUtils.getSubmitToAccountID(policy, expenseReport)).toBe(categoryapprover2AccountID);
});
expect(PolicyUtils.getSubmitToAccountID(policy, expenseReport)).toBe(categoryapprover2AccountID);
});
describe('Has no transaction match with the category approver rule', () => {
it('should return the first tag approver if has any transaction tag match with with the tag approver rule ', () => {
it('should return the first tag approver if has any transaction tag match with with the tag approver rule ', async() => {

Check failure on line 340 in tests/unit/PolicyUtilsTest.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `·`

Check failure on line 340 in tests/unit/PolicyUtilsTest.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Insert `·`
const policy: Policy = {
...createRandomPolicy(0),
approver: '[email protected]',
owner: '[email protected]',
type: 'team',
employeeList,
rules,
approvalMode: CONST.POLICY.APPROVAL_MODE.ADVANCED,
};
const expenseReport: Report = {
...createRandomReport(0),
Expand All @@ -363,21 +366,21 @@ describe('PolicyUtils', () => {
created: '2',
reportID: expenseReport.reportID,
};
Onyx.set(ONYXKEYS.COLLECTION.TRANSACTION, {
await Onyx.set(ONYXKEYS.COLLECTION.TRANSACTION, {
[transaction1.transactionID]: transaction1,
[transaction2.transactionID]: transaction2,
}).then(() => {
expect(PolicyUtils.getSubmitToAccountID(policy, expenseReport)).toBe(tagapprover1AccountID);
});
expect(PolicyUtils.getSubmitToAccountID(policy, expenseReport)).toBe(tagapprover1AccountID);
});
it('should return the tag approver of the first transaction sorted by created if we have many transaction tags match with the tag approver rule', () => {
it('should return the tag approver of the first transaction sorted by created if we have many transaction tags match with the tag approver rule', async() => {

Check failure on line 375 in tests/unit/PolicyUtilsTest.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `·`

Check failure on line 375 in tests/unit/PolicyUtilsTest.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Insert `·`
const policy: Policy = {
...createRandomPolicy(0),
approver: '[email protected]',
owner: '[email protected]',
type: 'team',
employeeList,
rules,
approvalMode: CONST.POLICY.APPROVAL_MODE.ADVANCED,
};
const expenseReport: Report = {
...createRandomReport(0),
Expand All @@ -398,12 +401,11 @@ describe('PolicyUtils', () => {
created: '2',
reportID: expenseReport.reportID,
};
Onyx.set(ONYXKEYS.COLLECTION.TRANSACTION, {
await Onyx.set(ONYXKEYS.COLLECTION.TRANSACTION, {
[transaction1.transactionID]: transaction1,
[transaction2.transactionID]: transaction2,
}).then(() => {
expect(PolicyUtils.getSubmitToAccountID(policy, expenseReport)).toBe(tagapprover2AccountID);
});
expect(PolicyUtils.getSubmitToAccountID(policy, expenseReport)).toBe(tagapprover2AccountID);
});
});
});
Expand Down

0 comments on commit 0e7beb3

Please sign in to comment.