Skip to content
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

[NO QA]Validating keys from Report type #52619

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
88 changes: 88 additions & 0 deletions src/types/utils/whitelistedReportKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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
// 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;
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);
});
});
Loading