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(
dependencies: ["DependencyInjection"]
),
// MARK: - AppTests
.testTarget(
name: "AppTests",
dependencies: ["App"]
),
// MARK: - ProfileFeatureTests
.testTarget(
......
......@@ -143,10 +143,8 @@ public class AppDelegate: UIResponder, UIApplicationDelegate {
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool {
if let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
let invitation = components.queryItems?.first(where: { $0.name == "invitation" }),
let username = invitation.value {
self.invitation = username
if let invitationUsername = getUsernameFromInvitationDeepLink(url) {
self.invitation = invitationUsername
return true
} else {
return dropboxService.handleOpenUrl(url)
......@@ -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
extension AppDelegate: UNUserNotificationCenterDelegate {
......
......@@ -50,19 +50,15 @@ final class SearchLeftViewModel {
networkMonitor.statusPublisher
.first { $0 == .available }
.map { [unowned self] _ in
session.waitForNodes(timeout: 5).first()
.sink {
if case .failure(let error) = $0 {
self.hudSubject.send(.error(.init(with: error)))
}
networkCancellable.removeAll()
} receiveValue: { _ in
self.didStartSearching()
networkCancellable.removeAll()
}.store(in: &networkCancellable)
}.sink(receiveValue: { _ in })
.store(in: &networkCancellable)
.eraseToAnyPublisher()
.flatMap { _ in self.session.waitForNodes(timeout: 5) }
.sink {
if case .failure(let error) = $0 {
self.hudSubject.send(.error(.init(with: error)))
}
} receiveValue: {
self.didStartSearching()
}.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