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

[HOLD #51296] [Unit & UI Tests]: add unit test for automatically approved expense #51330

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"ios-build": "bundle exec fastlane ios build_unsigned",
"android-build": "bundle exec fastlane android build_local",
"test": "TZ=utc NODE_OPTIONS=--experimental-vm-modules jest",
"test:unit": "TZ=utc NODE_OPTIONS=--experimental-vm-modules jest tests/unit/ReportUtilsTest.ts",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Beamanator please ignore this, i have used this temporarily just to not use up all the memory testing all files 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha yeah that's useful, you'll remove before we merge, eh? :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, for sure !

"typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=0 --cache --cache-location=node_modules/.cache/eslint",
"lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 eslint --max-warnings=0 --config ./.eslintrc.changed.js $(git diff --diff-filter=AM --name-only origin/main HEAD -- \"*.ts\" \"*.tsx\")",
Expand Down
88 changes: 88 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,94 @@ describe('ReportUtils', () => {
});
});

describe('Automatically approved report message via automatic (not by a human) action is', () => {
test('Automatically Approved Report message when report is forwarded (Control feature)', () => {
Comment on lines +297 to +298
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can clean up these names a bit - I believe ideally it reads almost like a sentence, starting with the describe text, followed by the test itself - you can see how in other places (like just above) we have describe('ParentReportAction is') + test('Manually Submitted Report Action')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool cool, I'll update in the next commit

const threadOfSubmittedReportAction = {
...LHNTestUtils.getFakeReport(),
type: CONST.REPORT.TYPE.EXPENSE,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.APPROVED,
parentReportID: '101',
policyID: policy.id,
};
const submittedParentReportAction = {
actionName: CONST.REPORT.ACTIONS.TYPE.FORWARDED,
originalMessage: {
amount: 169,
currency: 'USD',
automaticAction: true,
},
} as ReportAction;

expect(ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction)).toBe('automatically approved $1.69 via workspace rules');
});

test('Automatically Approved Report message when report is approved', () => {
const threadOfSubmittedReportAction = {
...LHNTestUtils.getFakeReport(),
type: CONST.REPORT.TYPE.EXPENSE,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.APPROVED,
parentReportID: '101',
policyID: policy.id,
};
const submittedParentReportAction = {
actionName: CONST.REPORT.ACTIONS.TYPE.APPROVED,
originalMessage: {
amount: 169,
currency: 'USD',
automaticAction: true,
},
} as ReportAction;

expect(ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction)).toBe('automatically approved $1.69 via workspace rules');
});
});

describe('Automatically approved report message via harvesting (delayed submit) is', () => {
test('Automatically Approved Report message for report type submitted and status is submitted', () => {
const threadOfSubmittedReportAction = {
...LHNTestUtils.getFakeReport(),
type: CONST.REPORT.TYPE.EXPENSE,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
parentReportID: '101',
policyID: policy.id,
};
const submittedParentReportAction = {
actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED,
originalMessage: {
amount: 169,
currency: 'USD',
harvesting: true,
},
} as ReportAction;

expect(ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction)).toBe('automatically submitted $1.69 via delayed submission');
});

test('Automatically Approved Report message for report type submitted and status is closed', () => {
const threadOfSubmittedReportAction = {
...LHNTestUtils.getFakeReport(),
type: CONST.REPORT.TYPE.EXPENSE,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS_NUM.CLOSED,
parentReportID: '101',
policyID: policy.id,
};
const submittedParentReportAction = {
actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED_AND_CLOSED,
originalMessage: {
amount: 169,
currency: 'USD',
harvesting: true,
},
} as ReportAction;

expect(ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction)).toBe('automatically submitted $1.69 via delayed submission');
});
});

describe('requiresAttentionFromCurrentUser', () => {
afterEach(async () => {
await Onyx.clear();
Expand Down
Loading