Skip to content

Commit

Permalink
feat: Remove isFlatDomain from getSharingLink
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The client already carries this information,
if need to change this value, please update the client.
  • Loading branch information
Merkur39 committed Dec 1, 2023
1 parent 872a9d4 commit 7d768de
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
5 changes: 2 additions & 3 deletions docs/api/cozy-client/modules/models.sharing.md
Expand Up @@ -8,7 +8,7 @@

### getSharingLink

**getSharingLink**(`client`, `filesIds`, `isFlatDomain`): `Promise`<`string`>
**getSharingLink**(`client`, `filesIds`): `Promise`<`string`>

Generate Sharing link for one or many files

Expand All @@ -18,7 +18,6 @@ Generate Sharing link for one or many files
| :------ | :------ | :------ |
| `client` | [`CozyClient`](../classes/CozyClient.md) | Instance of CozyClient |
| `filesIds` | `string`\[] | Array of io.cozy.files ids |
| `isFlatDomain` | `boolean` | - |

*Returns*

Expand All @@ -28,4 +27,4 @@ Shared link

*Defined in*

[packages/cozy-client/src/models/sharing.js:13](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/sharing.js#L13)
[packages/cozy-client/src/models/sharing.js:12](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/models/sharing.js#L12)
5 changes: 2 additions & 3 deletions packages/cozy-client/src/models/sharing.js
Expand Up @@ -7,10 +7,9 @@ import { generateWebLink } from '../helpers'
*
* @param {CozyClient} client - Instance of CozyClient
* @param {string[]} filesIds - Array of io.cozy.files ids
* @param {boolean} [isFlatDomain] -
* @returns {Promise<string>} Shared link
*/
export const getSharingLink = async (client, filesIds, isFlatDomain) => {
export const getSharingLink = async (client, filesIds) => {
const PERMS = {
_type: DOCTYPE_PERMISSIONS,
permissions: {
Expand All @@ -24,7 +23,7 @@ export const getSharingLink = async (client, filesIds, isFlatDomain) => {
searchParams: [['sharecode', sharedLink?.attributes?.shortcodes?.code]],
pathname: '/public',
slug: 'drive',
subDomainType: isFlatDomain ? 'flat' : 'nested'
subDomainType: client.capabilities.flat_subdomains ? 'flat' : 'nested'
})

return webLink
Expand Down
23 changes: 10 additions & 13 deletions packages/cozy-client/src/models/sharing.spec.js
Expand Up @@ -2,29 +2,28 @@ import { getSharingLink } from './sharing'

describe('getSharingLink', () => {
const mockSharecode = { attributes: { shortcodes: { code: 'shortcode' } } }
const mockClient = {
const mockClient = ({ isFlatDomain = false } = {}) => ({
save: jest.fn(() => ({ data: mockSharecode })),
getStackClient: jest.fn(() => ({ uri: 'http://cozy.cloud' }))
}
getStackClient: jest.fn(() => ({ uri: 'http://cozy.cloud' })),
capabilities: { flat_subdomains: isFlatDomain }
})
const mockFiles = [
{ id: 'fileId01', name: 'File 01' },
{ id: 'fileId02', name: 'File 02' }
]

it('should generate the right share link if "isFlatDomain" param is not defined', async () => {
const sharingLink = await getSharingLink(mockClient, mockFiles)
const sharingLink = await getSharingLink(mockClient(), mockFiles)

expect(sharingLink).toBe(
'http://drive.cozy.cloud/public?sharecode=shortcode#/'
)
})

it('should generate the right share link to a nested cozy', async () => {
const isFlatDomain = false
const sharingLink = await getSharingLink(
mockClient,
mockFiles,
isFlatDomain
mockClient({ isFlatDomain: false }),
mockFiles
)

expect(sharingLink).toBe(
Expand All @@ -33,11 +32,9 @@ describe('getSharingLink', () => {
})

it('should generate the right share link to a flat cozy', async () => {
const isFlatDomain = true
const sharingLink = await getSharingLink(
mockClient,
mockFiles,
isFlatDomain
mockClient({ isFlatDomain: true }),
mockFiles
)

expect(sharingLink).toBe(
Expand All @@ -46,7 +43,7 @@ describe('getSharingLink', () => {
})

it('should generate the right share link with an correct sharecode', async () => {
const sharingLink = await getSharingLink(mockClient, mockFiles)
const sharingLink = await getSharingLink(mockClient(), mockFiles)

expect(sharingLink).toContain('sharecode=shortcode')
})
Expand Down
2 changes: 1 addition & 1 deletion packages/cozy-client/types/models/sharing.d.ts
@@ -1,2 +1,2 @@
export function getSharingLink(client: CozyClient, filesIds: string[], isFlatDomain?: boolean): Promise<string>;
export function getSharingLink(client: CozyClient, filesIds: string[]): Promise<string>;
import CozyClient from "../CozyClient";

0 comments on commit 7d768de

Please sign in to comment.