Skip to content

Commit

Permalink
IOS-6901: Update SDKNodesUpdateListenerRepository on node updates to …
Browse files Browse the repository at this point in the history
…match MEGAGlobalDelegate

(cherry picked from commit 4fc93ca)
  • Loading branch information
mauritz-mega authored and gmagpayo committed Feb 20, 2023
1 parent f2fd948 commit b758daf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions MEGA.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
0DE3037826B25AA100E4A66B /* FileProviderItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DE3035F26B11E7800E4A66B /* FileProviderItem.swift */; };
0E32FFAA293E817A004BB11D /* NodeUpdateRepositoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E32FFA9293E8179004BB11D /* NodeUpdateRepositoryTests.swift */; };
0E32FFB2293E896A004BB11D /* NodeUpdateRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E32FFB1293E896A004BB11D /* NodeUpdateRepository.swift */; };
0E6F57B4299DEB13005C279F /* SDKNodesUpdateListenerRepositoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E6F57B3299DEB13005C279F /* SDKNodesUpdateListenerRepositoryTests.swift */; };
12084048286120020079127B /* SearchOperation+Initialize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12084047286120020079127B /* SearchOperation+Initialize.swift */; };
1208CEC527FA49EB00F514D4 /* PhotoCellVideoDurationViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1208CEC427FA49EB00F514D4 /* PhotoCellVideoDurationViewModifier.swift */; };
120B4A7927430F3E00312B35 /* Strings+Generated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 120B4A7827430F3E00312B35 /* Strings+Generated.swift */; };
Expand Down Expand Up @@ -2691,6 +2692,7 @@
0DE3035F26B11E7800E4A66B /* FileProviderItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileProviderItem.swift; sourceTree = "<group>"; };
0E32FFA9293E8179004BB11D /* NodeUpdateRepositoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NodeUpdateRepositoryTests.swift; sourceTree = "<group>"; };
0E32FFB1293E896A004BB11D /* NodeUpdateRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NodeUpdateRepository.swift; sourceTree = "<group>"; };
0E6F57B3299DEB13005C279F /* SDKNodesUpdateListenerRepositoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SDKNodesUpdateListenerRepositoryTests.swift; sourceTree = "<group>"; };
12084047286120020079127B /* SearchOperation+Initialize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SearchOperation+Initialize.swift"; sourceTree = "<group>"; };
1208CEC427FA49EB00F514D4 /* PhotoCellVideoDurationViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoCellVideoDurationViewModifier.swift; sourceTree = "<group>"; };
120B4A7827430F3E00312B35 /* Strings+Generated.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Strings+Generated.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5434,6 +5436,7 @@
0E32FFA9293E8179004BB11D /* NodeUpdateRepositoryTests.swift */,
94417EAE296D825B007C9230 /* RubbishBinRepositoryTests.swift */,
B5CC2A632994A22800A966A0 /* ShareRepositoryTests.swift */,
0E6F57B3299DEB13005C279F /* SDKNodesUpdateListenerRepositoryTests.swift */,
);
path = Repos;
sourceTree = "<group>";
Expand Down Expand Up @@ -14549,6 +14552,7 @@
C45A2E3825D2F80900915A83 /* NodeInfoUseCaseTests.swift in Sources */,
BFDE0EEB263A44BC00FC586E /* MockUserInviteUseCase.swift in Sources */,
8340CB1C284F5507007C3B39 /* HeaderViewModelTests.swift in Sources */,
0E6F57B4299DEB13005C279F /* SDKNodesUpdateListenerRepositoryTests.swift in Sources */,
B6E18AEF29372FA300EDFC10 /* PhotoLibraryCollectionViewScrollTrackerTests.swift in Sources */,
C45A2E0825D2B9DE00915A83 /* MockAudioPlaylistViewRouter.swift in Sources */,
B5CC2A662994AD8C00A966A0 /* MockShareList.swift in Sources */,
Expand Down
19 changes: 19 additions & 0 deletions MEGADataTests/Repos/SDKNodesUpdateListenerRepositoryTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import XCTest
@testable import MEGA

final class SDKNodesUpdateListenerRepositoryTests: XCTestCase {

func testMEGAGlobalDelegateonNodesUpdate_shouldPassNodeEntitiesToUpdateHandler() {
let mockSdk = MockSdk()
let repo = SDKNodesUpdateListenerRepository(sdk: mockSdk)
let nodes = [MockNode(handle: 1),
MockNode(handle: 2)]
let exp = expectation(description: "SDK onNodesUpdate pass to onNodesUpdateHandler")
repo.onNodesUpdateHandler = {
XCTAssertEqual($0, nodes.toNodeEntities())
exp.fulfill()
}
repo.onNodesUpdate(mockSdk, nodeList: MockNodeList(nodes: nodes))
wait(for: [exp], timeout: 0.5)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import MEGADomain

final class SDKNodesUpdateListenerRepository: NSObject, MEGAGlobalDelegate, NodesUpdateListenerProtocol {
final class SDKNodesUpdateListenerRepository: NSObject, NodesUpdateListenerProtocol {
var onNodesUpdateHandler: (([NodeEntity]) -> Void)?

private let sdk: MEGASdk
Expand All @@ -14,8 +14,10 @@ final class SDKNodesUpdateListenerRepository: NSObject, MEGAGlobalDelegate, Node
deinit {
sdk.remove(self)
}

func onNodesUpdateHandler(_ api: MEGASdk, nodeList: MEGANodeList?) {
}

extension SDKNodesUpdateListenerRepository: MEGAGlobalDelegate {
func onNodesUpdate(_ api: MEGASdk, nodeList: MEGANodeList?) {
guard let updatedNodes = nodeList?.toNodeEntities() else { return }
onNodesUpdateHandler?(updatedNodes)
}
Expand Down

0 comments on commit b758daf

Please sign in to comment.