From bac130218b927a80510cacfb7351e3002435b371 Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Fri, 13 Dec 2024 12:53:19 -0800 Subject: [PATCH 01/19] Failing test only returns invoice chat when receiver type matches --- tests/unit/ReportUtilsTest.ts | 75 ++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index e1eda3171355..83f0bee3ca20 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ import {addDays, format as formatDate} from 'date-fns'; -import type {OnyxEntry} from 'react-native-onyx'; +import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import DateUtils from '@libs/DateUtils'; import * as ReportUtils from '@libs/ReportUtils'; @@ -1414,4 +1414,77 @@ describe('ReportUtils', () => { ).toBeTruthy(); }); }); + + describe('getInvoiceChatByParticipants', () => { + it('only returns an invoice chat if the receiver type matches', () => { + // Given an invoice chat that has been converted from an individual to policy receiver type + const convertedInvoiceChat = { + chatType: CONST.REPORT.CHAT_TYPE.INVOICE, + currency: 'USD', + description: '', + errorFields: null, + hasOutstandingChildRequest: false, + hasOutstandingChildTask: false, + invoiceReceiver: { + accountID: 33, + policyID: '5F2F82F98C848CAA', + type: 'policy', + }, + isCancelledIOU: false, + isOwnPolicyExpenseChat: false, + isPinned: false, + isWaitingOnBankAccount: false, + lastActionType: 'REPORTPREVIEW', + lastActorAccountID: '32', + lastMessageHtml: 'paid $1.00', + lastMessageText: 'paid $1.00', + lastMessageTranslationKey: '', + lastReadSequenceNumber: 0, + lastReadTime: '2024-12-13 19:45:28.942', + lastVisibleActionCreated: '2024-12-13 19:19:01.794', + lastVisibleActionLastModified: '2024-12-13 19:19:01.794', + managerID: 0, + nonReimbursableTotal: 0, + oldPolicyName: '', + ownerAccountID: 0, + participants: { + '32': { + notificationPreference: 'always', + role: 'admin', + }, + '33': { + notificationPreference: 'always', + permissions: ['read', 'write', 'share', 'own'], + }, + }, + policyAvatar: '', + policyID: 'CC048FA711B35B1F', + policyName: "53019's Workspace", + private_isArchived: '', + reportID: '7605647250932303', + reportName: 'Chat Report', + state: 'OPEN', + stateNum: 0, + statusNum: 0, + total: 0, + type: 'chat', + unheldNonReimbursableTotal: 0, + unheldTotal: 0, + visibility: 'private', + welcomeMessage: '', + writeCapability: 'all', + }; + + // Get an Onyx collection of reports + const reports: OnyxCollection = { + [convertedInvoiceChat.reportID]: convertedInvoiceChat, + }; + + // When we send another invoice to the individual from global create and call getInvoiceChatByParticipants + const invoiceChatReport = ReportUtils.getInvoiceChatByParticipants(convertedInvoiceChat.policyID, 33, reports); + + // Then no invoice chat should be returned because the receiver type does not match + expect(invoiceChatReport).toBeUndefined(); + }); + }); }); From 59d79fa2ad9b480432498c0e751d56864c08b272 Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Fri, 13 Dec 2024 13:03:33 -0800 Subject: [PATCH 02/19] Fix test, require invoice receiver to match --- src/libs/ReportUtils.ts | 5 +++-- src/types/onyx/Report.ts | 5 ++++- tests/unit/ReportUtilsTest.ts | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0b5d03e9e365..25a8055bc747 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -52,7 +52,7 @@ import type {ErrorFields, Errors, Icon, PendingAction} from '@src/types/onyx/Ony import type {OriginalMessageChangeLog, PaymentMethodType} from '@src/types/onyx/OriginalMessage'; import type {Status} from '@src/types/onyx/PersonalDetails'; import type {ConnectionName} from '@src/types/onyx/Policy'; -import type {NotificationPreference, Participants, PendingChatMember, Participant as ReportParticipant} from '@src/types/onyx/Report'; +import type {InvoiceReceiverType, NotificationPreference, Participants, PendingChatMember, Participant as ReportParticipant} from '@src/types/onyx/Report'; import type {Message, OldDotReportAction, ReportActions} from '@src/types/onyx/ReportAction'; import type {SearchPolicy, SearchReport, SearchTransaction} from '@src/types/onyx/SearchResults'; import type {Comment, TransactionChanges, WaypointCollection} from '@src/types/onyx/Transaction'; @@ -6746,7 +6746,7 @@ function getChatByParticipants(newParticipantList: number[], reports: OnyxCollec /** * Attempts to find an invoice chat report in onyx with the provided policyID and receiverID. */ -function getInvoiceChatByParticipants(policyID: string, receiverID: string | number, reports: OnyxCollection = allReports): OnyxEntry { +function getInvoiceChatByParticipants(policyID: string, receiverID: string | number, receiverType: InvoiceReceiverType, reports: OnyxCollection = allReports): OnyxEntry { return Object.values(reports ?? {}).find((report) => { if (!report || !isInvoiceRoom(report) || isArchivedRoom(report)) { return false; @@ -6754,6 +6754,7 @@ function getInvoiceChatByParticipants(policyID: string, receiverID: string | num const isSameReceiver = report.invoiceReceiver && + report.invoiceReceiver.type === receiverType && (('accountID' in report.invoiceReceiver && report.invoiceReceiver.accountID === receiverID) || ('policyID' in report.invoiceReceiver && report.invoiceReceiver.policyID === receiverID)); diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index b89b6c8e0777..7f652904f0cb 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -61,6 +61,9 @@ type InvoiceReceiver = policyID: string; }; +/** Type of invoice receiver */ +type InvoiceReceiverType = InvoiceReceiver['type']; + /** Record of report participants, indexed by their accountID */ type Participants = Record; @@ -244,4 +247,4 @@ type ReportCollectionDataSet = CollectionDataSet { }; // When we send another invoice to the individual from global create and call getInvoiceChatByParticipants - const invoiceChatReport = ReportUtils.getInvoiceChatByParticipants(convertedInvoiceChat.policyID, 33, reports); + const invoiceChatReport = ReportUtils.getInvoiceChatByParticipants(convertedInvoiceChat.policyID, 33, CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL, reports); // Then no invoice chat should be returned because the receiver type does not match expect(invoiceChatReport).toBeUndefined(); From 0afdca3337ddc95690f406a7c38ea14ccbd13ada Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Fri, 13 Dec 2024 13:27:58 -0800 Subject: [PATCH 03/19] WIP test getSendMoneyInvoiceInformation --- tests/actions/IOUTest.ts | 229 ++++++++++++++++++++++++++++++++++ tests/unit/ReportUtilsTest.ts | 118 +++++++++--------- 2 files changed, 289 insertions(+), 58 deletions(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 11ff821cb240..27c9f302de8a 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -21,6 +21,7 @@ import type * as OnyxTypes from '@src/types/onyx'; import type {Participant} from '@src/types/onyx/Report'; import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import {convertedInvoiceChat} from '../unit/ReportUtilsTest'; import PusherHelper from '../utils/PusherHelper'; import type {MockFetch} from '../utils/TestHelper'; import * as TestHelper from '../utils/TestHelper'; @@ -3303,4 +3304,232 @@ describe('actions/IOU', () => { ); }); }); + + describe('getSendInvoiceInformation', () => { + // Given a convertedInvoiceReport is stored in Onyx + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${convertedInvoiceChat.reportID}`, convertedInvoiceChat); + + // And data for when a new invoice is sent to a user + const transaction: OnyxEntry = { + amount: 100, + attendees: [ + { + email: 'a1@53019.com', + login: 'a1@53019.com', + displayName: 'a1', + avatarUrl: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_9.png', + accountID: 32, + text: 'a1@53019.com', + selected: true, + reportID: '3634215302663162', + }, + ], + comment: { + customUnit: { + customUnitRateID: '_FAKE_P2P_ID_', + }, + }, + created: '2024-12-13', + currency: 'USD', + iouRequestType: 'manual', + reportID: '3634215302663162', + transactionID: '1', + isFromGlobalCreate: true, + merchant: '(none)', + splitPayerAccountIDs: [32], + shouldShowOriginalAmount: true, + participants: [ + { + accountID: 33, + login: 'b1@53019.com', + isPolicyExpenseChat: false, + reportID: '', + selected: true, + iouType: 'invoice', + }, + { + policyID: 'CC048FA711B35B1F', + isSender: true, + selected: false, + iouType: 'invoice', + }, + ], + tag: '', + category: '', + billable: false, + }; + const currentUserAccountID = 32; + const policy: OnyxEntry = { + id: 'CC048FA711B35B1F', + type: 'team', + name: "53019's Workspace", + role: 'admin', + owner: 'a1@53019.com', + ownerAccountID: 32, + isPolicyExpenseChatEnabled: true, + outputCurrency: 'USD', + autoReporting: true, + autoReportingFrequency: 'instant', + approvalMode: 'OPTIONAL', + harvesting: { + enabled: true, + jobID: 7206965285807173000, + }, + customUnits: { + '39C3FF491F559': { + customUnitID: '39C3FF491F559', + name: 'Distance', + attributes: { + unit: 'mi', + }, + rates: { + '928A74633831E': { + customUnitRateID: '928A74633831E', + name: 'Default Rate', + rate: 67, + enabled: true, + currency: 'USD', + }, + }, + defaultCategory: 'Car', + enabled: true, + }, + }, + areCategoriesEnabled: true, + areTagsEnabled: false, + areDistanceRatesEnabled: false, + areWorkflowsEnabled: false, + areReportFieldsEnabled: false, + areConnectionsEnabled: false, + employeeList: { + 'a1@53019.com': { + role: 'admin', + errors: {}, + email: 'a1@53019.com', + forwardsTo: '', + submitsTo: 'a1@53019.com', + }, + }, + pendingFields: {}, + chatReportIDAnnounce: 0, + chatReportIDAdmins: 1811331783036078, + address: [], + approver: 'a1@53019.com', + areCompanyCardsEnabled: false, + areExpensifyCardsEnabled: false, + areInvoicesEnabled: true, + arePerDiemRatesEnabled: false, + areRulesEnabled: false, + autoReimbursement: { + limit: 0, + }, + autoReimbursementLimit: 0, + autoReportingOffset: 1, + avatarURL: '', + defaultBillable: false, + description: '', + disabledFields: { + defaultBillable: true, + reimbursable: false, + }, + fieldList: { + text_title: { + defaultValue: '{report:type} {report:startdate}', + deletable: true, + disabledOptions: [], + externalIDs: [], + fieldID: 'text_title', + isTax: false, + keys: [], + name: 'title', + orderWeight: 0, + target: 'expense', + type: 'formula', + values: [], + }, + }, + hasMultipleTagLists: false, + invoice: { + markUp: 0, + companyName: 'b1-53019', + companyWebsite: 'https://www.53019.com', + pendingFields: {}, + bankAccount: { + stripeConnectAccountBalance: 0, + stripeConnectAccountID: 'acct_1QVeO7S7tHTCCfyY', + transferBankAccountID: 29, + }, + }, + preventSelfApproval: false, + reimbursementChoice: 'reimburseManual', + requiresCategory: false, + requiresTag: false, + tax: { + trackingEnabled: false, + }, + mccGroup: { + airlines: { + category: 'Travel', + groupID: 'airlines', + }, + commuter: { + category: 'Car', + groupID: 'commuter', + }, + gas: { + category: 'Car', + groupID: 'gas', + }, + goods: { + category: 'Materials', + groupID: 'goods', + }, + groceries: { + category: 'Meals and Entertainment', + groupID: 'groceries', + }, + hotel: { + category: 'Travel', + groupID: 'hotel', + }, + mail: { + category: 'Office Supplies', + groupID: 'mail', + }, + meals: { + category: 'Meals and Entertainment', + groupID: 'meals', + }, + rental: { + category: 'Travel', + groupID: 'rental', + }, + services: { + category: 'Professional Services', + groupID: 'services', + }, + taxi: { + category: 'Travel', + groupID: 'taxi', + }, + uncategorized: { + category: 'Other', + groupID: 'uncategorized', + }, + utilities: { + category: 'Utilities', + groupID: 'utilities', + }, + }, + rules: [], + }; + const companyName = 'b1-53019'; + const companyWebsite = 'https://www.53019.com'; + + // When getSendInvoiceInformation is called + const information = IOU.getSendInvoiceInformation(transaction, currentUserAccountID, undefined, undefined, policy, undefined, undefined, companyName, companyWebsite); + + // Then a new invoice chat/room is created + expect(information?.invoiceRoom?.reportID).not.toEqual(convertedInvoiceChat.reportID); + }); }); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 6addefe96c23..918115f3756d 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -62,6 +62,63 @@ const policy: Policy = { isPolicyExpenseChatEnabled: false, }; +const convertedInvoiceChat = { + chatType: CONST.REPORT.CHAT_TYPE.INVOICE, + currency: 'USD', + description: '', + errorFields: null, + hasOutstandingChildRequest: false, + hasOutstandingChildTask: false, + invoiceReceiver: { + accountID: 33, + policyID: '5F2F82F98C848CAA', + type: 'policy', + }, + isCancelledIOU: false, + isOwnPolicyExpenseChat: false, + isPinned: false, + isWaitingOnBankAccount: false, + lastActionType: 'REPORTPREVIEW', + lastActorAccountID: '32', + lastMessageHtml: 'paid $1.00', + lastMessageText: 'paid $1.00', + lastMessageTranslationKey: '', + lastReadSequenceNumber: 0, + lastReadTime: '2024-12-13 19:45:28.942', + lastVisibleActionCreated: '2024-12-13 19:19:01.794', + lastVisibleActionLastModified: '2024-12-13 19:19:01.794', + managerID: 0, + nonReimbursableTotal: 0, + oldPolicyName: '', + ownerAccountID: 0, + participants: { + '32': { + notificationPreference: 'always', + role: 'admin', + }, + '33': { + notificationPreference: 'always', + permissions: ['read', 'write', 'share', 'own'], + }, + }, + policyAvatar: '', + policyID: 'CC048FA711B35B1F', + policyName: "53019's Workspace", + private_isArchived: '', + reportID: '7605647250932303', + reportName: 'Chat Report', + state: 'OPEN', + stateNum: 0, + statusNum: 0, + total: 0, + type: 'chat', + unheldNonReimbursableTotal: 0, + unheldTotal: 0, + visibility: 'private', + welcomeMessage: '', + writeCapability: 'all', +}; + Onyx.init({keys: ONYXKEYS}); describe('ReportUtils', () => { @@ -1418,64 +1475,6 @@ describe('ReportUtils', () => { describe('getInvoiceChatByParticipants', () => { it('only returns an invoice chat if the receiver type matches', () => { // Given an invoice chat that has been converted from an individual to policy receiver type - const convertedInvoiceChat = { - chatType: CONST.REPORT.CHAT_TYPE.INVOICE, - currency: 'USD', - description: '', - errorFields: null, - hasOutstandingChildRequest: false, - hasOutstandingChildTask: false, - invoiceReceiver: { - accountID: 33, - policyID: '5F2F82F98C848CAA', - type: 'policy', - }, - isCancelledIOU: false, - isOwnPolicyExpenseChat: false, - isPinned: false, - isWaitingOnBankAccount: false, - lastActionType: 'REPORTPREVIEW', - lastActorAccountID: '32', - lastMessageHtml: 'paid $1.00', - lastMessageText: 'paid $1.00', - lastMessageTranslationKey: '', - lastReadSequenceNumber: 0, - lastReadTime: '2024-12-13 19:45:28.942', - lastVisibleActionCreated: '2024-12-13 19:19:01.794', - lastVisibleActionLastModified: '2024-12-13 19:19:01.794', - managerID: 0, - nonReimbursableTotal: 0, - oldPolicyName: '', - ownerAccountID: 0, - participants: { - '32': { - notificationPreference: 'always', - role: 'admin', - }, - '33': { - notificationPreference: 'always', - permissions: ['read', 'write', 'share', 'own'], - }, - }, - policyAvatar: '', - policyID: 'CC048FA711B35B1F', - policyName: "53019's Workspace", - private_isArchived: '', - reportID: '7605647250932303', - reportName: 'Chat Report', - state: 'OPEN', - stateNum: 0, - statusNum: 0, - total: 0, - type: 'chat', - unheldNonReimbursableTotal: 0, - unheldTotal: 0, - visibility: 'private', - welcomeMessage: '', - writeCapability: 'all', - }; - - // Get an Onyx collection of reports const reports: OnyxCollection = { [convertedInvoiceChat.reportID]: convertedInvoiceChat, }; @@ -1488,3 +1487,6 @@ describe('ReportUtils', () => { }); }); }); + +// eslint-disable-next-line import/prefer-default-export +export {convertedInvoiceChat}; From 3054897047fa07ccd1e1cfae66fbac61c6a595e0 Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Fri, 13 Dec 2024 14:02:42 -0800 Subject: [PATCH 04/19] WIP test via sendInvoice --- tests/actions/IOUTest.ts | 437 ++++++++++++++++++++------------------- 1 file changed, 226 insertions(+), 211 deletions(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 27c9f302de8a..1d92855ceb77 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -9,6 +9,7 @@ import * as PolicyActions from '@src/libs/actions/Policy/Policy'; import * as Report from '@src/libs/actions/Report'; import * as ReportActions from '@src/libs/actions/ReportActions'; import * as User from '@src/libs/actions/User'; +import * as API from '@src/libs/API'; import DateUtils from '@src/libs/DateUtils'; import * as Localize from '@src/libs/Localize'; import * as NumberUtils from '@src/libs/NumberUtils'; @@ -3305,231 +3306,245 @@ describe('actions/IOU', () => { }); }); - describe('getSendInvoiceInformation', () => { - // Given a convertedInvoiceReport is stored in Onyx - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${convertedInvoiceChat.reportID}`, convertedInvoiceChat); - - // And data for when a new invoice is sent to a user - const transaction: OnyxEntry = { - amount: 100, - attendees: [ - { - email: 'a1@53019.com', - login: 'a1@53019.com', - displayName: 'a1', - avatarUrl: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_9.png', - accountID: 32, - text: 'a1@53019.com', - selected: true, - reportID: '3634215302663162', - }, - ], - comment: { - customUnit: { - customUnitRateID: '_FAKE_P2P_ID_', - }, - }, - created: '2024-12-13', - currency: 'USD', - iouRequestType: 'manual', - reportID: '3634215302663162', - transactionID: '1', - isFromGlobalCreate: true, - merchant: '(none)', - splitPayerAccountIDs: [32], - shouldShowOriginalAmount: true, - participants: [ - { - accountID: 33, - login: 'b1@53019.com', - isPolicyExpenseChat: false, - reportID: '', - selected: true, - iouType: 'invoice', - }, - { - policyID: 'CC048FA711B35B1F', - isSender: true, - selected: false, - iouType: 'invoice', + describe('sendInvoice', () => { + it('creates a new invoice chat when one has been converted from individual to business', async () => { + // Mock API.write for this test + const writeSpy = jest.spyOn(API, 'write').mockImplementation(jest.fn()); + + // Given a convertedInvoiceReport is stored in Onyx + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${convertedInvoiceChat.reportID}`, convertedInvoiceChat); + + // And data for when a new invoice is sent to a user + const transaction: OnyxEntry = { + amount: 100, + attendees: [ + { + email: 'a1@53019.com', + login: 'a1@53019.com', + displayName: 'a1', + avatarUrl: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_9.png', + accountID: 32, + text: 'a1@53019.com', + selected: true, + reportID: '3634215302663162', + }, + ], + comment: { + customUnit: { + customUnitRateID: '_FAKE_P2P_ID_', + }, }, - ], - tag: '', - category: '', - billable: false, - }; - const currentUserAccountID = 32; - const policy: OnyxEntry = { - id: 'CC048FA711B35B1F', - type: 'team', - name: "53019's Workspace", - role: 'admin', - owner: 'a1@53019.com', - ownerAccountID: 32, - isPolicyExpenseChatEnabled: true, - outputCurrency: 'USD', - autoReporting: true, - autoReportingFrequency: 'instant', - approvalMode: 'OPTIONAL', - harvesting: { - enabled: true, - jobID: 7206965285807173000, - }, - customUnits: { - '39C3FF491F559': { - customUnitID: '39C3FF491F559', - name: 'Distance', - attributes: { - unit: 'mi', + created: '2024-12-13', + currency: 'USD', + iouRequestType: 'manual', + reportID: '3634215302663162', + transactionID: '1', + isFromGlobalCreate: true, + merchant: '(none)', + splitPayerAccountIDs: [32], + shouldShowOriginalAmount: true, + participants: [ + { + accountID: 33, + login: 'b1@53019.com', + isPolicyExpenseChat: false, + reportID: '', + selected: true, + iouType: 'invoice', }, - rates: { - '928A74633831E': { - customUnitRateID: '928A74633831E', - name: 'Default Rate', - rate: 67, - enabled: true, - currency: 'USD', - }, + { + policyID: 'CC048FA711B35B1F', + isSender: true, + selected: false, + iouType: 'invoice', }, - defaultCategory: 'Car', + ], + tag: '', + category: '', + billable: false, + }; + const currentUserAccountID = 32; + const policy: OnyxEntry = { + id: 'CC048FA711B35B1F', + type: 'team', + name: "53019's Workspace", + role: 'admin', + owner: 'a1@53019.com', + ownerAccountID: 32, + isPolicyExpenseChatEnabled: true, + outputCurrency: 'USD', + autoReporting: true, + autoReportingFrequency: 'instant', + approvalMode: 'OPTIONAL', + harvesting: { enabled: true, + jobID: 7206965285807173000, }, - }, - areCategoriesEnabled: true, - areTagsEnabled: false, - areDistanceRatesEnabled: false, - areWorkflowsEnabled: false, - areReportFieldsEnabled: false, - areConnectionsEnabled: false, - employeeList: { - 'a1@53019.com': { - role: 'admin', - errors: {}, - email: 'a1@53019.com', - forwardsTo: '', - submitsTo: 'a1@53019.com', + customUnits: { + '39C3FF491F559': { + customUnitID: '39C3FF491F559', + name: 'Distance', + attributes: { + unit: 'mi', + }, + rates: { + '928A74633831E': { + customUnitRateID: '928A74633831E', + name: 'Default Rate', + rate: 67, + enabled: true, + currency: 'USD', + }, + }, + defaultCategory: 'Car', + enabled: true, + }, }, - }, - pendingFields: {}, - chatReportIDAnnounce: 0, - chatReportIDAdmins: 1811331783036078, - address: [], - approver: 'a1@53019.com', - areCompanyCardsEnabled: false, - areExpensifyCardsEnabled: false, - areInvoicesEnabled: true, - arePerDiemRatesEnabled: false, - areRulesEnabled: false, - autoReimbursement: { - limit: 0, - }, - autoReimbursementLimit: 0, - autoReportingOffset: 1, - avatarURL: '', - defaultBillable: false, - description: '', - disabledFields: { - defaultBillable: true, - reimbursable: false, - }, - fieldList: { - text_title: { - defaultValue: '{report:type} {report:startdate}', - deletable: true, - disabledOptions: [], - externalIDs: [], - fieldID: 'text_title', - isTax: false, - keys: [], - name: 'title', - orderWeight: 0, - target: 'expense', - type: 'formula', - values: [], + areCategoriesEnabled: true, + areTagsEnabled: false, + areDistanceRatesEnabled: false, + areWorkflowsEnabled: false, + areReportFieldsEnabled: false, + areConnectionsEnabled: false, + employeeList: { + 'a1@53019.com': { + role: 'admin', + errors: {}, + email: 'a1@53019.com', + forwardsTo: '', + submitsTo: 'a1@53019.com', + }, }, - }, - hasMultipleTagLists: false, - invoice: { - markUp: 0, - companyName: 'b1-53019', - companyWebsite: 'https://www.53019.com', pendingFields: {}, - bankAccount: { - stripeConnectAccountBalance: 0, - stripeConnectAccountID: 'acct_1QVeO7S7tHTCCfyY', - transferBankAccountID: 29, + chatReportIDAnnounce: 0, + chatReportIDAdmins: 1811331783036078, + address: [], + approver: 'a1@53019.com', + areCompanyCardsEnabled: false, + areExpensifyCardsEnabled: false, + areInvoicesEnabled: true, + arePerDiemRatesEnabled: false, + areRulesEnabled: false, + autoReimbursement: { + limit: 0, }, - }, - preventSelfApproval: false, - reimbursementChoice: 'reimburseManual', - requiresCategory: false, - requiresTag: false, - tax: { - trackingEnabled: false, - }, - mccGroup: { - airlines: { - category: 'Travel', - groupID: 'airlines', + autoReimbursementLimit: 0, + autoReportingOffset: 1, + avatarURL: '', + defaultBillable: false, + description: '', + disabledFields: { + defaultBillable: true, + reimbursable: false, }, - commuter: { - category: 'Car', - groupID: 'commuter', - }, - gas: { - category: 'Car', - groupID: 'gas', - }, - goods: { - category: 'Materials', - groupID: 'goods', - }, - groceries: { - category: 'Meals and Entertainment', - groupID: 'groceries', - }, - hotel: { - category: 'Travel', - groupID: 'hotel', - }, - mail: { - category: 'Office Supplies', - groupID: 'mail', - }, - meals: { - category: 'Meals and Entertainment', - groupID: 'meals', - }, - rental: { - category: 'Travel', - groupID: 'rental', - }, - services: { - category: 'Professional Services', - groupID: 'services', + fieldList: { + text_title: { + defaultValue: '{report:type} {report:startdate}', + deletable: true, + disabledOptions: [], + externalIDs: [], + fieldID: 'text_title', + isTax: false, + keys: [], + name: 'title', + orderWeight: 0, + target: 'expense', + type: 'formula', + values: [], + }, }, - taxi: { - category: 'Travel', - groupID: 'taxi', + hasMultipleTagLists: false, + invoice: { + markUp: 0, + companyName: 'b1-53019', + companyWebsite: 'https://www.53019.com', + pendingFields: {}, + bankAccount: { + stripeConnectAccountBalance: 0, + stripeConnectAccountID: 'acct_1QVeO7S7tHTCCfyY', + transferBankAccountID: 29, + }, }, - uncategorized: { - category: 'Other', - groupID: 'uncategorized', + preventSelfApproval: false, + reimbursementChoice: 'reimburseManual', + requiresCategory: false, + requiresTag: false, + tax: { + trackingEnabled: false, }, - utilities: { - category: 'Utilities', - groupID: 'utilities', + mccGroup: { + airlines: { + category: 'Travel', + groupID: 'airlines', + }, + commuter: { + category: 'Car', + groupID: 'commuter', + }, + gas: { + category: 'Car', + groupID: 'gas', + }, + goods: { + category: 'Materials', + groupID: 'goods', + }, + groceries: { + category: 'Meals and Entertainment', + groupID: 'groceries', + }, + hotel: { + category: 'Travel', + groupID: 'hotel', + }, + mail: { + category: 'Office Supplies', + groupID: 'mail', + }, + meals: { + category: 'Meals and Entertainment', + groupID: 'meals', + }, + rental: { + category: 'Travel', + groupID: 'rental', + }, + services: { + category: 'Professional Services', + groupID: 'services', + }, + taxi: { + category: 'Travel', + groupID: 'taxi', + }, + uncategorized: { + category: 'Other', + groupID: 'uncategorized', + }, + utilities: { + category: 'Utilities', + groupID: 'utilities', + }, }, - }, - rules: [], - }; - const companyName = 'b1-53019'; - const companyWebsite = 'https://www.53019.com'; - - // When getSendInvoiceInformation is called - const information = IOU.getSendInvoiceInformation(transaction, currentUserAccountID, undefined, undefined, policy, undefined, undefined, companyName, companyWebsite); + rules: [], + }; + const companyName = 'b1-53019'; + const companyWebsite = 'https://www.53019.com'; + + IOU.sendInvoice(currentUserAccountID, transaction, undefined, undefined, policy, undefined, undefined, companyName, companyWebsite); + + // Assert that API.write has been called with parameters where the parameters.invoiceRoomReportID is not the same as the convertedInvoiceChat.reportID + expect(writeSpy).toHaveBeenCalledWith( + expect.anything(), + expect.objectContaining({ + invoiceRoomReportID: expect.not.stringMatching(convertedInvoiceChat.reportID), + }), + expect.anything(), + expect.anything(), + ); - // Then a new invoice chat/room is created - expect(information?.invoiceRoom?.reportID).not.toEqual(convertedInvoiceChat.reportID); + // Restore the original implementation + writeSpy.mockRestore(); + }); }); }); From 401f5debd7cbe83e0ed9378c320930541c21ec72 Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Fri, 13 Dec 2024 14:32:52 -0800 Subject: [PATCH 05/19] Fix test, remove extra expected param --- tests/actions/IOUTest.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 1d92855ceb77..a28ab0a5b3e8 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -3540,7 +3540,6 @@ describe('actions/IOU', () => { invoiceRoomReportID: expect.not.stringMatching(convertedInvoiceChat.reportID), }), expect.anything(), - expect.anything(), ); // Restore the original implementation From 3d11b6c9adf485ed141c07b4c244ba3b3381878a Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Fri, 13 Dec 2024 14:33:03 -0800 Subject: [PATCH 06/19] Pass proper invoice receiver type --- src/libs/actions/IOU.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index c094873379b9..1ba31d09438a 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -39,6 +39,7 @@ import GoogleTagManager from '@libs/GoogleTagManager'; import * as IOUUtils from '@libs/IOUUtils'; import * as LocalePhoneNumber from '@libs/LocalePhoneNumber'; import * as Localize from '@libs/Localize'; +import Log from '@libs/Log'; import isSearchTopmostCentralPane from '@libs/Navigation/isSearchTopmostCentralPane'; import Navigation from '@libs/Navigation/Navigation'; import * as NextStepUtils from '@libs/NextStepUtils'; @@ -65,6 +66,7 @@ import type * as OnyxTypes from '@src/types/onyx'; import type {Attendee, Participant, Split} from '@src/types/onyx/IOU'; import type {ErrorFields, Errors} from '@src/types/onyx/OnyxCommon'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; +import {InvoiceReceiver, InvoiceReceiverType} from '@src/types/onyx/Report'; import type ReportAction from '@src/types/onyx/ReportAction'; import type {OnyxData} from '@src/types/onyx/Request'; import type {SearchPolicy, SearchReport, SearchTransaction} from '@src/types/onyx/SearchResults'; @@ -2037,6 +2039,20 @@ function getDeleteTrackExpenseInformation( return {parameters, optimisticData, successData, failureData, shouldDeleteTransactionThread, chatReport}; } +function getReceiverType(receiverParticipant: Participant | InvoiceReceiver | undefined): InvoiceReceiverType { + if (!receiverParticipant) { + Log.warn('getReceiverType called with no receiverParticipant'); + return CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL; + } + if ('type' in receiverParticipant && receiverParticipant.type) { + return receiverParticipant.type; + } + if ('policyID' in receiverParticipant && receiverParticipant.policyID) { + return CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS; + } + return CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL; +} + /** Gathers all the data needed to create an invoice. */ function getSendInvoiceInformation( transaction: OnyxEntry, @@ -2052,17 +2068,18 @@ function getSendInvoiceInformation( const {amount = 0, currency = '', created = '', merchant = '', category = '', tag = '', taxCode = '', taxAmount = 0, billable, comment, participants} = transaction ?? {}; const trimmedComment = (comment?.comment ?? '').trim(); const senderWorkspaceID = participants?.find((participant) => participant?.isSender)?.policyID ?? '-1'; - const receiverParticipant = participants?.find((participant) => participant?.accountID) ?? invoiceChatReport?.invoiceReceiver; + const receiverParticipant: Participant | InvoiceReceiver | undefined = participants?.find((participant) => participant?.accountID) ?? invoiceChatReport?.invoiceReceiver; const receiverAccountID = receiverParticipant && 'accountID' in receiverParticipant && receiverParticipant.accountID ? receiverParticipant.accountID : -1; let receiver = ReportUtils.getPersonalDetailsForAccountID(receiverAccountID); let optimisticPersonalDetailListAction = {}; + const receiverType = getReceiverType(receiverParticipant); // STEP 1: Get existing chat report OR build a new optimistic one let isNewChatReport = false; let chatReport = !isEmptyObject(invoiceChatReport) && invoiceChatReport?.reportID ? invoiceChatReport : null; if (!chatReport) { - chatReport = ReportUtils.getInvoiceChatByParticipants(senderWorkspaceID, receiverAccountID) ?? null; + chatReport = ReportUtils.getInvoiceChatByParticipants(senderWorkspaceID, receiverAccountID, receiverType) ?? null; } if (!chatReport) { @@ -6827,7 +6844,7 @@ function getPayMoneyRequestParams( } if (ReportUtils.isIndividualInvoiceRoom(chatReport) && payAsBusiness && activePolicyID) { - const existingB2BInvoiceRoom = ReportUtils.getInvoiceChatByParticipants(chatReport.policyID ?? '', activePolicyID); + const existingB2BInvoiceRoom = ReportUtils.getInvoiceChatByParticipants(chatReport.policyID ?? '', activePolicyID, CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL); if (existingB2BInvoiceRoom) { chatReport = existingB2BInvoiceRoom; } From 03c9bf995709d3a9aa6d59063c9ca9026fd7555c Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Fri, 13 Dec 2024 15:02:55 -0800 Subject: [PATCH 07/19] WIP fix some types --- src/types/onyx/Policy.ts | 24 ++++++++++++++++-------- src/types/onyx/Report.ts | 2 +- tests/actions/IOUTest.ts | 4 +++- tests/unit/ReportUtilsTest.ts | 12 ++++++++---- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index 672816e1fa6b..86f4a1aaad38 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -1491,9 +1491,15 @@ type PolicyInvoicingDetails = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** Account balance */ stripeConnectAccountBalance?: number; + /** AccountID */ + stripeConnectAccountID?: string; + /** bankAccountID of selected BBA for payouts */ transferBankAccountID?: number; }; + + /** The markUp */ + markUp?: number; }>; /** Names of policy features */ @@ -1593,7 +1599,7 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< outputCurrency: string; /** The address of the company */ - address?: CompanyAddress; + address?: CompanyAddress | []; /** The URL for the policy avatar */ avatarURL?: string; @@ -1742,13 +1748,15 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< taxRates?: TaxRatesWithDefault; /** A set of rules related to the workpsace */ - rules?: { - /** A set of rules related to the workpsace approvals */ - approvalRules?: ApprovalRule[]; - - /** A set of rules related to the workpsace expenses */ - expenseRules?: ExpenseRule[]; - }; + rules?: + | { + /** A set of rules related to the workpsace approvals */ + approvalRules?: ApprovalRule[]; + + /** A set of rules related to the workpsace expenses */ + expenseRules?: ExpenseRule[]; + } + | []; /** ReportID of the admins room for this workspace */ chatReportIDAdmins?: number; diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index 7f652904f0cb..f552c5eeaef4 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -194,7 +194,7 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< currency?: string; /** Collection of errors that exist in report fields */ - errorFields?: OnyxCommon.ErrorFields; + errorFields?: OnyxCommon.ErrorFields | null; /** Whether the report is waiting on a bank account */ isWaitingOnBankAccount?: boolean; diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index a28ab0a5b3e8..9b75a5d9be63 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -3407,6 +3407,7 @@ describe('actions/IOU', () => { areReportFieldsEnabled: false, areConnectionsEnabled: false, employeeList: { + // eslint-disable-next-line @typescript-eslint/naming-convention 'a1@53019.com': { role: 'admin', errors: {}, @@ -3438,6 +3439,7 @@ describe('actions/IOU', () => { reimbursable: false, }, fieldList: { + // eslint-disable-next-line @typescript-eslint/naming-convention text_title: { defaultValue: '{report:type} {report:startdate}', deletable: true, @@ -3537,7 +3539,7 @@ describe('actions/IOU', () => { expect(writeSpy).toHaveBeenCalledWith( expect.anything(), expect.objectContaining({ - invoiceRoomReportID: expect.not.stringMatching(convertedInvoiceChat.reportID), + invoiceRoomReportID: expect.not.stringMatching(convertedInvoiceChat?.reportID ?? ''), }), expect.anything(), ); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 918115f3756d..5ff3a73b3089 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -8,6 +8,7 @@ import CONST from '@src/CONST'; import * as TransactionUtils from '@src/libs/TransactionUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetailsList, Policy, Report, ReportAction} from '@src/types/onyx'; +import type {InvoiceReceiver} from '@src/types/onyx/Report'; import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet'; import * as NumberUtils from '../../src/libs/NumberUtils'; import * as LHNTestUtils from '../utils/LHNTestUtils'; @@ -62,24 +63,27 @@ const policy: Policy = { isPolicyExpenseChatEnabled: false, }; -const convertedInvoiceChat = { +const convertedInvoiceChat: OnyxEntry = { chatType: CONST.REPORT.CHAT_TYPE.INVOICE, currency: 'USD', description: '', errorFields: null, hasOutstandingChildRequest: false, hasOutstandingChildTask: false, + + // The invoice receiver shouldn't have an accountID when the type is business, + // but this is to test that it still works if the value is present invoiceReceiver: { accountID: 33, policyID: '5F2F82F98C848CAA', type: 'policy', - }, + } as unknown as InvoiceReceiver, isCancelledIOU: false, isOwnPolicyExpenseChat: false, isPinned: false, isWaitingOnBankAccount: false, lastActionType: 'REPORTPREVIEW', - lastActorAccountID: '32', + lastActorAccountID: 32, lastMessageHtml: 'paid $1.00', lastMessageText: 'paid $1.00', lastMessageTranslationKey: '', @@ -98,7 +102,7 @@ const convertedInvoiceChat = { }, '33': { notificationPreference: 'always', - permissions: ['read', 'write', 'share', 'own'], + permissions: [CONST.REPORT.PERMISSIONS.READ, CONST.REPORT.PERMISSIONS.WRITE, CONST.REPORT.PERMISSIONS.SHARE, CONST.REPORT.PERMISSIONS.OWN], }, }, policyAvatar: '', From 0c6e50d49b1ba5caa4a16290042bb2efb38c7d16 Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Fri, 13 Dec 2024 17:08:39 -0800 Subject: [PATCH 08/19] Add doc comment to make function more clear --- src/libs/actions/IOU.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 1ba31d09438a..8d072ab459aa 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -2039,6 +2039,11 @@ function getDeleteTrackExpenseInformation( return {parameters, optimisticData, successData, failureData, shouldDeleteTransactionThread, chatReport}; } +/** + * Get the invoice receiver type based on the receiver participant. + * @param receiverParticipant The participant who will receive the invoice or the invoice receiver object directly. + * @returns The invoice receiver type. + */ function getReceiverType(receiverParticipant: Participant | InvoiceReceiver | undefined): InvoiceReceiverType { if (!receiverParticipant) { Log.warn('getReceiverType called with no receiverParticipant'); From a2bbb544b91ea2e3e62765d98a056778eacacd15 Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Fri, 13 Dec 2024 17:10:25 -0800 Subject: [PATCH 09/19] Fix receiver type getting B2B invoice room --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 8d072ab459aa..04671ac2fa04 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -6849,7 +6849,7 @@ function getPayMoneyRequestParams( } if (ReportUtils.isIndividualInvoiceRoom(chatReport) && payAsBusiness && activePolicyID) { - const existingB2BInvoiceRoom = ReportUtils.getInvoiceChatByParticipants(chatReport.policyID ?? '', activePolicyID, CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL); + const existingB2BInvoiceRoom = ReportUtils.getInvoiceChatByParticipants(chatReport.policyID ?? '', activePolicyID, CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS); if (existingB2BInvoiceRoom) { chatReport = existingB2BInvoiceRoom; } From 410868e8337526a27f7ab4f83c367edd9f33ae53 Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Fri, 13 Dec 2024 18:03:54 -0800 Subject: [PATCH 10/19] Major clean up of tests and types and lint --- src/libs/ReportUtils.ts | 2 +- src/libs/actions/IOU.ts | 4 +- src/types/onyx/Policy.ts | 3 + src/types/onyx/Report.ts | 13 +- tests/actions/IOUTest.ts | 225 +------------------------- tests/data/Invoice.ts | 295 ++++++++++++++++++++++++++++++++++ tests/unit/ReportUtilsTest.ts | 67 +------- 7 files changed, 321 insertions(+), 288 deletions(-) create mode 100644 tests/data/Invoice.ts diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 25a8055bc747..59f6effc63d4 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6746,7 +6746,7 @@ function getChatByParticipants(newParticipantList: number[], reports: OnyxCollec /** * Attempts to find an invoice chat report in onyx with the provided policyID and receiverID. */ -function getInvoiceChatByParticipants(policyID: string, receiverID: string | number, receiverType: InvoiceReceiverType, reports: OnyxCollection = allReports): OnyxEntry { +function getInvoiceChatByParticipants(receiverID: string | number, receiverType: InvoiceReceiverType, policyID?: string, reports: OnyxCollection = allReports): OnyxEntry { return Object.values(reports ?? {}).find((report) => { if (!report || !isInvoiceRoom(report) || isArchivedRoom(report)) { return false; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 04671ac2fa04..9d4aa640aeb1 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -2084,7 +2084,7 @@ function getSendInvoiceInformation( let chatReport = !isEmptyObject(invoiceChatReport) && invoiceChatReport?.reportID ? invoiceChatReport : null; if (!chatReport) { - chatReport = ReportUtils.getInvoiceChatByParticipants(senderWorkspaceID, receiverAccountID, receiverType) ?? null; + chatReport = ReportUtils.getInvoiceChatByParticipants(receiverAccountID, receiverType, senderWorkspaceID) ?? null; } if (!chatReport) { @@ -6849,7 +6849,7 @@ function getPayMoneyRequestParams( } if (ReportUtils.isIndividualInvoiceRoom(chatReport) && payAsBusiness && activePolicyID) { - const existingB2BInvoiceRoom = ReportUtils.getInvoiceChatByParticipants(chatReport.policyID ?? '', activePolicyID, CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS); + const existingB2BInvoiceRoom = ReportUtils.getInvoiceChatByParticipants(activePolicyID, CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS, chatReport.policyID); if (existingB2BInvoiceRoom) { chatReport = existingB2BInvoiceRoom; } diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index 86f4a1aaad38..2873a80b1d52 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -1636,6 +1636,9 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< harvesting?: { /** Whether the scheduled submit is enabled */ enabled: boolean; + + /** The ID of the Bedrock job that runs harvesting */ + jobID: number; }; /** Whether the self approval or submitting is enabled */ diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index f552c5eeaef4..ea6fa5d33c3a 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -42,6 +42,9 @@ type Participant = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** Whether the participant is visible in the report */ notificationPreference: NotificationPreference; + + /** Permissions granted to the participant */ + permissions?: Array>; }>; /** Types of invoice receivers in a report */ @@ -133,10 +136,13 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< /** ID of the chat report */ chatReportID?: string; - /** The state that the report is currently in */ + /** The state of the report */ + state?: keyof typeof CONST.REPORT.STATE_NUM; + + /** The state number of the report */ stateNum?: ValueOf; - /** The status of the current report */ + /** The state that the report is currently in */ statusNum?: ValueOf; /** Which user role is capable of posting messages on the report */ @@ -238,6 +244,9 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< /** Whether the report is archived */ // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived?: string; + + /** The report's welcome message */ + welcomeMessage?: string; }, 'addWorkspaceRoom' | 'avatar' | 'createChat' | 'partial' | 'reimbursed' | 'preview' >; diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 9b75a5d9be63..e74b380b7b02 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -22,7 +22,8 @@ import type * as OnyxTypes from '@src/types/onyx'; import type {Participant} from '@src/types/onyx/Report'; import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; -import {convertedInvoiceChat} from '../unit/ReportUtilsTest'; +import * as InvoiceData from '../data/Invoice'; +import type {InvoiceTestData} from '../data/Invoice'; import PusherHelper from '../utils/PusherHelper'; import type {MockFetch} from '../utils/TestHelper'; import * as TestHelper from '../utils/TestHelper'; @@ -3312,234 +3313,22 @@ describe('actions/IOU', () => { const writeSpy = jest.spyOn(API, 'write').mockImplementation(jest.fn()); // Given a convertedInvoiceReport is stored in Onyx - await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${convertedInvoiceChat.reportID}`, convertedInvoiceChat); + const {policy, transaction, convertedInvoiceChat}: InvoiceTestData = InvoiceData; + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${convertedInvoiceChat?.reportID}`, convertedInvoiceChat ?? {}); // And data for when a new invoice is sent to a user - const transaction: OnyxEntry = { - amount: 100, - attendees: [ - { - email: 'a1@53019.com', - login: 'a1@53019.com', - displayName: 'a1', - avatarUrl: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_9.png', - accountID: 32, - text: 'a1@53019.com', - selected: true, - reportID: '3634215302663162', - }, - ], - comment: { - customUnit: { - customUnitRateID: '_FAKE_P2P_ID_', - }, - }, - created: '2024-12-13', - currency: 'USD', - iouRequestType: 'manual', - reportID: '3634215302663162', - transactionID: '1', - isFromGlobalCreate: true, - merchant: '(none)', - splitPayerAccountIDs: [32], - shouldShowOriginalAmount: true, - participants: [ - { - accountID: 33, - login: 'b1@53019.com', - isPolicyExpenseChat: false, - reportID: '', - selected: true, - iouType: 'invoice', - }, - { - policyID: 'CC048FA711B35B1F', - isSender: true, - selected: false, - iouType: 'invoice', - }, - ], - tag: '', - category: '', - billable: false, - }; const currentUserAccountID = 32; - const policy: OnyxEntry = { - id: 'CC048FA711B35B1F', - type: 'team', - name: "53019's Workspace", - role: 'admin', - owner: 'a1@53019.com', - ownerAccountID: 32, - isPolicyExpenseChatEnabled: true, - outputCurrency: 'USD', - autoReporting: true, - autoReportingFrequency: 'instant', - approvalMode: 'OPTIONAL', - harvesting: { - enabled: true, - jobID: 7206965285807173000, - }, - customUnits: { - '39C3FF491F559': { - customUnitID: '39C3FF491F559', - name: 'Distance', - attributes: { - unit: 'mi', - }, - rates: { - '928A74633831E': { - customUnitRateID: '928A74633831E', - name: 'Default Rate', - rate: 67, - enabled: true, - currency: 'USD', - }, - }, - defaultCategory: 'Car', - enabled: true, - }, - }, - areCategoriesEnabled: true, - areTagsEnabled: false, - areDistanceRatesEnabled: false, - areWorkflowsEnabled: false, - areReportFieldsEnabled: false, - areConnectionsEnabled: false, - employeeList: { - // eslint-disable-next-line @typescript-eslint/naming-convention - 'a1@53019.com': { - role: 'admin', - errors: {}, - email: 'a1@53019.com', - forwardsTo: '', - submitsTo: 'a1@53019.com', - }, - }, - pendingFields: {}, - chatReportIDAnnounce: 0, - chatReportIDAdmins: 1811331783036078, - address: [], - approver: 'a1@53019.com', - areCompanyCardsEnabled: false, - areExpensifyCardsEnabled: false, - areInvoicesEnabled: true, - arePerDiemRatesEnabled: false, - areRulesEnabled: false, - autoReimbursement: { - limit: 0, - }, - autoReimbursementLimit: 0, - autoReportingOffset: 1, - avatarURL: '', - defaultBillable: false, - description: '', - disabledFields: { - defaultBillable: true, - reimbursable: false, - }, - fieldList: { - // eslint-disable-next-line @typescript-eslint/naming-convention - text_title: { - defaultValue: '{report:type} {report:startdate}', - deletable: true, - disabledOptions: [], - externalIDs: [], - fieldID: 'text_title', - isTax: false, - keys: [], - name: 'title', - orderWeight: 0, - target: 'expense', - type: 'formula', - values: [], - }, - }, - hasMultipleTagLists: false, - invoice: { - markUp: 0, - companyName: 'b1-53019', - companyWebsite: 'https://www.53019.com', - pendingFields: {}, - bankAccount: { - stripeConnectAccountBalance: 0, - stripeConnectAccountID: 'acct_1QVeO7S7tHTCCfyY', - transferBankAccountID: 29, - }, - }, - preventSelfApproval: false, - reimbursementChoice: 'reimburseManual', - requiresCategory: false, - requiresTag: false, - tax: { - trackingEnabled: false, - }, - mccGroup: { - airlines: { - category: 'Travel', - groupID: 'airlines', - }, - commuter: { - category: 'Car', - groupID: 'commuter', - }, - gas: { - category: 'Car', - groupID: 'gas', - }, - goods: { - category: 'Materials', - groupID: 'goods', - }, - groceries: { - category: 'Meals and Entertainment', - groupID: 'groceries', - }, - hotel: { - category: 'Travel', - groupID: 'hotel', - }, - mail: { - category: 'Office Supplies', - groupID: 'mail', - }, - meals: { - category: 'Meals and Entertainment', - groupID: 'meals', - }, - rental: { - category: 'Travel', - groupID: 'rental', - }, - services: { - category: 'Professional Services', - groupID: 'services', - }, - taxi: { - category: 'Travel', - groupID: 'taxi', - }, - uncategorized: { - category: 'Other', - groupID: 'uncategorized', - }, - utilities: { - category: 'Utilities', - groupID: 'utilities', - }, - }, - rules: [], - }; const companyName = 'b1-53019'; const companyWebsite = 'https://www.53019.com'; + // When the user sends a new invoice to an individual IOU.sendInvoice(currentUserAccountID, transaction, undefined, undefined, policy, undefined, undefined, companyName, companyWebsite); - // Assert that API.write has been called with parameters where the parameters.invoiceRoomReportID is not the same as the convertedInvoiceChat.reportID + // Then a new invoice chat is created instead of incorrectly using the invoice chat which has been converted from individual to business expect(writeSpy).toHaveBeenCalledWith( expect.anything(), expect.objectContaining({ - invoiceRoomReportID: expect.not.stringMatching(convertedInvoiceChat?.reportID ?? ''), + invoiceRoomReportID: expect.not.stringMatching(convertedInvoiceChat.reportID), }), expect.anything(), ); diff --git a/tests/data/Invoice.ts b/tests/data/Invoice.ts new file mode 100644 index 000000000000..24ae87f451fe --- /dev/null +++ b/tests/data/Invoice.ts @@ -0,0 +1,295 @@ +// Test data for Invoices. The values come from the Onyx store in the app while manually testing. +import type {OnyxEntry} from 'react-native-onyx'; +import CONST from '@src/CONST'; +import type * as OnyxTypes from '@src/types/onyx'; +import type {InvoiceReceiver} from '@src/types/onyx/Report'; + +const policy: OnyxEntry = { + id: 'CC048FA711B35B1F', + type: 'team', + name: "53019's Workspace", + role: 'admin', + owner: 'a1@53019.com', + ownerAccountID: 32, + isPolicyExpenseChatEnabled: true, + outputCurrency: 'USD', + autoReporting: true, + autoReportingFrequency: 'instant', + approvalMode: 'OPTIONAL', + harvesting: { + enabled: true, + jobID: 7206965285807173000, + }, + customUnits: { + // eslint-disable-next-line @typescript-eslint/naming-convention + '39C3FF491F559': { + customUnitID: '39C3FF491F559', + name: 'Distance', + attributes: { + unit: 'mi', + }, + rates: { + // eslint-disable-next-line @typescript-eslint/naming-convention + '928A74633831E': { + customUnitRateID: '928A74633831E', + name: 'Default Rate', + rate: 67, + enabled: true, + currency: 'USD', + }, + }, + defaultCategory: 'Car', + enabled: true, + }, + }, + areCategoriesEnabled: true, + areTagsEnabled: false, + areDistanceRatesEnabled: false, + areWorkflowsEnabled: false, + areReportFieldsEnabled: false, + areConnectionsEnabled: false, + employeeList: { + // eslint-disable-next-line @typescript-eslint/naming-convention + 'a1@53019.com': { + role: 'admin', + errors: {}, + email: 'a1@53019.com', + forwardsTo: '', + submitsTo: 'a1@53019.com', + }, + }, + pendingFields: {}, + chatReportIDAnnounce: 0, + chatReportIDAdmins: 1811331783036078, + address: [], + approver: 'a1@53019.com', + areCompanyCardsEnabled: false, + areExpensifyCardsEnabled: false, + areInvoicesEnabled: true, + arePerDiemRatesEnabled: false, + areRulesEnabled: false, + autoReimbursement: { + limit: 0, + }, + autoReimbursementLimit: 0, + autoReportingOffset: 1, + avatarURL: '', + defaultBillable: false, + description: '', + disabledFields: { + defaultBillable: true, + reimbursable: false, + }, + fieldList: { + // eslint-disable-next-line @typescript-eslint/naming-convention + text_title: { + defaultValue: '{report:type} {report:startdate}', + deletable: true, + disabledOptions: [], + externalIDs: [], + fieldID: 'text_title', + isTax: false, + keys: [], + name: 'title', + orderWeight: 0, + target: 'expense', + type: 'formula', + values: [], + }, + }, + hasMultipleTagLists: false, + invoice: { + markUp: 0, + companyName: 'b1-53019', + companyWebsite: 'https://www.53019.com', + pendingFields: {}, + bankAccount: { + stripeConnectAccountBalance: 0, + stripeConnectAccountID: 'acct_1QVeO7S7tHTCCfyY', + transferBankAccountID: 29, + }, + }, + preventSelfApproval: false, + reimbursementChoice: 'reimburseManual', + requiresCategory: false, + requiresTag: false, + tax: { + trackingEnabled: false, + }, + mccGroup: { + airlines: { + category: 'Travel', + groupID: 'airlines', + }, + commuter: { + category: 'Car', + groupID: 'commuter', + }, + gas: { + category: 'Car', + groupID: 'gas', + }, + goods: { + category: 'Materials', + groupID: 'goods', + }, + groceries: { + category: 'Meals and Entertainment', + groupID: 'groceries', + }, + hotel: { + category: 'Travel', + groupID: 'hotel', + }, + mail: { + category: 'Office Supplies', + groupID: 'mail', + }, + meals: { + category: 'Meals and Entertainment', + groupID: 'meals', + }, + rental: { + category: 'Travel', + groupID: 'rental', + }, + services: { + category: 'Professional Services', + groupID: 'services', + }, + taxi: { + category: 'Travel', + groupID: 'taxi', + }, + uncategorized: { + category: 'Other', + groupID: 'uncategorized', + }, + utilities: { + category: 'Utilities', + groupID: 'utilities', + }, + }, + rules: [], +}; + +const transaction: OnyxEntry = { + amount: 100, + attendees: [ + { + email: 'a1@53019.com', + login: 'a1@53019.com', + displayName: 'a1', + avatarUrl: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_9.png', + accountID: 32, + text: 'a1@53019.com', + selected: true, + reportID: '3634215302663162', + }, + ], + comment: { + customUnit: { + customUnitRateID: '_FAKE_P2P_ID_', + }, + }, + created: '2024-12-13', + currency: 'USD', + iouRequestType: 'manual', + reportID: '3634215302663162', + transactionID: '1', + isFromGlobalCreate: true, + merchant: '(none)', + splitPayerAccountIDs: [32], + shouldShowOriginalAmount: true, + participants: [ + { + accountID: 33, + login: 'b1@53019.com', + isPolicyExpenseChat: false, + reportID: '', + selected: true, + iouType: 'invoice', + }, + { + policyID: 'CC048FA711B35B1F', + isSender: true, + selected: false, + iouType: 'invoice', + }, + ], + tag: '', + category: '', + billable: false, +}; + +const convertedInvoiceChat: OnyxTypes.Report = { + chatType: CONST.REPORT.CHAT_TYPE.INVOICE, + currency: 'USD', + description: '', + errorFields: null, + hasOutstandingChildRequest: false, + hasOutstandingChildTask: false, + + // The invoice receiver shouldn't have an accountID when the type is business, + // but this is to test that it still works if the value is present, so cast it to unknown + invoiceReceiver: { + accountID: 33, + policyID: '5F2F82F98C848CAA', + type: 'policy', + } as unknown as InvoiceReceiver, + isCancelledIOU: false, + isOwnPolicyExpenseChat: false, + isPinned: false, + isWaitingOnBankAccount: false, + lastActionType: 'REPORTPREVIEW', + lastActorAccountID: 32, + lastMessageHtml: 'paid $1.00', + lastMessageText: 'paid $1.00', + lastMessageTranslationKey: '', + lastReadSequenceNumber: 0, + lastReadTime: '2024-12-13 19:45:28.942', + lastVisibleActionCreated: '2024-12-13 19:19:01.794', + lastVisibleActionLastModified: '2024-12-13 19:19:01.794', + managerID: 0, + nonReimbursableTotal: 0, + oldPolicyName: '', + ownerAccountID: 0, + participants: { + // eslint-disable-next-line @typescript-eslint/naming-convention + '32': { + notificationPreference: 'always', + role: 'admin', + }, + // eslint-disable-next-line @typescript-eslint/naming-convention + '33': { + notificationPreference: 'always', + permissions: [CONST.REPORT.PERMISSIONS.READ, CONST.REPORT.PERMISSIONS.WRITE, CONST.REPORT.PERMISSIONS.SHARE, CONST.REPORT.PERMISSIONS.OWN], + }, + }, + policyAvatar: '', + policyID: 'CC048FA711B35B1F', + policyName: "53019's Workspace", + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: '', + reportID: '7605647250932303', + reportName: 'Chat Report', + state: 'OPEN', + stateNum: 0, + statusNum: 0, + total: 0, + type: 'chat', + unheldNonReimbursableTotal: 0, + unheldTotal: 0, + visibility: 'private', + welcomeMessage: '', + writeCapability: 'all', +}; + +type InvoiceTestData = { + policy: OnyxEntry; + transaction: OnyxEntry; + convertedInvoiceChat: OnyxTypes.Report; +}; + +export type {InvoiceTestData}; +export {policy, transaction, convertedInvoiceChat}; diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 5ff3a73b3089..751e9e5beb2d 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -2,13 +2,13 @@ import {addDays, format as formatDate} from 'date-fns'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; +import {convertedInvoiceChat} from 'tests/data/Invoice'; import DateUtils from '@libs/DateUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import * as TransactionUtils from '@src/libs/TransactionUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetailsList, Policy, Report, ReportAction} from '@src/types/onyx'; -import type {InvoiceReceiver} from '@src/types/onyx/Report'; import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet'; import * as NumberUtils from '../../src/libs/NumberUtils'; import * as LHNTestUtils from '../utils/LHNTestUtils'; @@ -63,66 +63,6 @@ const policy: Policy = { isPolicyExpenseChatEnabled: false, }; -const convertedInvoiceChat: OnyxEntry = { - chatType: CONST.REPORT.CHAT_TYPE.INVOICE, - currency: 'USD', - description: '', - errorFields: null, - hasOutstandingChildRequest: false, - hasOutstandingChildTask: false, - - // The invoice receiver shouldn't have an accountID when the type is business, - // but this is to test that it still works if the value is present - invoiceReceiver: { - accountID: 33, - policyID: '5F2F82F98C848CAA', - type: 'policy', - } as unknown as InvoiceReceiver, - isCancelledIOU: false, - isOwnPolicyExpenseChat: false, - isPinned: false, - isWaitingOnBankAccount: false, - lastActionType: 'REPORTPREVIEW', - lastActorAccountID: 32, - lastMessageHtml: 'paid $1.00', - lastMessageText: 'paid $1.00', - lastMessageTranslationKey: '', - lastReadSequenceNumber: 0, - lastReadTime: '2024-12-13 19:45:28.942', - lastVisibleActionCreated: '2024-12-13 19:19:01.794', - lastVisibleActionLastModified: '2024-12-13 19:19:01.794', - managerID: 0, - nonReimbursableTotal: 0, - oldPolicyName: '', - ownerAccountID: 0, - participants: { - '32': { - notificationPreference: 'always', - role: 'admin', - }, - '33': { - notificationPreference: 'always', - permissions: [CONST.REPORT.PERMISSIONS.READ, CONST.REPORT.PERMISSIONS.WRITE, CONST.REPORT.PERMISSIONS.SHARE, CONST.REPORT.PERMISSIONS.OWN], - }, - }, - policyAvatar: '', - policyID: 'CC048FA711B35B1F', - policyName: "53019's Workspace", - private_isArchived: '', - reportID: '7605647250932303', - reportName: 'Chat Report', - state: 'OPEN', - stateNum: 0, - statusNum: 0, - total: 0, - type: 'chat', - unheldNonReimbursableTotal: 0, - unheldTotal: 0, - visibility: 'private', - welcomeMessage: '', - writeCapability: 'all', -}; - Onyx.init({keys: ONYXKEYS}); describe('ReportUtils', () => { @@ -1484,13 +1424,10 @@ describe('ReportUtils', () => { }; // When we send another invoice to the individual from global create and call getInvoiceChatByParticipants - const invoiceChatReport = ReportUtils.getInvoiceChatByParticipants(convertedInvoiceChat.policyID, 33, CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL, reports); + const invoiceChatReport = ReportUtils.getInvoiceChatByParticipants(33, CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL, convertedInvoiceChat.policyID, reports); // Then no invoice chat should be returned because the receiver type does not match expect(invoiceChatReport).toBeUndefined(); }); }); }); - -// eslint-disable-next-line import/prefer-default-export -export {convertedInvoiceChat}; From 57ba052c310be26fb859c424974ece66a56412ac Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Fri, 13 Dec 2024 18:12:50 -0800 Subject: [PATCH 11/19] Jest matcher returns any so cast to fix type error --- tests/actions/IOUTest.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index e74b380b7b02..c70134f64b6e 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -3328,12 +3328,10 @@ describe('actions/IOU', () => { expect(writeSpy).toHaveBeenCalledWith( expect.anything(), expect.objectContaining({ - invoiceRoomReportID: expect.not.stringMatching(convertedInvoiceChat.reportID), + invoiceRoomReportID: expect.not.stringMatching(convertedInvoiceChat.reportID) as string, }), expect.anything(), ); - - // Restore the original implementation writeSpy.mockRestore(); }); }); From e6d5a920fee36535f92b4ee571c2d29a165797b8 Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Fri, 13 Dec 2024 18:46:49 -0800 Subject: [PATCH 12/19] Undo edge case type changes --- src/libs/DebugUtils.ts | 3 +++ src/types/onyx/Policy.ts | 18 ++++++++---------- src/types/onyx/Report.ts | 2 +- tests/data/Invoice.ts | 3 --- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index 9343164db1e8..9c27009b036e 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -514,6 +514,7 @@ function validateReportDraftProperty(key: keyof Report, value: string) { pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION, pendingFields: 'object', notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE, + permissions: 'array', }, 'number', ); @@ -630,6 +631,8 @@ function validateReportDraftProperty(key: keyof Report, value: string) { partial: CONST.RED_BRICK_ROAD_PENDING_ACTION, reimbursed: CONST.RED_BRICK_ROAD_PENDING_ACTION, preview: CONST.RED_BRICK_ROAD_PENDING_ACTION, + state: CONST.RED_BRICK_ROAD_PENDING_ACTION, + welcomeMessage: CONST.RED_BRICK_ROAD_PENDING_ACTION, }); } } diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index 2873a80b1d52..57550592d0bd 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -1599,7 +1599,7 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< outputCurrency: string; /** The address of the company */ - address?: CompanyAddress | []; + address?: CompanyAddress; /** The URL for the policy avatar */ avatarURL?: string; @@ -1751,15 +1751,13 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< taxRates?: TaxRatesWithDefault; /** A set of rules related to the workpsace */ - rules?: - | { - /** A set of rules related to the workpsace approvals */ - approvalRules?: ApprovalRule[]; - - /** A set of rules related to the workpsace expenses */ - expenseRules?: ExpenseRule[]; - } - | []; + rules?: { + /** A set of rules related to the workpsace approvals */ + approvalRules?: ApprovalRule[]; + + /** A set of rules related to the workpsace expenses */ + expenseRules?: ExpenseRule[]; + }; /** ReportID of the admins room for this workspace */ chatReportIDAdmins?: number; diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index ea6fa5d33c3a..881c416e01a8 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -200,7 +200,7 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< currency?: string; /** Collection of errors that exist in report fields */ - errorFields?: OnyxCommon.ErrorFields | null; + errorFields?: OnyxCommon.ErrorFields; /** Whether the report is waiting on a bank account */ isWaitingOnBankAccount?: boolean; diff --git a/tests/data/Invoice.ts b/tests/data/Invoice.ts index 24ae87f451fe..6a5c478a3a94 100644 --- a/tests/data/Invoice.ts +++ b/tests/data/Invoice.ts @@ -61,7 +61,6 @@ const policy: OnyxEntry = { pendingFields: {}, chatReportIDAnnounce: 0, chatReportIDAdmins: 1811331783036078, - address: [], approver: 'a1@53019.com', areCompanyCardsEnabled: false, areExpensifyCardsEnabled: false, @@ -170,7 +169,6 @@ const policy: OnyxEntry = { groupID: 'utilities', }, }, - rules: [], }; const transaction: OnyxEntry = { @@ -226,7 +224,6 @@ const convertedInvoiceChat: OnyxTypes.Report = { chatType: CONST.REPORT.CHAT_TYPE.INVOICE, currency: 'USD', description: '', - errorFields: null, hasOutstandingChildRequest: false, hasOutstandingChildTask: false, From 2ada6b83be4127f2a87741e39a22d117c47fd5fa Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Fri, 13 Dec 2024 18:52:46 -0800 Subject: [PATCH 13/19] More type fixes --- src/types/onyx/Policy.ts | 2 +- src/types/utils/whitelistedReportKeys.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index 57550592d0bd..3079b3f31f3f 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -1638,7 +1638,7 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< enabled: boolean; /** The ID of the Bedrock job that runs harvesting */ - jobID: number; + jobID?: number; }; /** Whether the self approval or submitting is enabled */ diff --git a/src/types/utils/whitelistedReportKeys.ts b/src/types/utils/whitelistedReportKeys.ts index 015420683925..c3849e3bf83d 100644 --- a/src/types/utils/whitelistedReportKeys.ts +++ b/src/types/utils/whitelistedReportKeys.ts @@ -64,6 +64,8 @@ type WhitelistedReport = OnyxCommon.OnyxValueWithOfflineFeedback< }; // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: unknown; + state: unknown; + welcomeMessage: unknown; }, PolicyReportField['fieldID'] >; From 3e4e0339aee2f9178d654e0746e56d2c238e406d Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Fri, 13 Dec 2024 19:05:18 -0800 Subject: [PATCH 14/19] Fix lint --- src/libs/DebugUtils.ts | 2 ++ src/libs/actions/IOU.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index 9c27009b036e..a8cd91599bff 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -469,6 +469,8 @@ function validateReportDraftProperty(key: keyof Report, value: string) { case 'iouReportID': case 'preexistingReportID': case 'private_isArchived': + case 'state': + case 'welcomeMessage': return validateString(value); case 'hasOutstandingChildRequest': case 'hasOutstandingChildTask': diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 9d4aa640aeb1..f803386cb649 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -66,7 +66,7 @@ import type * as OnyxTypes from '@src/types/onyx'; import type {Attendee, Participant, Split} from '@src/types/onyx/IOU'; import type {ErrorFields, Errors} from '@src/types/onyx/OnyxCommon'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; -import {InvoiceReceiver, InvoiceReceiverType} from '@src/types/onyx/Report'; +import type {InvoiceReceiver, InvoiceReceiverType} from '@src/types/onyx/Report'; import type ReportAction from '@src/types/onyx/ReportAction'; import type {OnyxData} from '@src/types/onyx/Request'; import type {SearchPolicy, SearchReport, SearchTransaction} from '@src/types/onyx/SearchResults'; From 4516d8fb51737529cdf946d6bb0821136ada9269 Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Fri, 13 Dec 2024 19:08:07 -0800 Subject: [PATCH 15/19] Fix test, bad import path --- tests/unit/ReportUtilsTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 751e9e5beb2d..85cf0125a5eb 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -2,7 +2,6 @@ import {addDays, format as formatDate} from 'date-fns'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; -import {convertedInvoiceChat} from 'tests/data/Invoice'; import DateUtils from '@libs/DateUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; @@ -11,6 +10,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetailsList, Policy, Report, ReportAction} from '@src/types/onyx'; import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet'; import * as NumberUtils from '../../src/libs/NumberUtils'; +import {convertedInvoiceChat} from '../data/Invoice'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import {fakePersonalDetails} from '../utils/LHNTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; From 17d298adeff0480b026174c3a7dac7d484530e8c Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Tue, 17 Dec 2024 10:20:37 -0500 Subject: [PATCH 16/19] Fix accidentally changed comment --- src/types/onyx/Report.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index 881c416e01a8..1e4256c0e8ae 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -1,9 +1,10 @@ -import type {ValueOf} from 'type-fest'; +import type { ValueOf } from 'type-fest'; import type CONST from '@src/CONST'; import type ONYXKEYS from '@src/ONYXKEYS'; import type CollectionDataSet from '@src/types/utils/CollectionDataSet'; import type * as OnyxCommon from './OnyxCommon'; -import type {PolicyReportField} from './Policy'; +import type { PolicyReportField } from './Policy'; + /** Preference that defines how regular the chat notifications are sent to the user */ type NotificationPreference = ValueOf; @@ -142,7 +143,7 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< /** The state number of the report */ stateNum?: ValueOf; - /** The state that the report is currently in */ + /** The status of the current report */ statusNum?: ValueOf; /** Which user role is capable of posting messages on the report */ @@ -256,4 +257,4 @@ type ReportCollectionDataSet = CollectionDataSet Date: Tue, 17 Dec 2024 18:00:32 -0500 Subject: [PATCH 17/19] Fix style --- src/types/onyx/Report.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index 1e4256c0e8ae..7075c9f35085 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -1,10 +1,9 @@ -import type { ValueOf } from 'type-fest'; +import type {ValueOf} from 'type-fest'; import type CONST from '@src/CONST'; import type ONYXKEYS from '@src/ONYXKEYS'; import type CollectionDataSet from '@src/types/utils/CollectionDataSet'; import type * as OnyxCommon from './OnyxCommon'; -import type { PolicyReportField } from './Policy'; - +import type {PolicyReportField} from './Policy'; /** Preference that defines how regular the chat notifications are sent to the user */ type NotificationPreference = ValueOf; @@ -257,4 +256,4 @@ type ReportCollectionDataSet = CollectionDataSet Date: Tue, 24 Dec 2024 07:12:49 -0800 Subject: [PATCH 18/19] Remove field no longer present on type --- tests/data/Invoice.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/data/Invoice.ts b/tests/data/Invoice.ts index 6a5c478a3a94..650b9afab832 100644 --- a/tests/data/Invoice.ts +++ b/tests/data/Invoice.ts @@ -242,7 +242,6 @@ const convertedInvoiceChat: OnyxTypes.Report = { lastActorAccountID: 32, lastMessageHtml: 'paid $1.00', lastMessageText: 'paid $1.00', - lastMessageTranslationKey: '', lastReadSequenceNumber: 0, lastReadTime: '2024-12-13 19:45:28.942', lastVisibleActionCreated: '2024-12-13 19:19:01.794', From 55572c31dee16d950538b0fdb8c52c234d0e661c Mon Sep 17 00:00:00 2001 From: neil-marcellini Date: Tue, 24 Dec 2024 11:18:13 -0800 Subject: [PATCH 19/19] Remove accidentally added client only Report key state --- src/libs/DebugUtils.ts | 2 -- src/types/onyx/Report.ts | 5 +---- src/types/utils/whitelistedReportKeys.ts | 1 - tests/data/Invoice.ts | 1 - 4 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index 9660a95d999d..109dbf2820f3 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -468,7 +468,6 @@ function validateReportDraftProperty(key: keyof Report, value: string) { case 'iouReportID': case 'preexistingReportID': case 'private_isArchived': - case 'state': case 'welcomeMessage': return validateString(value); case 'hasOutstandingChildRequest': @@ -631,7 +630,6 @@ function validateReportDraftProperty(key: keyof Report, value: string) { partial: CONST.RED_BRICK_ROAD_PENDING_ACTION, reimbursed: CONST.RED_BRICK_ROAD_PENDING_ACTION, preview: CONST.RED_BRICK_ROAD_PENDING_ACTION, - state: CONST.RED_BRICK_ROAD_PENDING_ACTION, welcomeMessage: CONST.RED_BRICK_ROAD_PENDING_ACTION, }); } diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index a864c369aab9..613f524b8c08 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -136,10 +136,7 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< /** ID of the chat report */ chatReportID?: string; - /** The state of the report */ - state?: keyof typeof CONST.REPORT.STATE_NUM; - - /** The state number of the report */ + /** The state that the report is currently in */ stateNum?: ValueOf; /** The status of the current report */ diff --git a/src/types/utils/whitelistedReportKeys.ts b/src/types/utils/whitelistedReportKeys.ts index 367da53d3122..7e27d49de1d6 100644 --- a/src/types/utils/whitelistedReportKeys.ts +++ b/src/types/utils/whitelistedReportKeys.ts @@ -63,7 +63,6 @@ type WhitelistedReport = OnyxCommon.OnyxValueWithOfflineFeedback< }; // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: unknown; - state: unknown; welcomeMessage: unknown; }, PolicyReportField['fieldID'] diff --git a/tests/data/Invoice.ts b/tests/data/Invoice.ts index 650b9afab832..c94c7ce816be 100644 --- a/tests/data/Invoice.ts +++ b/tests/data/Invoice.ts @@ -269,7 +269,6 @@ const convertedInvoiceChat: OnyxTypes.Report = { private_isArchived: '', reportID: '7605647250932303', reportName: 'Chat Report', - state: 'OPEN', stateNum: 0, statusNum: 0, total: 0,