diff --git a/src/CONST/index.ts b/src/CONST/index.ts index 804db2d28d7b8..250f44c995fe1 100755 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -8454,9 +8454,6 @@ const CONST = { ONBOARDING: { INTERESTED_FEATURES_ITEM: 'Onboarding-InterestedFeaturesItem', }, - BASE_ANCHOR_FOR_ATTACHMENTS_ONLY: { - DOWNLOAD_BUTTON: 'BaseAnchorForAttachmentsOnly-DownloadButton', - }, REPORT_HEADER_SKELETON: { GO_BACK: 'ReportHeaderSkeleton-GoBack', }, diff --git a/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx b/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx index dfac5478e5a41..03159e30cf5c8 100644 --- a/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx +++ b/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx @@ -1,6 +1,5 @@ import React from 'react'; import AttachmentView from '@components/Attachments/AttachmentView'; -import {useSession} from '@components/OnyxListItemProvider'; import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback'; import {ShowContextMenuContext, showContextMenuForReport} from '@components/ShowContextMenuContext'; import useLocalize from '@hooks/useLocalize'; @@ -26,18 +25,16 @@ type BaseAnchorForAttachmentsOnlyProps = AnchorForAttachmentsOnlyProps & { }; function BaseAnchorForAttachmentsOnly({style, source = '', displayName = '', onPressIn, onPressOut, isDeleted}: BaseAnchorForAttachmentsOnlyProps) { + const sourceURLWithAuth = addEncryptedAuthTokenToURL(source); const sourceID = (source.match(CONST.REGEX.ATTACHMENT_ID) ?? [])[1]; const [download] = useOnyx(`${ONYXKEYS.COLLECTION.DOWNLOAD}${sourceID}`, {canBeMissing: true}); - const session = useSession(); const {translate} = useLocalize(); const {isOffline} = useNetwork(); const styles = useThemeStyles(); const isDownloading = download?.isDownloading ?? false; - const encryptedAuthToken = session?.encryptedAuthToken ?? ''; - const sourceURLWithAuth = addEncryptedAuthTokenToURL(source, encryptedAuthToken); return ( @@ -62,7 +59,6 @@ function BaseAnchorForAttachmentsOnly({style, source = '', displayName = '', onP shouldUseHapticsOnLongPress accessibilityLabel={displayName} role={CONST.ROLE.BUTTON} - sentryLabel={CONST.SENTRY_LABEL.BASE_ANCHOR_FOR_ATTACHMENTS_ONLY.DOWNLOAD_BUTTON} > { const id = (transaction && transaction.transactionID) ?? reportActionID; diff --git a/src/components/Composer/implementation/index.tsx b/src/components/Composer/implementation/index.tsx index a49514d2b1f74..7d181775ed4ea 100755 --- a/src/components/Composer/implementation/index.tsx +++ b/src/components/Composer/implementation/index.tsx @@ -6,7 +6,6 @@ import React, {useCallback, useEffect, useImperativeHandle, useMemo, useRef, use import type {TextInputKeyPressEvent, TextInputSelectionChangeEvent} from 'react-native'; import {DeviceEventEmitter, StyleSheet} from 'react-native'; import type {ComposerProps} from '@components/Composer/types'; -import {useSession} from '@components/OnyxListItemProvider'; import type {AnimatedMarkdownTextInputRef} from '@components/RNMarkdownTextInput'; import RNMarkdownTextInput from '@components/RNMarkdownTextInput'; import useHtmlPaste from '@hooks/useHtmlPaste'; @@ -56,9 +55,6 @@ function Composer({ const textContainsOnlyEmojis = useMemo(() => containsOnlyEmojis(Parser.htmlToText(Parser.replace(value ?? ''))), [value]); const theme = useTheme(); const styles = useThemeStyles(); - const session = useSession(); - const encryptedAuthToken = session?.encryptedAuthToken ?? ''; - const addAuthTokenToImageURL = (url: string) => addEncryptedAuthTokenToURL(url, encryptedAuthToken); const markdownStyle = useMarkdownStyle(textContainsOnlyEmojis, !isGroupPolicyReport ? excludeReportMentionStyle : excludeNoStyles); const StyleUtils = useStyleUtils(); const textInput = useRef(null); @@ -365,7 +361,7 @@ function Composer({ }} disabled={isDisabled} onKeyPress={handleKeyPress} - addAuthTokenToImageURLCallback={addAuthTokenToImageURL} + addAuthTokenToImageURLCallback={addEncryptedAuthTokenToURL} imagePreviewAuthRequiredURLs={imagePreviewAuthRequiredURLs} /> ); diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 2816a35c388ac..66824eb0514da 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -217,7 +217,6 @@ function MoneyReportHeader({ const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, {canBeMissing: true}); const [reportPDFFilename] = useOnyx(`${ONYXKEYS.COLLECTION.NVP_EXPENSIFY_REPORT_PDF_FILENAME}${moneyRequestReport?.reportID}`, {canBeMissing: true}) ?? null; const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false}); - const encryptedAuthToken = session?.encryptedAuthToken ?? ''; const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true}); const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true}); const activePolicy = usePolicy(activePolicyID); @@ -1625,9 +1624,9 @@ function MoneyReportHeader({ if (!hasFinishedPDFDownload || !canTriggerAutomaticPDFDownload.current) { return; } - downloadReportPDF(reportPDFFilename, moneyRequestReport?.reportName ?? '', translate, currentUserLogin ?? '', encryptedAuthToken); + downloadReportPDF(reportPDFFilename, moneyRequestReport?.reportName ?? '', translate, currentUserLogin ?? ''); canTriggerAutomaticPDFDownload.current = false; - }, [hasFinishedPDFDownload, reportPDFFilename, moneyRequestReport?.reportName, translate, currentUserLogin, encryptedAuthToken]); + }, [hasFinishedPDFDownload, reportPDFFilename, moneyRequestReport?.reportName, translate, currentUserLogin]); const shouldShowBackButton = shouldDisplayBackButton || shouldUseNarrowLayout; @@ -1966,7 +1965,7 @@ function MoneyReportHeader({ if (!hasFinishedPDFDownload) { setIsPDFModalVisible(false); } else { - downloadReportPDF(reportPDFFilename, moneyRequestReport?.reportName ?? '', translate, currentUserLogin ?? '', encryptedAuthToken); + downloadReportPDF(reportPDFFilename, moneyRequestReport?.reportName ?? '', translate, currentUserLogin ?? ''); } }} text={hasFinishedPDFDownload ? translate('common.download') : translate('common.cancel')} diff --git a/src/components/PDFThumbnail/index.native.tsx b/src/components/PDFThumbnail/index.native.tsx index 32ca78785eb2e..f92a9e2291033 100644 --- a/src/components/PDFThumbnail/index.native.tsx +++ b/src/components/PDFThumbnail/index.native.tsx @@ -3,10 +3,11 @@ import {View} from 'react-native'; import Pdf from 'react-native-pdf'; import LoadingIndicator from '@components/LoadingIndicator'; import useThemeStyles from '@hooks/useThemeStyles'; +import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; import PDFThumbnailError from './PDFThumbnailError'; import type PDFThumbnailProps from './types'; -function PDFThumbnail({previewSourceURL, style, enabled = true, fitPolicy = 0, onPassword, onLoadError, onLoadSuccess}: PDFThumbnailProps) { +function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, fitPolicy = 0, onPassword, onLoadError, onLoadSuccess}: PDFThumbnailProps) { const styles = useThemeStyles(); const sizeStyles = [styles.w100, styles.h100]; const [failedToLoad, setFailedToLoad] = useState(false); @@ -19,7 +20,7 @@ function PDFThumbnail({previewSourceURL, style, enabled = true, fitPolicy = 0, o fitPolicy={fitPolicy} trustAllCerts={false} renderActivityIndicator={() => } - source={{uri: previewSourceURL}} + source={{uri: isAuthTokenRequired ? addEncryptedAuthTokenToURL(previewSourceURL) : previewSourceURL}} singlePage style={sizeStyles} onError={(error) => { diff --git a/src/components/PDFThumbnail/index.tsx b/src/components/PDFThumbnail/index.tsx index 949d16d7e19c8..fadd0bd350deb 100644 --- a/src/components/PDFThumbnail/index.tsx +++ b/src/components/PDFThumbnail/index.tsx @@ -6,6 +6,7 @@ import {View} from 'react-native'; import {Document, pdfjs, Thumbnail} from 'react-pdf'; import LoadingIndicator from '@components/LoadingIndicator'; import useThemeStyles from '@hooks/useThemeStyles'; +import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; import PDFThumbnailError from './PDFThumbnailError'; import type PDFThumbnailProps from './types'; @@ -13,7 +14,7 @@ if (!pdfjs.GlobalWorkerOptions.workerSrc) { pdfjs.GlobalWorkerOptions.workerSrc = URL.createObjectURL(new Blob([pdfWorkerSource], {type: 'text/javascript'})); } -function PDFThumbnail({previewSourceURL, style, enabled = true, onPassword, onLoadError, onLoadSuccess}: PDFThumbnailProps) { +function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword, onLoadError, onLoadSuccess}: PDFThumbnailProps) { const styles = useThemeStyles(); const [failedToLoad, setFailedToLoad] = useState(false); @@ -21,7 +22,7 @@ function PDFThumbnail({previewSourceURL, style, enabled = true, onPassword, onLo () => ( } - file={previewSourceURL} + file={isAuthTokenRequired ? addEncryptedAuthTokenToURL(previewSourceURL) : previewSourceURL} options={{ cMapUrl: 'cmaps/', cMapPacked: true, @@ -50,7 +51,7 @@ function PDFThumbnail({previewSourceURL, style, enabled = true, onPassword, onLo ), - [previewSourceURL, onPassword, onLoadError, onLoadSuccess], + [isAuthTokenRequired, previewSourceURL, onPassword, onLoadError, onLoadSuccess], ); return ( diff --git a/src/components/PDFThumbnail/types.ts b/src/components/PDFThumbnail/types.ts index 8300fbaa4bd1a..bd9f2783b2054 100644 --- a/src/components/PDFThumbnail/types.ts +++ b/src/components/PDFThumbnail/types.ts @@ -7,6 +7,9 @@ type PDFThumbnailProps = { /** Any additional styles to apply */ style?: StyleProp; + /** Whether the PDF thumbnail requires an authToken */ + isAuthTokenRequired?: boolean; + /** Whether the PDF thumbnail can be loaded */ enabled?: boolean; diff --git a/src/components/VideoPlayer/BaseVideoPlayer.tsx b/src/components/VideoPlayer/BaseVideoPlayer.tsx index 737f90a09ec28..ad93e461345df 100644 --- a/src/components/VideoPlayer/BaseVideoPlayer.tsx +++ b/src/components/VideoPlayer/BaseVideoPlayer.tsx @@ -11,7 +11,6 @@ import {scheduleOnRN} from 'react-native-worklets'; import AttachmentOfflineIndicator from '@components/AttachmentOfflineIndicator'; import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; import Hoverable from '@components/Hoverable'; -import {useSession} from '@components/OnyxListItemProvider'; import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback'; import {useFullScreenContext} from '@components/VideoPlayerContexts/FullScreenContext'; import {usePlaybackActionsContext, usePlaybackStateContext} from '@components/VideoPlayerContexts/PlaybackContext'; @@ -59,13 +58,11 @@ function BaseVideoPlayer({ const {isFullScreenRef} = useFullScreenContext(); const isOffline = useNetwork().isOffline; - const session = useSession(); - const encryptedAuthToken = session?.encryptedAuthToken ?? ''; const [duration, setDuration] = useState(videoDuration); const [isEnded, setIsEnded] = useState(false); const [isFirstLoad, setIsFirstLoad] = useState(true); // we add "#t=0.001" at the end of the URL to skip first millisecond of the video and always be able to show proper video preview when video is paused at the beginning - const [sourceURL] = useState(() => VideoUtils.addSkipTimeTagToURL(url.includes('blob:') || url.includes('file:///') ? url : addEncryptedAuthTokenToURL(url, encryptedAuthToken), 0.001)); + const [sourceURL] = useState(() => VideoUtils.addSkipTimeTagToURL(url.includes('blob:') || url.includes('file:///') ? url : addEncryptedAuthTokenToURL(url), 0.001)); const [isPopoverVisible, setIsPopoverVisible] = useState(false); const [popoverAnchorPosition, setPopoverAnchorPosition] = useState({horizontal: 0, vertical: 0}); const [controlStatusState, setControlStatusState] = useState(controlsStatus); diff --git a/src/components/VideoPlayerContexts/VideoPopoverMenuContext.tsx b/src/components/VideoPlayerContexts/VideoPopoverMenuContext.tsx index 3ae61e3a90b28..7708f8fe752ea 100644 --- a/src/components/VideoPlayerContexts/VideoPopoverMenuContext.tsx +++ b/src/components/VideoPlayerContexts/VideoPopoverMenuContext.tsx @@ -2,7 +2,6 @@ import type {VideoPlayer} from 'expo-video'; import React, {useCallback, useContext, useMemo, useRef, useState} from 'react'; // eslint-disable-next-line no-restricted-imports import * as Expensicons from '@components/Icon/Expensicons'; -import {useSession} from '@components/OnyxListItemProvider'; import type {PopoverMenuItem} from '@components/PopoverMenu'; import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; @@ -23,8 +22,6 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) { const {isOffline} = useNetwork(); const isLocalFile = source && CONST.ATTACHMENT_LOCAL_URL_PREFIX.some((prefix) => source.startsWith(prefix)); const videoPopoverMenuPlayerRef = useRef(null); - const session = useSession(); - const encryptedAuthToken = session?.encryptedAuthToken ?? ''; const updatePlaybackSpeed = useCallback( (speed: PlaybackSpeed) => { @@ -45,8 +42,8 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) { if (typeof source === 'number' || !source) { return; } - fileDownload(translate, addEncryptedAuthTokenToURL(source, encryptedAuthToken)); - }, [source, translate, encryptedAuthToken]); + fileDownload(translate, addEncryptedAuthTokenToURL(source)); + }, [source, translate]); const menuItems = useMemo(() => { const items: PopoverMenuItem[] = []; diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index f68aa7353f055..dd0ad4dd74c8d 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -5031,14 +5031,14 @@ function exportReportToPDF({reportID}: ExportReportPDFParams) { API.write(WRITE_COMMANDS.EXPORT_REPORT_TO_PDF, params, {optimisticData, failureData}); } -function downloadReportPDF(fileName: string, reportName: string, translate: LocalizedTranslate, currentUserLogin: string, encryptedAuthToken: string) { +function downloadReportPDF(fileName: string, reportName: string, translate: LocalizedTranslate, currentUserLogin: string) { const baseURL = addTrailingForwardSlash(getOldDotURLFromEnvironment(environment)); const downloadFileName = `${reportName}.pdf`; setDownload(fileName, true); const pdfURL = `${baseURL}secure?secureType=pdfreport&filename=${encodeURIComponent(fileName)}&downloadName=${encodeURIComponent(downloadFileName)}&email=${encodeURIComponent( currentUserLogin, )}`; - fileDownload(translate, addEncryptedAuthTokenToURL(pdfURL, encryptedAuthToken, true), downloadFileName, '', Browser.isMobileSafari()).then(() => setDownload(fileName, false)); + fileDownload(translate, addEncryptedAuthTokenToURL(pdfURL, true), downloadFileName, '', Browser.isMobileSafari()).then(() => setDownload(fileName, false)); } function setDeleteTransactionNavigateBackUrl(url: string) { diff --git a/src/libs/addEncryptedAuthTokenToURL.ts b/src/libs/addEncryptedAuthTokenToURL.ts index 3b00662e9c6f8..83c9239eff675 100644 --- a/src/libs/addEncryptedAuthTokenToURL.ts +++ b/src/libs/addEncryptedAuthTokenToURL.ts @@ -1,7 +1,19 @@ +import Onyx from 'react-native-onyx'; +import ONYXKEYS from '@src/ONYXKEYS'; + +let encryptedAuthToken = ''; +// We use `connectWithoutView` here since this connection only updates a module-level variable +// and doesn't need to trigger component re-renders. UI components get the current token +// value when they call the exported function. +Onyx.connectWithoutView({ + key: ONYXKEYS.SESSION, + callback: (session) => (encryptedAuthToken = session?.encryptedAuthToken ?? ''), +}); + /** * Add encryptedAuthToken to this attachment URL */ -export default function addEncryptedAuthTokenToURL(url: string, encryptedAuthToken: string, hasOtherParameters = false) { +export default function (url: string, hasOtherParameters = false) { const symbol = hasOtherParameters ? '&' : '?'; return `${url}${symbol}encryptedAuthToken=${encodeURIComponent(encryptedAuthToken)}`; } diff --git a/src/pages/inbox/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/inbox/report/ContextMenu/BaseReportActionContextMenu.tsx index 1ce91501a667f..2fd8696a016be 100755 --- a/src/pages/inbox/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/inbox/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -9,7 +9,6 @@ import * as ActionSheetAwareScrollView from '@components/ActionSheetAwareScrollV import ContextMenuItem from '@components/ContextMenuItem'; import {DelegateNoAccessContext} from '@components/DelegateNoAccessModalProvider'; import FocusTrapForModal from '@components/FocusTrap/FocusTrapForModal'; -import {useSession} from '@components/OnyxListItemProvider'; import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useEnvironment from '@hooks/useEnvironment'; @@ -241,8 +240,6 @@ function BaseReportActionContextMenu({ const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true}); const isTryNewDotNVPDismissed = !!tryNewDot?.classicRedirect?.dismissed; - const session = useSession(); - const encryptedAuthToken = session?.encryptedAuthToken ?? ''; const isMoneyRequest = useMemo(() => ReportUtilsIsMoneyRequest(childReport), [childReport]); const isTrackExpenseReport = ReportUtilsIsTrackExpenseReport(childReport); @@ -404,7 +401,6 @@ function BaseReportActionContextMenu({ showDelegateNoAccessModal, currentUserAccountID: currentUserPersonalDetails?.accountID, currentUserPersonalDetails, - encryptedAuthToken, }; if ('renderContent' in contextAction) { diff --git a/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx b/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx index b137ad25ad146..8bbc6514fbc12 100644 --- a/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx @@ -284,7 +284,6 @@ type ContextMenuActionPayload = { isDelegateAccessRestricted?: boolean; showDelegateNoAccessModal?: () => void; currentUserPersonalDetails: ReturnType; - encryptedAuthToken: string; }; type OnPress = (closePopover: boolean, payload: ContextMenuActionPayload, selection?: string, reportID?: string, draftMessage?: string) => void; @@ -1184,10 +1183,10 @@ const ContextMenuActions: ContextMenuAction[] = [ const isUploading = html.includes(CONST.ATTACHMENT_OPTIMISTIC_SOURCE_ATTRIBUTE); return isAttachment && !isUploading && !!reportAction?.reportActionID && !isMessageDeleted(reportAction) && !isOffline; }, - onPress: (closePopover, {reportAction, translate, encryptedAuthToken}) => { + onPress: (closePopover, {reportAction, translate}) => { const html = getActionHtml(reportAction); const {originalFileName, sourceURL} = getAttachmentDetails(html); - const sourceURLWithAuth = addEncryptedAuthTokenToURL(sourceURL ?? '', encryptedAuthToken); + const sourceURLWithAuth = addEncryptedAuthTokenToURL(sourceURL ?? ''); const sourceID = (sourceURL?.match(CONST.REGEX.ATTACHMENT_ID) ?? [])[1]; setDownload(sourceID, true); const anchorRegex = CONST.REGEX_LINK_IN_ANCHOR; diff --git a/src/pages/media/AttachmentModalScreen/routes/hooks/useDownloadAttachment.ts b/src/pages/media/AttachmentModalScreen/routes/hooks/useDownloadAttachment.ts index 7a327f8a32af8..482454f0190ae 100644 --- a/src/pages/media/AttachmentModalScreen/routes/hooks/useDownloadAttachment.ts +++ b/src/pages/media/AttachmentModalScreen/routes/hooks/useDownloadAttachment.ts @@ -1,6 +1,5 @@ import {useCallback} from 'react'; import {Keyboard} from 'react-native'; -import {useSession} from '@components/OnyxListItemProvider'; import useLocalize from '@hooks/useLocalize'; import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; import fileDownload from '@libs/fileDownload'; @@ -16,8 +15,6 @@ type UseDownloadAttachmentProps = { function useDownloadAttachment({isAuthTokenRequired, type, draftTransactionID}: UseDownloadAttachmentProps = {}) { const {translate} = useLocalize(); - const session = useSession(); - const encryptedAuthToken = session?.encryptedAuthToken ?? ''; /** * Download the currently viewed attachment. */ @@ -25,7 +22,7 @@ function useDownloadAttachment({isAuthTokenRequired, type, draftTransactionID}: ({source, file}) => { let sourceURL = source; if (isAuthTokenRequired && typeof sourceURL === 'string') { - sourceURL = addEncryptedAuthTokenToURL(sourceURL, encryptedAuthToken); + sourceURL = addEncryptedAuthTokenToURL(sourceURL); } if (typeof sourceURL === 'string') { @@ -38,7 +35,7 @@ function useDownloadAttachment({isAuthTokenRequired, type, draftTransactionID}: // the attachment keyboard will show up. So, to fix it we need to dismiss the keyboard. Keyboard.dismiss(); }, - [isAuthTokenRequired, type, draftTransactionID, translate, encryptedAuthToken], + [isAuthTokenRequired, type, draftTransactionID, translate], ); return downloadAttachment; diff --git a/tests/ui/components/FeatureTrainingModalTest.tsx b/tests/ui/components/FeatureTrainingModalTest.tsx index b2528d8e0b58f..11d4a303146a9 100644 --- a/tests/ui/components/FeatureTrainingModalTest.tsx +++ b/tests/ui/components/FeatureTrainingModalTest.tsx @@ -5,7 +5,6 @@ import Onyx from 'react-native-onyx'; import ReceiptDoc from '@assets/images/receipt-doc.png'; import ComposeProviders from '@components/ComposeProviders'; import FeatureTrainingModal from '@components/FeatureTrainingModal'; -import OnyxListItemProvider from '@components/OnyxListItemProvider'; import {FullScreenContextProvider} from '@components/VideoPlayerContexts/FullScreenContext'; import {PlaybackContextProvider} from '@components/VideoPlayerContexts/PlaybackContext'; import {VideoPopoverMenuContextProvider} from '@components/VideoPlayerContexts/VideoPopoverMenuContext'; @@ -43,7 +42,7 @@ describe('FeatureTrainingModal', () => { describe('renderIllustration', () => { it('renders video', () => { render( - + { - it('should add encryptedAuthToken with ? when URL has no parameters', () => { - const result = addEncryptedAuthTokenToURL(FILE_URL, ENCRYPTED_TOKEN); - expect(result).toBe(`${FILE_URL}?encryptedAuthToken=${ENCRYPTED_TOKEN}`); - }); - - it('should add encryptedAuthToken with & when URL has existing parameters', () => { - const result = addEncryptedAuthTokenToURL(FILE_URL, ENCRYPTED_TOKEN, true); - expect(result).toBe(`${FILE_URL}&encryptedAuthToken=${ENCRYPTED_TOKEN}`); - }); -}); diff --git a/tests/unit/useDownloadAttachmentTest.ts b/tests/unit/useDownloadAttachmentTest.ts deleted file mode 100644 index e607cd61cbe91..0000000000000 --- a/tests/unit/useDownloadAttachmentTest.ts +++ /dev/null @@ -1,56 +0,0 @@ -import {renderHook} from '@testing-library/react-native'; -import Onyx from 'react-native-onyx'; -import OnyxListItemProvider from '@components/OnyxListItemProvider'; -import fileDownload from '@libs/fileDownload'; -import useDownloadAttachment from '@pages/media/AttachmentModalScreen/routes/hooks/useDownloadAttachment'; -import ONYXKEYS from '@src/ONYXKEYS'; - -jest.mock('@libs/fileDownload'); - -const mockFileDownload = fileDownload as jest.MockedFunction; - -const ENCRYPTED_TOKEN = 'testEncryptedToken123'; -const FILE_URL = 'https://example.com/file.jpg'; - -describe('useDownloadAttachment', () => { - beforeAll(() => { - Onyx.init({ - keys: ONYXKEYS, - initialKeyStates: { - [ONYXKEYS.SESSION]: {encryptedAuthToken: ENCRYPTED_TOKEN}, - }, - }); - }); - - beforeEach(() => { - mockFileDownload.mockClear(); - }); - - afterEach(() => Onyx.clear()); - - it('should add encryptedAuthToken to URL when isAuthTokenRequired is true', async () => { - const {result} = renderHook(() => useDownloadAttachment({isAuthTokenRequired: true}), {wrapper: OnyxListItemProvider}); - - result.current({source: FILE_URL, file: {name: 'file.jpg'}}); - - expect(mockFileDownload).toHaveBeenCalledWith( - expect.anything(), - `${FILE_URL}?encryptedAuthToken=${ENCRYPTED_TOKEN}`, - 'file.jpg', - undefined, - undefined, - undefined, - undefined, - undefined, - true, - ); - }); - - it('should NOT add encryptedAuthToken to URL when isAuthTokenRequired is false', async () => { - const {result} = renderHook(() => useDownloadAttachment({isAuthTokenRequired: false}), {wrapper: OnyxListItemProvider}); - - result.current({source: FILE_URL, file: {name: 'file.jpg'}}); - - expect(mockFileDownload).toHaveBeenCalledWith(expect.anything(), FILE_URL, 'file.jpg', undefined, undefined, undefined, undefined, undefined, true); - }); -});