externalStorageUtils.spec.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. import { expect } from '@jest/globals'
  6. import { File, Folder, Permission } from '@nextcloud/files'
  7. import { isNodeExternalStorage } from './externalStorageUtils'
  8. describe('Is node an external storage', () => {
  9. test('A Folder with a backend and a valid scope is an external storage', () => {
  10. const folder = new Folder({
  11. id: 1,
  12. source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/',
  13. owner: 'admin',
  14. permissions: Permission.ALL,
  15. attributes: {
  16. scope: 'personal',
  17. backend: 'SFTP',
  18. },
  19. })
  20. expect(isNodeExternalStorage(folder)).toBe(true)
  21. })
  22. test('a File is not a valid storage', () => {
  23. const file = new File({
  24. id: 1,
  25. source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
  26. owner: 'admin',
  27. mime: 'text/plain',
  28. permissions: Permission.ALL,
  29. })
  30. expect(isNodeExternalStorage(file)).toBe(false)
  31. })
  32. test('A Folder without a backend is not a storage', () => {
  33. const folder = new Folder({
  34. id: 1,
  35. source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/',
  36. owner: 'admin',
  37. permissions: Permission.ALL,
  38. attributes: {
  39. scope: 'personal',
  40. },
  41. })
  42. expect(isNodeExternalStorage(folder)).toBe(false)
  43. })
  44. test('A Folder without a scope is not a storage', () => {
  45. const folder = new Folder({
  46. id: 1,
  47. source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/',
  48. owner: 'admin',
  49. permissions: Permission.ALL,
  50. attributes: {
  51. backend: 'SFTP',
  52. },
  53. })
  54. expect(isNodeExternalStorage(folder)).toBe(false)
  55. })
  56. test('A Folder with an invalid scope is not a storage', () => {
  57. const folder = new Folder({
  58. id: 1,
  59. source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/',
  60. owner: 'admin',
  61. permissions: Permission.ALL,
  62. attributes: {
  63. scope: 'null',
  64. backend: 'SFTP',
  65. },
  66. })
  67. expect(isNodeExternalStorage(folder)).toBe(false)
  68. })
  69. })