Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAndBear committed Oct 25, 2023
1 parent 10f390f commit 12abdb3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: Add permission to delete link passwords when password is enforced

We've enabled to ability to allow delete passwords on public links, even if the password is enforced.
Therefore, the user needs respective permission, granted by the server.
This feature is only possible on public links that have the viewer role.

https://github.com/owncloud/web/pull/9857
https://github.com/owncloud/ocis/issues/7538
9 changes: 6 additions & 3 deletions packages/web-pkg/src/helpers/share/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { showQuickLinkPasswordModal } from '../../quickActions'

export interface CreateQuicklink {
clientService: ClientService
passwordPolicyService: PasswordPolicyService
language: Language
store: Store<any>
storageId?: any
Expand All @@ -27,6 +26,10 @@ export interface CreateQuicklink {
ability: Ability
}

export interface CopyQuickLink extends CreateQuicklink {
passwordPolicyService: PasswordPolicyService
}

// doCopy creates the requested link and copies the url to the clipboard,
// the copy action uses the clipboard // clipboardItem api to work around the webkit limitations.
//
Expand Down Expand Up @@ -68,12 +71,12 @@ const doCopy = async ({
})
}
}
export const copyQuicklink = async (args: CreateQuicklink) => {
export const copyQuicklink = async (args: CopyQuickLink) => {
const { store, language, resource, clientService, passwordPolicyService } = args
const { $gettext } = language

const linkSharesForResource = await clientService.owncloudSdk.shares.getShares(resource.path, {
share_types: ShareTypes.link.value.toString(),
share_types: ShareTypes?.link?.value?.toString(),
include_tags: false
})

Expand Down
28 changes: 25 additions & 3 deletions packages/web-pkg/tests/unit/helpers/share/link.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { copyQuicklink, createQuicklink, CreateQuicklink } from '../../../../src/helpers/share'
import { DateTime } from 'luxon'
import { Store } from 'vuex'
import { ClientService } from '../../../../src/services'
import { ClientService, PasswordPolicyService } from '../../../../src/services'
import { useClipboard } from '@vueuse/core'
import { Ability } from '@ownclouders/web-client/src/helpers/resource/types'
import { mock, mockDeep } from 'jest-mock-extended'
Expand All @@ -13,6 +13,19 @@ jest.mock('@vueuse/core', () => ({
}))

const mockStore = {
getters: {
capabilities: {
files_sharing: {
public: {
password: {
enforced_for: {
read_only: false
}
}
}
}
}
},
state: {
user: {
capabilities: {
Expand All @@ -24,6 +37,11 @@ const mockStore = {
expire_date: {
enforced: true,
days: 5
},
password: {
enforced_for: {
read_only: false
}
}
}
}
Expand Down Expand Up @@ -51,6 +69,8 @@ jest.mock('@ownclouders/web-client/src/helpers/share', () => ({
describe('createQuicklink', () => {
it('should create a quicklink with the correct parameters', async () => {
const clientService = mockDeep<ClientService>()
clientService.owncloudSdk.shares.getShares.mockResolvedValue([])
const passwordPolicyService = mockDeep<PasswordPolicyService>()
const args: CreateQuicklink = {
store: mockStore as unknown as Store<any>,
resource: mockResource,
Expand All @@ -65,7 +85,7 @@ describe('createQuicklink', () => {
expect(link).toBeDefined()
expect(link.url).toBeDefined()

await copyQuicklink(args)
await copyQuicklink({ ...args, passwordPolicyService })
expect(useClipboard).toHaveBeenCalled()

expect(mockStore.dispatch).toHaveBeenCalledWith('Files/addLink', {
Expand All @@ -91,6 +111,8 @@ describe('createQuicklink', () => {
'should create a quicklink without a password if no password is provided and capabilities set to default %s',
async (role) => {
const clientService = mockDeep<ClientService>()
clientService.owncloudSdk.shares.getShares.mockResolvedValue([])
const passwordPolicyService = mockDeep<PasswordPolicyService>()
returnBitmask = role === 'viewer' ? 1 : 0
mockStore.state.user.capabilities.files_sharing.quickLink.default_role = role

Expand All @@ -107,7 +129,7 @@ describe('createQuicklink', () => {
expect(link).toBeDefined()
expect(link.url).toBeDefined()

await copyQuicklink(args)
await copyQuicklink({ ...args, passwordPolicyService })
expect(useClipboard).toHaveBeenCalled()

expect(mockStore.dispatch).toHaveBeenCalledWith('Files/addLink', {
Expand Down

0 comments on commit 12abdb3

Please sign in to comment.