mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			62 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			62 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Swift
		
	
| 
								 
											6 years ago
										 
									 | 
							
								import PromiseKit
							 | 
						||
| 
								 | 
							
								@testable import SignalServiceKit
							 | 
						||
| 
								 | 
							
								import XCTest
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class MultiDeviceProtocolTests : XCTestCase {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    private var storage: OWSPrimaryStorage { OWSPrimaryStorage.shared() }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    override func setUp() {
							 | 
						||
| 
								 | 
							
								        super.setUp()
							 | 
						||
| 
								 | 
							
								        LokiTestUtilities.setUpMockEnvironment()
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    // MARK: - isSlaveThread
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    func test_isSlaveThreadShouldReturnFalseOnGroupThreads() {
							 | 
						||
| 
								 | 
							
								        let allGroupTypes: [GroupType] = [ .closedGroup, .openGroup, .rssFeed ]
							 | 
						||
| 
								 | 
							
								        for groupType in allGroupTypes {
							 | 
						||
| 
								 | 
							
								            guard let groupThread = LokiTestUtilities.createGroupThread(groupType: groupType) else { return XCTFail() }
							 | 
						||
| 
								 | 
							
								            XCTAssertFalse(MultiDeviceProtocol.isSlaveThread(groupThread))
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    func test_isSlaveThreadShouldReturnTheCorrectValues() {
							 | 
						||
| 
								 | 
							
								        let master = LokiTestUtilities.generateHexEncodedPublicKey()
							 | 
						||
| 
								 | 
							
								        let slave = LokiTestUtilities.generateHexEncodedPublicKey()
							 | 
						||
| 
								 | 
							
								        let other = LokiTestUtilities.generateHexEncodedPublicKey()
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        guard let masterDevice = LokiTestUtilities.getDevice(for: master) else { return XCTFail() }
							 | 
						||
| 
								 | 
							
								        guard let slaveDevice = LokiTestUtilities.getDevice(for: slave) else { return XCTFail() }
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								        let deviceLink = DeviceLink(between: masterDevice, and: slaveDevice)
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								        storage.dbReadWriteConnection.readWrite { transaction in
							 | 
						||
| 
								 | 
							
								            self.storage.addDeviceLink(deviceLink, in: transaction)
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        let masterThread = LokiTestUtilities.createContactThread(for: master)
							 | 
						||
| 
								 | 
							
								        let slaveThread = LokiTestUtilities.createContactThread(for: slave)
							 | 
						||
| 
								 | 
							
								        let otherThread = LokiTestUtilities.createContactThread(for: other)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								        storage.dbReadConnection.read { transaction in
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								            XCTAssertNotNil(self.storage.getMasterHexEncodedPublicKey(for: slaveThread.contactIdentifier(), in: transaction))
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        XCTAssertFalse(MultiDeviceProtocol.isSlaveThread(masterThread))
							 | 
						||
| 
								 | 
							
								        XCTAssertTrue(MultiDeviceProtocol.isSlaveThread(slaveThread))
							 | 
						||
| 
								 | 
							
								        XCTAssertFalse(MultiDeviceProtocol.isSlaveThread(otherThread))
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    func test_isSlaveThreadShouldWorkInsideATransaction() {
							 | 
						||
| 
								 | 
							
								        let bob = LokiTestUtilities.generateHexEncodedPublicKey()
							 | 
						||
| 
								 | 
							
								        let thread = LokiTestUtilities.createContactThread(for: bob)
							 | 
						||
| 
								 | 
							
								        storage.dbReadWriteConnection.read { transaction in
							 | 
						||
| 
								 | 
							
								            XCTAssertNoThrow(MultiDeviceProtocol.isSlaveThread(thread))
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        storage.dbReadWriteConnection.readWrite { transaction in
							 | 
						||
| 
								 | 
							
								            XCTAssertNoThrow(MultiDeviceProtocol.isSlaveThread(thread))
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								}
							 |