IntegrationRoomTest.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  3. // SPDX-License-Identifier: GPL-3.0-or-later
  4. //
  5. import XCTest
  6. import Foundation
  7. @testable import NextcloudTalk
  8. final class IntegrationRoomTest: TestBase {
  9. func testRoomList() throws {
  10. let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
  11. let exp = expectation(description: "\(#function)\(#line)")
  12. NCAPIController.sharedInstance().getRooms(forAccount: activeAccount, updateStatus: false, modifiedSince: 0) { rooms, error in
  13. XCTAssertNil(error)
  14. // By default, the room list should never be empty, it should contain atleast the talk changelog room
  15. XCTAssertGreaterThan(rooms?.count ?? 0, 0)
  16. exp.fulfill()
  17. }
  18. waitForExpectations(timeout: TestConstants.timeoutLong, handler: nil)
  19. }
  20. func testRoomCreation() throws {
  21. let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
  22. let roomName = "Integration Test Room " + UUID().uuidString
  23. let exp = expectation(description: "\(#function)\(#line)")
  24. // Create a room
  25. NCAPIController.sharedInstance().createRoom(forAccount: activeAccount, withInvite: nil, ofType: .public, andName: roomName) { _, error in
  26. XCTAssertNil(error)
  27. exp.fulfill()
  28. }
  29. waitForExpectations(timeout: TestConstants.timeoutLong, handler: nil)
  30. self.checkRoomExists(roomName: roomName, withAccount: activeAccount)
  31. }
  32. func testRoomDescription() throws {
  33. let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
  34. let roomName = "Description Test Room " + UUID().uuidString
  35. let roomDescription = "This is a room description"
  36. let exp = expectation(description: "\(#function)\(#line)")
  37. var roomToken = ""
  38. // Create a room
  39. NCAPIController.sharedInstance().createRoom(forAccount: activeAccount, withInvite: nil, ofType: .public, andName: roomName) { room, error in
  40. XCTAssertNil(error)
  41. roomToken = room?.token ?? ""
  42. exp.fulfill()
  43. }
  44. waitForExpectations(timeout: TestConstants.timeoutLong, handler: nil)
  45. let expDescription = expectation(description: "\(#function)\(#line)")
  46. // Set a description
  47. NCAPIController.sharedInstance().setRoomDescription(roomDescription, forRoom: roomToken, forAccount: activeAccount) { error in
  48. XCTAssertNil(error)
  49. expDescription.fulfill()
  50. }
  51. waitForExpectations(timeout: TestConstants.timeoutLong, handler: nil)
  52. self.checkRoomExists(roomName: roomName, withAccount: activeAccount) { room in
  53. XCTAssertEqual(room?.roomDescription, roomDescription)
  54. }
  55. }
  56. func testRoomRename() throws {
  57. let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
  58. let roomName = "Rename Test Room " + UUID().uuidString
  59. let roomNameNew = "\(roomName)- New"
  60. let exp = expectation(description: "\(#function)\(#line)")
  61. var roomToken = ""
  62. // Create a room
  63. NCAPIController.sharedInstance().createRoom(forAccount: activeAccount, withInvite: nil, ofType: .public, andName: roomName) { room, error in
  64. XCTAssertNil(error)
  65. roomToken = room?.token ?? ""
  66. exp.fulfill()
  67. }
  68. waitForExpectations(timeout: TestConstants.timeoutLong, handler: nil)
  69. let expNewName = expectation(description: "\(#function)\(#line)")
  70. // Set a new name
  71. NCAPIController.sharedInstance().renameRoom(roomToken, forAccount: activeAccount, withName: roomNameNew) { error in
  72. XCTAssertNil(error)
  73. expNewName.fulfill()
  74. }
  75. waitForExpectations(timeout: TestConstants.timeoutLong, handler: nil)
  76. self.checkRoomExists(roomName: roomNameNew, withAccount: activeAccount) { room in
  77. XCTAssertEqual(room?.displayName, roomNameNew)
  78. }
  79. }
  80. }