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] Feature: IOUTests for submitReport #29476

Merged
merged 4 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -2162,7 +2162,7 @@ function submitReport(expenseReport) {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`,
value: {
state: CONST.REPORT.STATE.OPEN,
statusNum: CONST.REPORT.STATUS.OPEN,
waterim marked this conversation as resolved.
Show resolved Hide resolved
stateNum: CONST.REPORT.STATE_NUM.OPEN,
},
},
Expand Down
179 changes: 179 additions & 0 deletions tests/actions/IOUTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import OnyxUpdateManager from '../../src/libs/actions/OnyxUpdateManager';
import waitForNetworkPromises from '../utils/waitForNetworkPromises';
import * as ReportUtils from '../../src/libs/ReportUtils';
import * as ReportActionsUtils from '../../src/libs/ReportActionsUtils';
import * as PolicyActions from '../../src/libs/actions/Policy';
import * as PersonalDetailsUtils from '../../src/libs/PersonalDetailsUtils';
import * as User from '../../src/libs/actions/User';
import PusherHelper from '../utils/PusherHelper';
Expand Down Expand Up @@ -2158,4 +2159,182 @@ describe('actions/IOU', () => {
expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.REPORT_WITH_ID.getRoute(chatReport.reportID));
});
});

describe('submitReport', () => {
it('correctly sibmitting a report', () => {
waterim marked this conversation as resolved.
Show resolved Hide resolved
const amount = 10000;
const comment = '💸💸💸💸';
const merchant = 'NASDAQ';
let expenseReport = {};
let chatReport = {};
return waitForBatchedUpdates()
.then(() => {
PolicyActions.createWorkspace(CARLOS_EMAIL, true, "Carlos's Workspace");
waterim marked this conversation as resolved.
Show resolved Hide resolved
return waitForBatchedUpdates();
})
.then(
() =>
new Promise((resolve) => {
const connectionID = Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (allReports) => {
Onyx.disconnect(connectionID);
chatReport = _.find(allReports, (report) => report.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT);

resolve();
},
});
}),
)
.then(() => {
IOU.requestMoney(chatReport, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment);
return waitForBatchedUpdates();
})
.then(
() =>
new Promise((resolve) => {
const connectionID = Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (allReports) => {
Onyx.disconnect(connectionID);
expenseReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU);
Onyx.merge(`report_${expenseReport.reportID}`, {
statusNum: 0,
stateNum: 0,
});
resolve();
},
});
}),
)
.then(
() =>
new Promise((resolve) => {
const connectionID = Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (allReports) => {
Onyx.disconnect(connectionID);
expenseReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU);
// Verify report is a draft
expect(expenseReport.stateNum).toBe(0);
expect(expenseReport.statusNum).toBe(0);
resolve();
},
});
}),
)
.then(() => {
IOU.submitReport(expenseReport);
return waitForBatchedUpdates();
})
.then(
() =>
new Promise((resolve) => {
const connectionID = Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (allReports) => {
Onyx.disconnect(connectionID);
expenseReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU);
// Report was submitted correctly
expect(expenseReport.stateNum).toBe(1);
expect(expenseReport.statusNum).toBe(1);
resolve();
},
});
}),
);
});
it('correctly implements error handling', () => {
const amount = 10000;
const comment = '💸💸💸💸';
const merchant = 'NASDAQ';
let expenseReport = {};
let chatReport = {};
return waitForBatchedUpdates()
.then(() => {
PolicyActions.createWorkspace(CARLOS_EMAIL, true, "Carlos's Workspace");
return waitForBatchedUpdates();
})
.then(
() =>
new Promise((resolve) => {
const connectionID = Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (allReports) => {
Onyx.disconnect(connectionID);
chatReport = _.find(allReports, (report) => report.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT);

resolve();
},
});
}),
)
.then(() => {
IOU.requestMoney(chatReport, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment);
return waitForBatchedUpdates();
})
.then(
() =>
new Promise((resolve) => {
const connectionID = Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (allReports) => {
Onyx.disconnect(connectionID);
expenseReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU);
waterim marked this conversation as resolved.
Show resolved Hide resolved
Onyx.merge(`report_${expenseReport.reportID}`, {
statusNum: 0,
stateNum: 0,
});
resolve();
},
});
}),
)
.then(
() =>
new Promise((resolve) => {
const connectionID = Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (allReports) => {
Onyx.disconnect(connectionID);
expenseReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU);
waterim marked this conversation as resolved.
Show resolved Hide resolved
// Verify report is a draft
waterim marked this conversation as resolved.
Show resolved Hide resolved
expect(expenseReport.stateNum).toBe(0);
expect(expenseReport.statusNum).toBe(0);
resolve();
},
});
}),
)
.then(() => {
fetch.fail();
IOU.submitReport(expenseReport);
waterim marked this conversation as resolved.
Show resolved Hide resolved
return waitForBatchedUpdates();
})
.then(
() =>
new Promise((resolve) => {
const connectionID = Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (allReports) => {
Onyx.disconnect(connectionID);
expenseReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU);
waterim marked this conversation as resolved.
Show resolved Hide resolved
// Report was submitted with some fail
expect(expenseReport.stateNum).toBe(0);
expect(expenseReport.statusNum).toBe(0);
resolve();
},
});
}),
);
});
});
});
Loading