externalStorageUtils.spec.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
  3. *
  4. * @author John Molakvoæ <skjnldsv@protonmail.com>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. import { expect } from '@jest/globals'
  23. import { File, Folder, Permission } from '@nextcloud/files'
  24. import { isNodeExternalStorage } from './externalStorageUtils'
  25. describe('Is node an external storage', () => {
  26. test('A Folder with a backend and a valid scope is an external storage', () => {
  27. const folder = new Folder({
  28. id: 1,
  29. source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/',
  30. owner: 'admin',
  31. permissions: Permission.ALL,
  32. attributes: {
  33. scope: 'personal',
  34. backend: 'SFTP',
  35. },
  36. })
  37. expect(isNodeExternalStorage(folder)).toBe(true)
  38. })
  39. test('a File is not a valid storage', () => {
  40. const file = new File({
  41. id: 1,
  42. source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
  43. owner: 'admin',
  44. mime: 'text/plain',
  45. permissions: Permission.ALL,
  46. })
  47. expect(isNodeExternalStorage(file)).toBe(false)
  48. })
  49. test('A Folder without a backend is not a storage', () => {
  50. const folder = new Folder({
  51. id: 1,
  52. source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/',
  53. owner: 'admin',
  54. permissions: Permission.ALL,
  55. attributes: {
  56. scope: 'personal',
  57. },
  58. })
  59. expect(isNodeExternalStorage(folder)).toBe(false)
  60. })
  61. test('A Folder without a scope is not a storage', () => {
  62. const folder = new Folder({
  63. id: 1,
  64. source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/',
  65. owner: 'admin',
  66. permissions: Permission.ALL,
  67. attributes: {
  68. backend: 'SFTP',
  69. },
  70. })
  71. expect(isNodeExternalStorage(folder)).toBe(false)
  72. })
  73. test('A Folder with an invalid scope is not a storage', () => {
  74. const folder = new Folder({
  75. id: 1,
  76. source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/',
  77. owner: 'admin',
  78. permissions: Permission.ALL,
  79. attributes: {
  80. scope: 'null',
  81. backend: 'SFTP',
  82. },
  83. })
  84. expect(isNodeExternalStorage(folder)).toBe(false)
  85. })
  86. })