Skip to content

Commit 9400495

Browse files
authored
Merge pull request #61393 from truph01/fix/61006
fix: Error in archived task Set up categories
2 parents 8453ef6 + 197204e commit 9400495

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/libs/actions/Task.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,8 +1276,8 @@ function clearTaskErrors(reportID: string | undefined) {
12761276

12771277
function getFinishOnboardingTaskOnyxData(taskName: keyof OnyxTypes.IntroSelected): OnyxData {
12781278
const taskReportID = introSelected?.[taskName];
1279-
if (taskReportID) {
1280-
const taskReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`];
1279+
const taskReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`];
1280+
if (taskReportID && canActionTask(taskReport, currentUserAccountID)) {
12811281
if (taskReport) {
12821282
if (taskReport.stateNum !== CONST.REPORT.STATE_NUM.APPROVED || taskReport.statusNum !== CONST.REPORT.STATUS_NUM.APPROVED) {
12831283
return completeTask(taskReport);

tests/actions/TaskTest.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import {renderHook} from '@testing-library/react-native';
22
import Onyx from 'react-native-onyx';
33
import useReportIsArchived from '@hooks/useReportIsArchived';
4-
import {canModifyTask, completeTestDriveTask} from '@libs/actions/Task';
4+
import {canModifyTask, completeTestDriveTask, getFinishOnboardingTaskOnyxData} from '@libs/actions/Task';
55
// eslint-disable-next-line no-restricted-syntax -- this is required to allow mocking
66
import * as API from '@libs/API';
77
import {WRITE_COMMANDS} from '@libs/API/types';
8+
import DateUtils from '@libs/DateUtils';
89
import Parser from '@libs/Parser';
910
// eslint-disable-next-line no-restricted-syntax -- this is required to allow mocking
1011
import * as ReportUtils from '@libs/ReportUtils';
@@ -141,4 +142,33 @@ describe('actions/Task', () => {
141142
expect(writeSpy).toHaveBeenCalledWith(WRITE_COMMANDS.COMPLETE_TASK, expect.anything(), expect.anything());
142143
});
143144
});
145+
146+
describe('getFinishOnboardingTaskOnyxData', () => {
147+
const parentReport: Report = LHNTestUtils.getFakeReport();
148+
const taskReport: Report = {...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.TASK, ownerAccountID: 1, managerID: 2, parentReportID: parentReport.reportID};
149+
const reportCollectionDataSet: ReportCollectionDataSet = {
150+
[`${ONYXKEYS.COLLECTION.REPORT}${taskReport.reportID}`]: taskReport,
151+
[`${ONYXKEYS.COLLECTION.REPORT}${parentReport.reportID}`]: parentReport,
152+
};
153+
beforeEach(async () => {
154+
await Onyx.clear();
155+
await Onyx.multiSet({
156+
...reportCollectionDataSet,
157+
});
158+
await Onyx.set(ONYXKEYS.SESSION, {email: '[email protected]', accountID: 2});
159+
await Onyx.set(`${ONYXKEYS.NVP_INTRO_SELECTED}`, {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM, setupCategories: taskReport.reportID});
160+
await waitForBatchedUpdates();
161+
});
162+
it('Return not empty object', () => {
163+
expect(Object.values(getFinishOnboardingTaskOnyxData('setupCategories')).length).toBeGreaterThan(0);
164+
});
165+
it('Return empty object', async () => {
166+
const reportNameValuePairs = {
167+
private_isArchived: DateUtils.getDBTime(),
168+
};
169+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${parentReport.reportID}`, reportNameValuePairs);
170+
await waitForBatchedUpdates();
171+
expect(Object.values(getFinishOnboardingTaskOnyxData('setupCategories')).length).toBe(0);
172+
});
173+
});
144174
});

0 commit comments

Comments
 (0)