From 593acd8e376a556f4470310e478c63a1aa5f1fbf Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Mon, 8 May 2023 15:22:57 +1000 Subject: [PATCH] Fixed some broken tests and removed remaining remnants of the 'syncExpiries' job --- SessionMessagingKit/Database/Models/Contact.swift | 5 +++-- .../Open Groups/OpenGroupManagerSpec.swift | 8 +++++--- .../_TestUtilities/TestOnionRequestAPI.swift | 4 ++-- .../ThreadDisappearingMessagesViewModelSpec.swift | 14 ++++++++++---- .../Settings/ThreadSettingsViewModelSpec.swift | 2 +- SessionUtilitiesKit/Database/Models/Job.swift | 4 ---- SessionUtilitiesKit/Database/Storage.swift | 2 +- SessionUtilitiesKit/JobRunner/JobRunner.swift | 11 ----------- 8 files changed, 22 insertions(+), 28 deletions(-) diff --git a/SessionMessagingKit/Database/Models/Contact.swift b/SessionMessagingKit/Database/Models/Contact.swift index ef9138fda..aef6c4def 100644 --- a/SessionMessagingKit/Database/Models/Contact.swift +++ b/SessionMessagingKit/Database/Models/Contact.swift @@ -51,6 +51,7 @@ public struct Contact: Codable, Identifiable, Equatable, FetchableRecord, Persis // MARK: - Initialization public init( + _ db: Database? = nil, id: String, isTrusted: Bool = false, isApproved: Bool = false, @@ -62,7 +63,7 @@ public struct Contact: Codable, Identifiable, Equatable, FetchableRecord, Persis self.id = id self.isTrusted = ( isTrusted || - id == getUserHexEncodedPublicKey() // Always trust ourselves + id == getUserHexEncodedPublicKey(db) // Always trust ourselves ) self.isApproved = isApproved self.isBlocked = isBlocked @@ -105,7 +106,7 @@ public extension Contact { /// **Note:** This method intentionally does **not** save the newly created Contact, /// it will need to be explicitly saved after calling static func fetchOrCreate(_ db: Database, id: ID) -> Contact { - return ((try? fetchOne(db, id: id)) ?? Contact(id: id)) + return ((try? fetchOne(db, id: id)) ?? Contact(db, id: id)) } } diff --git a/SessionMessagingKitTests/Open Groups/OpenGroupManagerSpec.swift b/SessionMessagingKitTests/Open Groups/OpenGroupManagerSpec.swift index 03618a3b5..def2fe342 100644 --- a/SessionMessagingKitTests/Open Groups/OpenGroupManagerSpec.swift +++ b/SessionMessagingKitTests/Open Groups/OpenGroupManagerSpec.swift @@ -234,7 +234,9 @@ class OpenGroupManagerSpec: QuickSpec { mockGeneralCache.when { $0.encodedPublicKey }.thenReturn("05\(TestConstants.publicKey)") mockGenericHash.when { $0.hash(message: anyArray(), outputLength: any()) }.thenReturn([]) mockSodium - .when { $0.blindedKeyPair(serverPublicKey: any(), edKeyPair: any(), genericHash: mockGenericHash) } + .when { [mockGenericHash] mock in + mock.blindedKeyPair(serverPublicKey: any(), edKeyPair: any(), genericHash: mockGenericHash!) + } .thenReturn( Box.KeyPair( publicKey: Data.data(fromHex: TestConstants.publicKey)!.bytes, @@ -3568,11 +3570,11 @@ class OpenGroupManagerSpec: QuickSpec { it("adds the image retrieval promise to the cache") { class TestNeverReturningApi: OnionRequestAPIType { - static func sendOnionRequest(_ request: URLRequest, to server: String, using version: OnionRequestAPIVersion, with x25519PublicKey: String) -> Promise<(OnionRequestResponseInfoType, Data?)> { + static func sendOnionRequest(_ request: URLRequest, to server: String, using version: OnionRequestAPIVersion, with x25519PublicKey: String, timeout: TimeInterval) -> Promise<(OnionRequestResponseInfoType, Data?)> { return Promise<(OnionRequestResponseInfoType, Data?)>.pending().promise } - static func sendOnionRequest(to snode: Snode, invoking method: SnodeAPIEndpoint, with parameters: JSON, associatedWith publicKey: String?) -> Promise { + static func sendOnionRequest(to snode: Snode, invoking method: SnodeAPIEndpoint, with parameters: JSON, associatedWith publicKey: String?, timeout: TimeInterval) -> Promise { return Promise.value(Data()) } } diff --git a/SessionMessagingKitTests/_TestUtilities/TestOnionRequestAPI.swift b/SessionMessagingKitTests/_TestUtilities/TestOnionRequestAPI.swift index 67b7dde86..3da2fbdd4 100644 --- a/SessionMessagingKitTests/_TestUtilities/TestOnionRequestAPI.swift +++ b/SessionMessagingKitTests/_TestUtilities/TestOnionRequestAPI.swift @@ -34,7 +34,7 @@ class TestOnionRequestAPI: OnionRequestAPIType { class var mockResponse: Data? { return nil } - static func sendOnionRequest(_ request: URLRequest, to server: String, using version: OnionRequestAPIVersion, with x25519PublicKey: String) -> Promise<(OnionRequestResponseInfoType, Data?)> { + static func sendOnionRequest(_ request: URLRequest, to server: String, using version: OnionRequestAPIVersion, with x25519PublicKey: String, timeout: TimeInterval) -> Promise<(OnionRequestResponseInfoType, Data?)> { let responseInfo: ResponseInfo = ResponseInfo( requestData: RequestData( urlString: request.url?.absoluteString, @@ -54,7 +54,7 @@ class TestOnionRequestAPI: OnionRequestAPIType { return Promise.value((responseInfo, mockResponse)) } - static func sendOnionRequest(to snode: Snode, invoking method: SnodeAPIEndpoint, with parameters: JSON, associatedWith publicKey: String?) -> Promise { + static func sendOnionRequest(to snode: Snode, invoking method: SnodeAPIEndpoint, with parameters: JSON, associatedWith publicKey: String?, timeout: TimeInterval) -> Promise { return Promise.value(mockResponse!) } } diff --git a/SessionTests/Conversations/Settings/ThreadDisappearingMessagesViewModelSpec.swift b/SessionTests/Conversations/Settings/ThreadDisappearingMessagesViewModelSpec.swift index add0a3945..dee5e95b1 100644 --- a/SessionTests/Conversations/Settings/ThreadDisappearingMessagesViewModelSpec.swift +++ b/SessionTests/Conversations/Settings/ThreadDisappearingMessagesViewModelSpec.swift @@ -92,7 +92,9 @@ class ThreadDisappearingMessagesViewModelSpec: QuickSpec { title: "DISAPPEARING_MESSAGES_OFF".localized(), rightAccessory: .radio( isSelected: { true } - ) + ), + accessibilityIdentifier: "Off option", + accessibilityLabel: "Off option" ) ) ) @@ -138,7 +140,9 @@ class ThreadDisappearingMessagesViewModelSpec: QuickSpec { title: "DISAPPEARING_MESSAGES_OFF".localized(), rightAccessory: .radio( isSelected: { false } - ) + ), + accessibilityIdentifier: "Off option", + accessibilityLabel: "Off option" ) ) ) @@ -173,7 +177,9 @@ class ThreadDisappearingMessagesViewModelSpec: QuickSpec { title: title, rightAccessory: .radio( isSelected: { true } - ) + ), + accessibilityIdentifier: "Time option", + accessibilityLabel: "Time option" ) ) ) @@ -192,7 +198,7 @@ class ThreadDisappearingMessagesViewModelSpec: QuickSpec { ) ) - expect(footerButtonInfo).to(equal(nil)) + expect(footerButtonInfo).to(beNil()) } context("when changed from the previous setting") { diff --git a/SessionTests/Conversations/Settings/ThreadSettingsViewModelSpec.swift b/SessionTests/Conversations/Settings/ThreadSettingsViewModelSpec.swift index 0ecc1d0a6..57babeb54 100644 --- a/SessionTests/Conversations/Settings/ThreadSettingsViewModelSpec.swift +++ b/SessionTests/Conversations/Settings/ThreadSettingsViewModelSpec.swift @@ -228,7 +228,7 @@ class ThreadSettingsViewModelSpec: QuickSpec { ParentType.NavItem( id: .cancel, systemItem: .cancel, - accessibilityIdentifier: "Cancel" + accessibilityIdentifier: "Cancel button" ) ])) expect(viewModel.rightNavItems.firstValue()) diff --git a/SessionUtilitiesKit/Database/Models/Job.swift b/SessionUtilitiesKit/Database/Models/Job.swift index 9ea968cad..9cdb2e2a7 100644 --- a/SessionUtilitiesKit/Database/Models/Job.swift +++ b/SessionUtilitiesKit/Database/Models/Job.swift @@ -106,10 +106,6 @@ public struct Job: Codable, Equatable, Hashable, Identifiable, FetchableRecord, /// This is a job that runs once whenever the user leaves a group to send a group leaving message, remove group /// record and group member record case groupLeaving - - /// This is a job that runs once whenever some disappearing messages is read and started the timer to inform - /// linked devices and the network for the change of the messages's ttl - case syncExpires } public enum Behaviour: Int, Codable, DatabaseValueConvertible, CaseIterable { diff --git a/SessionUtilitiesKit/Database/Storage.swift b/SessionUtilitiesKit/Database/Storage.swift index c3db2cd39..a7313f8e0 100644 --- a/SessionUtilitiesKit/Database/Storage.swift +++ b/SessionUtilitiesKit/Database/Storage.swift @@ -267,7 +267,7 @@ open class Storage { // after device restart until device is unlocked for the first time. If the app receives a push // notification, we won't be able to access the keychain to process that notification, so we should // just terminate by throwing an uncaught exception - if CurrentAppContext().isMainApp || CurrentAppContext().isInBackground() { + if HasAppContext() && (CurrentAppContext().isMainApp || CurrentAppContext().isInBackground()) { let appState: UIApplication.State = CurrentAppContext().reportedApplicationState // In this case we should have already detected the situation earlier and exited gracefully (in the diff --git a/SessionUtilitiesKit/JobRunner/JobRunner.swift b/SessionUtilitiesKit/JobRunner/JobRunner.swift index 1847ea930..25d352a1d 100644 --- a/SessionUtilitiesKit/JobRunner/JobRunner.swift +++ b/SessionUtilitiesKit/JobRunner/JobRunner.swift @@ -90,14 +90,6 @@ public final class JobRunner { jobVariants.remove(.attachmentDownload) ].compactMap { $0 } ) - let syncExpiriesQueue: JobQueue = JobQueue( - type: .syncExpiries, - executionType: .concurrent, // Allow as many jobs to run at once as supported by the device - qos: .default, - jobVariants: [ - jobVariants.remove(.syncExpires) - ].compactMap { $0 } - ) let generalQueue: JobQueue = JobQueue( type: .general(number: 0), qos: .utility, @@ -108,7 +100,6 @@ public final class JobRunner { messageSendQueue, messageReceiveQueue, attachmentDownloadQueue, - syncExpiriesQueue, generalQueue ].reduce(into: [:]) { prev, next in next.jobVariants.forEach { variant in @@ -417,7 +408,6 @@ private final class JobQueue { case messageSend case messageReceive case attachmentDownload - case syncExpiries var name: String { switch self { @@ -426,7 +416,6 @@ private final class JobQueue { case .messageSend: return "MessageSend" case .messageReceive: return "MessageReceive" case .attachmentDownload: return "AttachmentDownload" - case .syncExpiries: return "SyncExpiries" } } }