| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { |
| 4 | composerAttachmentFileReferenceKey, |
| 5 | resolveOwnedComposerAttachmentFileUri, |
| 6 | } from "./composerAttachmentFiles"; |
| 7 | |
| 8 | const OLD_CONTAINER = "11111111-1111-4111-8111-111111111111"; |
| 9 | const CURRENT_CONTAINER = "22222222-2222-4222-8222-222222222222"; |
| 10 | const FILE_NAME = "33333333-3333-4333-8333-333333333333-report%20%252F%20%23.pdf"; |
| 11 | |
| 12 | describe("owned attachment paths", () => { |
| 13 | it.each([ |
| 14 | "file:///var/mobile/Containers/Data/Application/", |
| 15 | "file:///Users/dev/Library/Developer/CoreSimulator/Devices/device/data/Containers/Data/Application/", |
| 16 | ])("resolves saved files after an iOS container move under %s", (prefix) => { |
| 17 | const oldUri = `${prefix}${OLD_CONTAINER}/Documents/t3-composer-attachments/${FILE_NAME}`; |
| 18 | const documentUri = `${prefix}${CURRENT_CONTAINER}/Documents/`; |
| 19 | const currentUri = `${documentUri}t3-composer-attachments/${FILE_NAME}`; |
| 20 | |
| 21 | expect(resolveOwnedComposerAttachmentFileUri(oldUri, documentUri)).toBe(currentUri); |
| 22 | expect(composerAttachmentFileReferenceKey(oldUri)).toBe( |
| 23 | composerAttachmentFileReferenceKey(currentUri), |
| 24 | ); |
| 25 | }); |
| 26 | |
| 27 | it("recognizes the private/var alias without changing the stored filename", () => { |
| 28 | const oldUri = `file:///private/var/mobile/Containers/Data/Application/${OLD_CONTAINER}/Documents/t3-composer-attachments/${FILE_NAME}`; |
| 29 | const documentUri = `file:///var/mobile/Containers/Data/Application/${CURRENT_CONTAINER}/Documents/`; |
| 30 | const currentUri = `${documentUri}t3-composer-attachments/${FILE_NAME}`; |
| 31 | |
| 32 | expect(resolveOwnedComposerAttachmentFileUri(oldUri, documentUri)).toBe(currentUri); |
| 33 | expect(composerAttachmentFileReferenceKey(oldUri)).toBe( |
| 34 | composerAttachmentFileReferenceKey(currentUri), |
| 35 | ); |
| 36 | }); |
| 37 | |
| 38 | it.each([ |
| 39 | `file:///private/var/mobile/Containers/Shared/FileProvider/other/Documents/t3-composer-attachments/${FILE_NAME}`, |
| 40 | `file:///var/mobile/Containers/Shared/AppGroup/other/t3-composer-attachments/${FILE_NAME}`, |
| 41 | `file:///var/mobile/Containers/Data/Application/${OLD_CONTAINER}/Documents/report.pdf`, |
| 42 | `file:///var/mobile/Containers/Data/Application/${OLD_CONTAINER}/Documents/t3-composer-attachments/report.pdf`, |
| 43 | `file:///downloads/t3-composer-attachments/${FILE_NAME}`, |
| 44 | `content://shared/t3-composer-attachments/${FILE_NAME}`, |
| 45 | `https://example.com/t3-composer-attachments/${FILE_NAME}`, |
| 46 | `file:///var/mobile/Containers/Data/Application/${OLD_CONTAINER}/Documents/t3-composer-attachments/..%2F..%2Fsender.pdf`, |
| 47 | `file:///var/mobile/Containers/Data/Application/${OLD_CONTAINER}/Documents/t3-composer-attachments/${FILE_NAME}%2Fnested.pdf`, |
| 48 | ])("does not rebase an external or escaped path: %s", (uri) => { |
| 49 | expect( |
| 50 | resolveOwnedComposerAttachmentFileUri( |
| 51 | uri, |
| 52 | `file:///var/mobile/Containers/Data/Application/${CURRENT_CONTAINER}/Documents/`, |
| 53 | ), |
| 54 | ).toBeNull(); |
| 55 | }); |
| 56 | }); |