From 3698b7282ac51a2d8d114478d30955c20db875b7 Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Mon, 11 Dec 2023 09:29:35 +0100 Subject: [PATCH 1/2] fix: resolve share jail private link in both formats --- .../src/pages/resolvePrivateLink.vue | 7 +++- .../unit/pages/resolvePrivateLink.spec.ts | 39 ++++++++++++------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/packages/web-runtime/src/pages/resolvePrivateLink.vue b/packages/web-runtime/src/pages/resolvePrivateLink.vue index 97841fbe31c..48ca136b879 100644 --- a/packages/web-runtime/src/pages/resolvePrivateLink.vue +++ b/packages/web-runtime/src/pages/resolvePrivateLink.vue @@ -91,7 +91,12 @@ export default defineComponent({ const resolvePrivateLinkTask = useTask(function* (signal, id) { try { - if (id === `${SHARE_JAIL_ID}$${SHARE_JAIL_ID}!${SHARE_JAIL_ID}`) { + if ( + [ + `${SHARE_JAIL_ID}$${SHARE_JAIL_ID}!${SHARE_JAIL_ID}`, + `${SHARE_JAIL_ID}$${SHARE_JAIL_ID}` + ].includes(id) + ) { return router.push(createLocationShares('files-shares-with-me')) } diff --git a/packages/web-runtime/tests/unit/pages/resolvePrivateLink.spec.ts b/packages/web-runtime/tests/unit/pages/resolvePrivateLink.spec.ts index cd2697c588e..e744f6b5dae 100644 --- a/packages/web-runtime/tests/unit/pages/resolvePrivateLink.spec.ts +++ b/packages/web-runtime/tests/unit/pages/resolvePrivateLink.spec.ts @@ -14,6 +14,7 @@ import { useGetResourceContext } from '@ownclouders/web-pkg' import { Resource, SpaceResource } from '@ownclouders/web-client' +import { SHARE_JAIL_ID } from '@ownclouders/web-client/src/helpers' jest.mock('@ownclouders/web-pkg', () => ({ ...jest.requireActual('@ownclouders/web-pkg'), @@ -48,21 +49,33 @@ describe('resolvePrivateLink', () => { }) ) }) - it('resolves to "files-shares-with-me" for received single file shares', async () => { - const fileId = '1' - const driveAliasAndItem = 'shares/someShare' - const space = mock({ - driveType: 'share', - getDriveAliasAndItem: () => driveAliasAndItem + describe('resolves to "files-shares-with-me"', () => { + it('resolves for single file shares', async () => { + const fileId = '1' + const driveAliasAndItem = 'shares/someShare' + const space = mock({ + driveType: 'share', + getDriveAliasAndItem: () => driveAliasAndItem + }) + const resource = mock({ fileId, type: 'file' }) + const { wrapper, mocks } = getWrapper({ space, resource, fileId, path: '/' }) + await wrapper.vm.resolvePrivateLinkTask.last + expect(mocks.$router.push).toHaveBeenCalledWith( + expect.objectContaining({ name: 'files-shares-with-me' }) + ) + }) + it.each([ + `${SHARE_JAIL_ID}$${SHARE_JAIL_ID}`, + `${SHARE_JAIL_ID}$${SHARE_JAIL_ID}!${SHARE_JAIL_ID}` + ])('resolves for the share jail id', async (fileId) => { + const { wrapper, mocks } = getWrapper({ fileId }) + await wrapper.vm.resolvePrivateLinkTask.last + expect(mocks.$router.push).toHaveBeenCalledWith( + expect.objectContaining({ name: 'files-shares-with-me' }) + ) }) - const resource = mock({ fileId, type: 'file' }) - const { wrapper, mocks } = getWrapper({ space, resource, fileId, path: '/' }) - await wrapper.vm.resolvePrivateLinkTask.last - expect(mocks.$router.push).toHaveBeenCalledWith( - expect.objectContaining({ name: 'files-shares-with-me' }) - ) }) - it('passes the details query paramif given via query', async () => { + it('passes the details query param if given via query', async () => { const details = 'sharing' const { wrapper, mocks } = getWrapper({ details }) await wrapper.vm.resolvePrivateLinkTask.last From 2fd7a88d749ee9fc3b81a6ce95343bee29b73642 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Mon, 11 Dec 2023 14:36:39 +0100 Subject: [PATCH 2/2] test: fix private link unit tests --- .../unit/pages/resolvePrivateLink.spec.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/web-runtime/tests/unit/pages/resolvePrivateLink.spec.ts b/packages/web-runtime/tests/unit/pages/resolvePrivateLink.spec.ts index e744f6b5dae..4ecf499de53 100644 --- a/packages/web-runtime/tests/unit/pages/resolvePrivateLink.spec.ts +++ b/packages/web-runtime/tests/unit/pages/resolvePrivateLink.spec.ts @@ -18,8 +18,8 @@ import { SHARE_JAIL_ID } from '@ownclouders/web-client/src/helpers' jest.mock('@ownclouders/web-pkg', () => ({ ...jest.requireActual('@ownclouders/web-pkg'), - useRouteQuery: jest.fn(), - useRouteParam: jest.fn(), + useRouteQuery: jest.fn((str) => str), + useRouteParam: jest.fn((str) => str), queryItemAsString: jest.fn(), useGetResourceContext: jest.fn(), useConfigurationManager: jest.fn() @@ -130,9 +130,18 @@ function getWrapper({ openWithDefaultAppQuery = 'true', openLinksWithDefaultApp = true } = {}) { - jest.mocked(queryItemAsString).mockReturnValueOnce(fileId) - jest.mocked(queryItemAsString).mockReturnValueOnce(openWithDefaultAppQuery) - jest.mocked(queryItemAsString).mockReturnValueOnce(details) + jest.mocked(queryItemAsString).mockImplementation((str: string) => { + if (str === 'fileId') { + return fileId + } + if (str === 'openWithDefaultApp') { + return openWithDefaultAppQuery + } + if (str === 'details') { + return details + } + return str + }) jest.mocked(useGetResourceContext).mockReturnValue({ getResourceContext: jest.fn().mockResolvedValue({ space, resource, path })