FilesIntegrationTests.swift 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. private let appDelegate = (UIApplication.shared.delegate as? AppDelegate)!
  26. override func setUp() {
  27. appDelegate.deleteAllAccounts()
  28. }
  29. func test_createReadDeleteFolder_withProperParams_shouldCreateReadDeleteFolder() throws {
  30. let expectation = expectation(description: "Should finish last callback")
  31. let folderName = "TestFolder\(randomInt)"
  32. let serverUrl = "\(TestConstants.server)/remote.php/dav/files/\(TestConstants.username)"
  33. let serverUrlFileName = "\(serverUrl)/\(folderName)"
  34. NextcloudKit.shared.setup(account: TestConstants.account, user: TestConstants.username, userId: TestConstants.username, password: appToken, urlBase: TestConstants.server)
  35. // Test creating folder
  36. NCNetworking.shared.createFolder(fileName: folderName, serverUrl: serverUrl, account: TestConstants.account, urlBase: TestConstants.server, userId: TestConstants.username, withPush: true, sceneIdentifier: nil) { error in
  37. XCTAssertEqual(NKError.success.errorCode, error.errorCode)
  38. XCTAssertEqual(NKError.success.errorDescription, error.errorDescription)
  39. Thread.sleep(forTimeInterval: 1)
  40. // Test reading folder, should exist
  41. NCNetworking.shared.readFolder(serverUrl: serverUrlFileName, account: TestConstants.username) { account, metadataFolder, _, _, _, _ in
  42. XCTAssertEqual(TestConstants.account, account)
  43. XCTAssertEqual(NKError.success.errorCode, error.errorCode)
  44. XCTAssertEqual(NKError.success.errorDescription, error.errorDescription)
  45. XCTAssertEqual(metadataFolder?.fileName, folderName)
  46. // Check Realm directory, should exist
  47. let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "serverUrl == %@", serverUrlFileName))
  48. XCTAssertNotNil(directory)
  49. Thread.sleep(forTimeInterval: 1)
  50. Task {
  51. // Test deleting folder
  52. await _ = NCNetworking.shared.deleteMetadata(metadataFolder!, onlyLocalCache: false)
  53. XCTAssertEqual(NKError.success.errorCode, error.errorCode)
  54. XCTAssertEqual(NKError.success.errorDescription, error.errorDescription)
  55. try await Task.sleep(for: .seconds(1))
  56. // Test reading folder, should NOT exist
  57. NCNetworking.shared.readFolder(serverUrl: serverUrlFileName, account: TestConstants.username) { account, metadataFolder, _, _, _, _ in
  58. defer { expectation.fulfill() }
  59. XCTAssertEqual(0, error.errorCode)
  60. XCTAssertNil(metadataFolder?.fileName)
  61. // Check Realm directory, should NOT exist
  62. let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "serverUrl == %@", serverUrlFileName))
  63. XCTAssertNil(directory)
  64. }
  65. }
  66. }
  67. }
  68. waitForExpectations(timeout: TestConstants.timeoutLong)
  69. }
  70. }