Skip to content
Snippets Groups Projects
Commit 2fcaf4fa authored by Bruno Muniz's avatar Bruno Muniz :apple:
Browse files

Fixed comments on MR and added unit test

parent 817d15c1
No related branches found
No related tags found
3 merge requests!71Releasing v1.1.5 (214),!67v1.1.5 b(203),!59Invite friends
...@@ -722,6 +722,13 @@ let package = Package( ...@@ -722,6 +722,13 @@ let package = Package(
dependencies: ["DependencyInjection"] dependencies: ["DependencyInjection"]
), ),
// MARK: - AppTests
.testTarget(
name: "AppTests",
dependencies: ["App"]
),
// MARK: - ProfileFeatureTests // MARK: - ProfileFeatureTests
.testTarget( .testTarget(
......
...@@ -143,10 +143,8 @@ public class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -143,10 +143,8 @@ public class AppDelegate: UIResponder, UIApplicationDelegate {
open url: URL, open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:] options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool { ) -> Bool {
if let components = URLComponents(url: url, resolvingAgainstBaseURL: false), if let invitationUsername = getUsernameFromInvitationDeepLink(url) {
let invitation = components.queryItems?.first(where: { $0.name == "invitation" }), self.invitation = invitationUsername
let username = invitation.value {
self.invitation = username
return true return true
} else { } else {
return dropboxService.handleOpenUrl(url) return dropboxService.handleOpenUrl(url)
...@@ -154,6 +152,18 @@ public class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -154,6 +152,18 @@ public class AppDelegate: UIResponder, UIApplicationDelegate {
} }
} }
func getUsernameFromInvitationDeepLink(_ url: URL) -> String? {
if let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
components.scheme == "xxnetwork",
components.host == "messenger",
let queryItem = components.queryItems?.first(where: { $0.name == "invitation" }),
let username = queryItem.value {
return username
}
return nil
}
// MARK: Notifications // MARK: Notifications
extension AppDelegate: UNUserNotificationCenterDelegate { extension AppDelegate: UNUserNotificationCenterDelegate {
......
...@@ -50,19 +50,15 @@ final class SearchLeftViewModel { ...@@ -50,19 +50,15 @@ final class SearchLeftViewModel {
networkMonitor.statusPublisher networkMonitor.statusPublisher
.first { $0 == .available } .first { $0 == .available }
.map { [unowned self] _ in .eraseToAnyPublisher()
session.waitForNodes(timeout: 5).first() .flatMap { _ in self.session.waitForNodes(timeout: 5) }
.sink { .sink {
if case .failure(let error) = $0 { if case .failure(let error) = $0 {
self.hudSubject.send(.error(.init(with: error))) self.hudSubject.send(.error(.init(with: error)))
} }
networkCancellable.removeAll() } receiveValue: {
} receiveValue: { _ in self.didStartSearching()
self.didStartSearching() }.store(in: &networkCancellable)
networkCancellable.removeAll()
}.store(in: &networkCancellable)
}.sink(receiveValue: { _ in })
.store(in: &networkCancellable)
} }
} }
......
import XCTest
@testable import App
final class AppDelegateTests: XCTestCase {
func test_invitationDeeplink() {
let host = "messenger"
let query = "invitation"
let scheme = "xxnetwork"
let username = "john_doe"
let url = URL(string: "\(scheme)://\(host)?\(query)=\(username)")!
XCTAssertEqual(getUsernameFromInvitationDeepLink(url), username)
let malformedURL = URL(string: "\(scheme)\(host)\(query)\(username)")!
XCTAssertNil(getUsernameFromInvitationDeepLink(malformedURL))
let urlAnotherUsername = URL(string: "\(scheme)://\(host)?\(query)=asdfg")!
XCTAssertNotEqual(getUsernameFromInvitationDeepLink(urlAnotherUsername), username)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment