Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions apps/files_sharing/src/services/SharingService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,25 @@ describe('SharingService share to Node mapping', () => {
accepted: false,
}

const remoteFolderAccepted = {
mimetype: 'httpd/unix-directory',
mtime: 1688721600,
permissions: 31,
type: 'dir',
file_id: 5678,
id: 5,
share_type: ShareType.User,
parent: null,
remote: 'http://example.com',
remote_id: '12346',
share_token: 'share-token-folder',
name: '/testfolder',
mountpoint: '/shares/testfolder',
owner: 'owner-uid',
user: 'sharee-uid',
accepted: true,
}

const tempExternalFile = {
id: 65,
share_type: 0,
Expand Down Expand Up @@ -455,6 +474,36 @@ describe('SharingService share to Node mapping', () => {
})
})

describe('Remote folder', () => {
test('Accepted with type dir', async () => {
axios.get.mockReturnValueOnce(Promise.resolve({
data: {
ocs: {
data: [remoteFolderAccepted],
},
},
}))

const shares = await getContents(false, true, false, false)

expect(axios.get).toHaveBeenCalledTimes(1)
expect(shares.contents).toHaveLength(1)

const folder = shares.contents[0] as Folder
expect(folder).toBeInstanceOf(Folder)
expect(folder.fileid).toBe(5678)
expect(folder.source).toBe('http://nextcloud.local/remote.php/dav/files/test/shares/testfolder')
expect(folder.owner).toBe('owner-uid')
expect(folder.mime).toBe('httpd/unix-directory')
expect(folder.mtime?.getTime()).toBe(remoteFolderAccepted.mtime * 1000)
expect(folder.size).toBe(undefined)
expect(folder.permissions).toBe(31)
expect(folder.root).toBe('/files/test')
expect(folder.attributes).toBeInstanceOf(Object)
expect(folder.attributes.favorite).toBe(0)
})
})

test('External temp file', async () => {
axios.get.mockReturnValueOnce(Promise.resolve({
data: {
Expand Down
3 changes: 2 additions & 1 deletion apps/files_sharing/src/services/SharingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const ocsEntryToNode = async function(ocsEntry: any): Promise<Folder | File | nu
// This won't catch files without an extension, but this is the best we can do
ocsEntry.mimetype = mime.getType(ocsEntry.name)
}
ocsEntry.item_type = ocsEntry.type || (ocsEntry.mimetype ? 'file' : 'folder')
const type = ocsEntry.type === 'dir' ? 'folder' : ocsEntry.type
ocsEntry.item_type = type || (ocsEntry.mimetype ? 'file' : 'folder')

// different naming for remote shares
ocsEntry.item_mtime = ocsEntry.mtime
Expand Down
Loading