Skip to content

fix: Error in archived task Set up categories #61393

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

Merged
merged 3 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1276,8 +1276,8 @@ function clearTaskErrors(reportID: string | undefined) {

function getFinishOnboardingTaskOnyxData(taskName: keyof OnyxTypes.IntroSelected): OnyxData {
const taskReportID = introSelected?.[taskName];
if (taskReportID) {
const taskReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`];
const taskReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`];
if (taskReportID && canActionTask(taskReport, currentUserAccountID)) {
if (taskReport) {
if (taskReport.stateNum !== CONST.REPORT.STATE_NUM.APPROVED || taskReport.statusNum !== CONST.REPORT.STATUS_NUM.APPROVED) {
return completeTask(taskReport);
Expand Down
32 changes: 31 additions & 1 deletion tests/actions/TaskTest.ts
Copy link
Contributor

Choose a reason for hiding this comment

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

This task is failing on local for me, can you take a look 👀 ?

Screenshot 2025-05-06 at 18 11 36

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hungvu193 Could you help run the test again?
Screenshot 2025-05-07 at 11 44 33

Copy link
Contributor

Choose a reason for hiding this comment

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

Tests passed!

Screenshot 2025-05-07 at 15 17 47

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {renderHook} from '@testing-library/react-native';
import Onyx from 'react-native-onyx';
import useReportIsArchived from '@hooks/useReportIsArchived';
import {canModifyTask, completeTestDriveTask} from '@libs/actions/Task';
import {canModifyTask, completeTestDriveTask, getFinishOnboardingTaskOnyxData} from '@libs/actions/Task';
// eslint-disable-next-line no-restricted-syntax -- this is required to allow mocking
import * as API from '@libs/API';
import {WRITE_COMMANDS} from '@libs/API/types';
import DateUtils from '@libs/DateUtils';
import Parser from '@libs/Parser';
// eslint-disable-next-line no-restricted-syntax -- this is required to allow mocking
import * as ReportUtils from '@libs/ReportUtils';
Expand Down Expand Up @@ -141,4 +142,33 @@ describe('actions/Task', () => {
expect(writeSpy).toHaveBeenCalledWith(WRITE_COMMANDS.COMPLETE_TASK, expect.anything(), expect.anything());
});
});

describe('getFinishOnboardingTaskOnyxData', () => {
const parentReport: Report = LHNTestUtils.getFakeReport();
const taskReport: Report = {...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.TASK, ownerAccountID: 1, managerID: 2, parentReportID: parentReport.reportID};
const reportCollectionDataSet: ReportCollectionDataSet = {
[`${ONYXKEYS.COLLECTION.REPORT}${taskReport.reportID}`]: taskReport,
[`${ONYXKEYS.COLLECTION.REPORT}${parentReport.reportID}`]: parentReport,
};
beforeEach(async () => {
await Onyx.clear();
await Onyx.multiSet({
...reportCollectionDataSet,
});
await Onyx.set(ONYXKEYS.SESSION, {email: '[email protected]', accountID: 2});
await Onyx.set(`${ONYXKEYS.NVP_INTRO_SELECTED}`, {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM, setupCategories: taskReport.reportID});
await waitForBatchedUpdates();
});
it('Return not empty object', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, just dropping in here, but can you please be more descriptive with the test names or comments? From looking at this test (and the one below), I have no context to understand why an empty or a non-empty object would be expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tgolen Should I create a follow-up PR to add a more descriptive explanation for the test?

expect(Object.values(getFinishOnboardingTaskOnyxData('setupCategories')).length).toBeGreaterThan(0);
});
it('Return empty object', async () => {
const reportNameValuePairs = {
private_isArchived: DateUtils.getDBTime(),
};
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${parentReport.reportID}`, reportNameValuePairs);
await waitForBatchedUpdates();
expect(Object.values(getFinishOnboardingTaskOnyxData('setupCategories')).length).toBe(0);
});
});
});
Loading