From a3c11f8f9fb1b9fdd34e6859143fa2917ba6cde8 Mon Sep 17 00:00:00 2001 From: Edu Date: Fri, 15 Nov 2024 15:40:37 +0100 Subject: [PATCH 1/3] Validating Report keys and if a change happens in it, it must be highlighted --- src/types/utils/whitelistedReportKeys.ts | 87 ++++++++++++++++++++++++ tests/unit/validateReportKeysTest.ts | 8 +++ 2 files changed, 95 insertions(+) create mode 100644 src/types/utils/whitelistedReportKeys.ts create mode 100644 tests/unit/validateReportKeysTest.ts diff --git a/src/types/utils/whitelistedReportKeys.ts b/src/types/utils/whitelistedReportKeys.ts new file mode 100644 index 000000000000..0c9222a6eb32 --- /dev/null +++ b/src/types/utils/whitelistedReportKeys.ts @@ -0,0 +1,87 @@ +import type {PolicyReportField, Report} from '../onyx'; +import type * as OnyxCommon from '../onyx/OnyxCommon'; + +// List of keys that are allowed on the Report type. These should be the keys that are sent from the server. +// you need confirmation from an internal engineer that this has indeed been added to the report object that is returned as +type WhitelistedReport = OnyxCommon.OnyxValueWithOfflineFeedback< + { + avatarUrl: unknown; + avatarFileName: unknown; + chatType: unknown; + hasOutstandingChildRequest: unknown; + hasOutstandingChildTask: unknown; + isOwnPolicyExpenseChat: unknown; + isPolicyExpenseChat: unknown; + isPinned: unknown; + lastMessageText: unknown; + lastVisibleActionCreated: unknown; + lastReadTime: unknown; + lastReadSequenceNumber: unknown; + lastMentionedTime: unknown; + policyAvatar: unknown; + policyName: unknown; + oldPolicyName: unknown; + hasParentAccess: unknown; + description: unknown; + isDeletedParentAction: unknown; + policyID: unknown; + reportName: unknown; + reportID: string; + reportActionID: unknown; + chatReportID: unknown; + stateNum: unknown; + statusNum: unknown; + writeCapability: unknown; + type: unknown; + visibility: unknown; + cachedTotal: unknown; + invoiceReceiver: unknown; + lastMessageTranslationKey: unknown; + parentReportID: unknown; + parentReportActionID: unknown; + isOptimisticReport: unknown; + managerID: unknown; + lastVisibleActionLastModified: unknown; + displayName: unknown; + lastMessageHtml: unknown; + lastActorAccountID: unknown; + lastActionType: unknown; + ownerAccountID: unknown; + participants: unknown; + total: unknown; + unheldTotal: unknown; + currency: unknown; + errors: unknown; + errorFields: unknown; + isWaitingOnBankAccount: unknown; + isCancelledIOU: unknown; + iouReportID: unknown; + preexistingReportID: unknown; + nonReimbursableTotal: unknown; + isHidden: unknown; + privateNotes: unknown; + isLoadingPrivateNotes: unknown; + pendingChatMembers: unknown; + transactionThreadReportID: unknown; + fieldList: unknown; + permissions: unknown; + tripData: { + startDate: unknown; + endDate: unknown; + tripID: unknown; + }; + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: unknown; + }, + PolicyReportField['fieldID'] +>; +type ReportKeys = keyof Report; +type WhitelistedReportKeys = keyof WhitelistedReport; + +type ValidateKeys = Exclude extends never ? true : false; + +// TypeScript type-level check intended to ensure that all keys in the Report type are part of the whitelisted keys. +// However, TypeScript doesn't execute code at runtime, so this check is purely for compile-time validation. +// This validation must be always TRUE. +const testReportKeys: ValidateKeys = true; +export default testReportKeys; diff --git a/tests/unit/validateReportKeysTest.ts b/tests/unit/validateReportKeysTest.ts new file mode 100644 index 000000000000..1339b126e41b --- /dev/null +++ b/tests/unit/validateReportKeysTest.ts @@ -0,0 +1,8 @@ +import testReportKeys from '@src/types/utils/whitelistedReportKeys'; + +// This test is mainly to avoid that the testReportKeys is not removed or changed to false +describe('whitelistedReportKeys', () => { + it('testReportKeys must be true', () => { + expect(testReportKeys).toBe(true); + }); +}); From e7d136e38c56194fb3705c9a2be35cd7511e7bd8 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Fri, 15 Nov 2024 17:07:05 +0100 Subject: [PATCH 2/3] Updated comment --- src/types/utils/whitelistedReportKeys.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/types/utils/whitelistedReportKeys.ts b/src/types/utils/whitelistedReportKeys.ts index 0c9222a6eb32..2bb6017584b0 100644 --- a/src/types/utils/whitelistedReportKeys.ts +++ b/src/types/utils/whitelistedReportKeys.ts @@ -1,8 +1,9 @@ import type {PolicyReportField, Report} from '../onyx'; import type * as OnyxCommon from '../onyx/OnyxCommon'; -// List of keys that are allowed on the Report type. These should be the keys that are sent from the server. -// you need confirmation from an internal engineer that this has indeed been added to the report object that is returned as +// List of keys that are allowed on the Report type. These should be the keys that are returned from the server in OpenApp. +// Before changing this, you need confirmation from an internal engineer that the new key has been added to the report object that is returned from the back-end in OpenApp +// Any report data that you want to store in Onyx, but isn't returned from the server, should be stored in reportMetaData. type WhitelistedReport = OnyxCommon.OnyxValueWithOfflineFeedback< { avatarUrl: unknown; From 14609302259edb5f1c8a631cd2a54839402040b2 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Fri, 15 Nov 2024 17:17:20 +0100 Subject: [PATCH 3/3] fixed imports --- src/types/utils/whitelistedReportKeys.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/utils/whitelistedReportKeys.ts b/src/types/utils/whitelistedReportKeys.ts index 2bb6017584b0..3c566c987526 100644 --- a/src/types/utils/whitelistedReportKeys.ts +++ b/src/types/utils/whitelistedReportKeys.ts @@ -1,5 +1,5 @@ -import type {PolicyReportField, Report} from '../onyx'; -import type * as OnyxCommon from '../onyx/OnyxCommon'; +import type {PolicyReportField, Report} from '@src/types/onyx'; +import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; // List of keys that are allowed on the Report type. These should be the keys that are returned from the server in OpenApp. // Before changing this, you need confirmation from an internal engineer that the new key has been added to the report object that is returned from the back-end in OpenApp