Skip to content

Commit

Permalink
Validating Report keys and if a change happens in it, it must be high…
Browse files Browse the repository at this point in the history
…lighted
  • Loading branch information
gedu committed Nov 15, 2024
1 parent 9685867 commit eb7f3f7
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
87 changes: 87 additions & 0 deletions src/types/utils/whitelistedReportKeys.ts
Original file line number Diff line number Diff line change
@@ -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<T, U> = Exclude<T, U> 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<ReportKeys, WhitelistedReportKeys> = true;
export default testReportKeys;
8 changes: 8 additions & 0 deletions tests/unit/validateReportKeysTest.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit eb7f3f7

Please sign in to comment.