PendingMessagesManagerTests.swift 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2019-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  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 <https://www.gnu.org/licenses/>.
  20. import XCTest
  21. @testable import Threema
  22. class PendingMessagesManagerTests: XCTestCase {
  23. private var mockValidationLogger: ValidationLoggerMock?
  24. private var mockLogger: TestLoggerMock?
  25. private let testLogMessage: String = "PendingMessagesManager.pendingMessage: Some arguments invalid, no key or sender identity could be evaluated"
  26. override func setUp() {
  27. super.setUp()
  28. // necessary for ValidationLogger
  29. AppGroup.setGroupId("group.ch.threema") //THREEMA_GROUP_IDENTIFIER @"group.ch.threema"
  30. mockLogger = TestLoggerMock()
  31. DDLog.add(mockLogger!, with: .all)
  32. }
  33. override func tearDown() {
  34. DDLog.remove(mockLogger!)
  35. }
  36. func testPendingMessageAllNil() {
  37. let pm = PendingMessagesManager.shared
  38. pm.pendingMessage(senderId: nil, messageId: nil, abstractMessage: nil, threemaDict: nil, completion: { pendingMessage in })
  39. DDLog.flushLog()
  40. XCTAssertEqual(testLogMessage, mockLogger!.getTestLogMessage()?.message)
  41. }
  42. func testPendingMessageNothingNil() {
  43. let am: AbstractMessage = AbstractMessage()
  44. am.fromIdentity = "FROM-ID"
  45. let pm = PendingMessagesManager.shared
  46. pm.pendingMessage(senderId: "SENDER-ID", messageId: "msgid123", abstractMessage: am, threemaDict: nil, completion: { pendingMessage in
  47. XCTAssertNotNil(pendingMessage)
  48. XCTAssertEqual("FROM-ID", pendingMessage!.key.prefix(7))
  49. })
  50. DDLog.flushLog()
  51. XCTAssertNotEqual(testLogMessage, mockLogger!.getTestLogMessage()?.message)
  52. }
  53. func testPendingMessageSenderIdNilAndAbstractMessageNil() {
  54. let pm = PendingMessagesManager.shared
  55. pm.pendingMessage(senderId: nil, messageId: "msgid123", abstractMessage: nil, threemaDict: nil, completion: { pendingMessage in })
  56. DDLog.flushLog()
  57. XCTAssertEqual(testLogMessage, mockLogger!.getTestLogMessage()?.message)
  58. }
  59. func testPendingMessageMessageIdNilAndAbstractMessageNil() {
  60. let pm = PendingMessagesManager.shared
  61. pm.pendingMessage(senderId: "SENDER-ID", messageId: nil, abstractMessage: nil, threemaDict: nil, completion: { pendingMessage in })
  62. DDLog.flushLog()
  63. XCTAssertEqual(testLogMessage, mockLogger!.getTestLogMessage()?.message)
  64. }
  65. /* This crash -> is abstractMessage nil, must be threemaDict NOT nil !?!?
  66. func testPendingMessageAbstractMessageNil() {
  67. let pm = PendingMessagesManager.shared
  68. pm.pendingMessage(senderId: "SENDER-ID", messageId: "msgid123", abstractMessage: nil, threemaDict: nil, validationLogger: self.mockValidationLogger!, completion: { pendingMessage in
  69. XCTAssertNotNil(pendingMessage)
  70. XCTAssertEqual("FROM-IDmsgid123", pendingMessage!.key.prefix(7))
  71. })
  72. XCTAssertNotNil(pm)
  73. }
  74. */
  75. }