FilesIntegrationTests.swift 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // NextcloudIntegrationTests.swift
  3. // NextcloudIntegrationTests
  4. //
  5. // Created by Milen Pivchev on 5/19/23.
  6. // Copyright © 2023 Marino Faggiana. All rights reserved.
  7. //
  8. // This program is free software: you can redistribute it and/or modify
  9. // it under the terms of the GNU General Public License as published by
  10. // the Free Software Foundation, either version 3 of the License, or
  11. // (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 General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU General Public License
  19. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. //
  21. import XCTest
  22. import NextcloudKit
  23. @testable import Nextcloud
  24. final class FilesIntegrationTests: BaseIntegrationXCTestCase {
  25. override func setUp() {
  26. NCAccount().deleteAllAccounts()
  27. }
  28. func test_createReadDeleteFolder_withProperParams_shouldCreateReadDeleteFolder() throws {
  29. let expectation = expectation(description: "Should finish last callback")
  30. let folderName = "TestFolder\(randomInt)"
  31. let serverUrl = "\(TestConstants.server)/remote.php/dav/files/\(TestConstants.username)"
  32. let serverUrlFileName = "\(serverUrl)/\(folderName)"
  33. let domain = NCDomain.Domain(account: TestConstants.account, urlBase: TestConstants.server, user: TestConstants.username, userId: TestConstants.username, sceneIdentifier: "")
  34. NextcloudKit.shared.setup(delegate: NCNetworking.shared)
  35. NextcloudKit.shared.appendAccount(TestConstants.account, urlBase: TestConstants.server, user: TestConstants.username, userId: TestConstants.username, password: appToken, userAgent: userAgent, nextcloudVersion: 0, groupIdentifier: NCBrandOptions.shared.capabilitiesGroup)
  36. // Test creating folder
  37. NCNetworking.shared.createFolder(fileName: folderName, serverUrl: serverUrl, overwrite: true, withPush: true, sceneIdentifier: nil, domain: domain) { error in
  38. XCTAssertEqual(NKError.success.errorCode, error.errorCode)
  39. XCTAssertEqual(NKError.success.errorDescription, error.errorDescription)
  40. Thread.sleep(forTimeInterval: 1)
  41. // Test reading folder, should exist
  42. NCNetworking.shared.readFolder(serverUrl: serverUrlFileName, account: TestConstants.username) { account, metadataFolder, _, _, _, _ in
  43. XCTAssertEqual(TestConstants.account, account)
  44. XCTAssertEqual(NKError.success.errorCode, error.errorCode)
  45. XCTAssertEqual(NKError.success.errorDescription, error.errorDescription)
  46. XCTAssertEqual(metadataFolder?.fileName, folderName)
  47. // Check Realm directory, should exist
  48. let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "serverUrl == %@", serverUrlFileName))
  49. XCTAssertNotNil(directory)
  50. Thread.sleep(forTimeInterval: 1)
  51. Task {
  52. // Test deleting folder
  53. await _ = NCNetworking.shared.deleteMetadata(metadataFolder!)
  54. XCTAssertEqual(NKError.success.errorCode, error.errorCode)
  55. XCTAssertEqual(NKError.success.errorDescription, error.errorDescription)
  56. try await Task.sleep(for: .seconds(1))
  57. // Test reading folder, should NOT exist
  58. NCNetworking.shared.readFolder(serverUrl: serverUrlFileName, account: TestConstants.username) { account, metadataFolder, _, _, _, _ in
  59. defer { expectation.fulfill() }
  60. XCTAssertEqual(0, error.errorCode)
  61. XCTAssertNil(metadataFolder?.fileName)
  62. // Check Realm directory, should NOT exist
  63. let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "serverUrl == %@", serverUrlFileName))
  64. XCTAssertNil(directory)
  65. }
  66. }
  67. }
  68. }
  69. waitForExpectations(timeout: TestConstants.timeoutLong)
  70. }
  71. }