Skip to content

Commit

Permalink
Merge pull request #272 from PermanentOrg/vsp-1037
Browse files Browse the repository at this point in the history
VSP-1037 [iOS] Share Management Unit Tests
  • Loading branch information
luciancerbu-vsp authored Dec 8, 2022
2 parents dcb6342 + 37cace6 commit 7b1fc86
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 94 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ iOSInjectionProject/
EnvVars.generated.swift
env-vars-staging.sh
env-vars.sh

.idea/
28 changes: 16 additions & 12 deletions Permanent.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
06B0EB2824E67E6A003D90C6 /* UIColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06B0EB2724E67E6A003D90C6 /* UIColor.swift */; };
06B0EB2A24E67EC4003D90C6 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06B0EB2924E67EC4003D90C6 /* Constants.swift */; };
1DC794553A5F562B11FC7A00 /* Pods_Permanent.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 078F6009A35F7CB0B45A8085 /* Pods_Permanent.framework */; };
37455747BFDB890EC35B23E2 /* ShareManagementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 374554B71E0322714462588A /* ShareManagementTests.swift */; };
5E0182C326B40A7200DB1F79 /* AccountInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E0182C226B40A7200DB1F79 /* AccountInfoTests.swift */; };
5E03F408291AA49200DFCE09 /* ShareManagementViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E03F407291AA49200DFCE09 /* ShareManagementViewController.swift */; };
5E03F40C291BD55600DFCE09 /* ShareManagementTitleCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E03F40A291BD55600DFCE09 /* ShareManagementTitleCollectionViewCell.swift */; };
Expand Down Expand Up @@ -694,6 +695,7 @@
2DC5C8BD7F66C354C5F14C20 /* Pods_ShareExtension.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ShareExtension.framework; sourceTree = BUILT_PRODUCTS_DIR; };
31A707DB681B868604AD1AD3 /* Pods-PermanentTests.dev-debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PermanentTests.dev-debug.xcconfig"; path = "Target Support Files/Pods-PermanentTests/Pods-PermanentTests.dev-debug.xcconfig"; sourceTree = "<group>"; };
3689520FA134A1DCBE0F6DF8 /* Pods-Permanent.dev-debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Permanent.dev-debug.xcconfig"; path = "Target Support Files/Pods-Permanent/Pods-Permanent.dev-debug.xcconfig"; sourceTree = "<group>"; };
374554B71E0322714462588A /* ShareManagementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShareManagementTests.swift; sourceTree = "<group>"; };
4102357D8E87F8C60DCE210A /* Pods-PermanentTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PermanentTests.debug.xcconfig"; path = "Target Support Files/Pods-PermanentTests/Pods-PermanentTests.debug.xcconfig"; sourceTree = "<group>"; };
5E0182C226B40A7200DB1F79 /* AccountInfoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountInfoTests.swift; sourceTree = "<group>"; };
5E03F407291AA49200DFCE09 /* ShareManagementViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareManagementViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1675,6 +1677,7 @@
F559F87E28F9C0640015A522 /* FolderSortViewModelTests.swift */,
F559F88028F9C1F10015A522 /* FolderViewSelectionViewModelTests.swift */,
F559F88228F9C32E0015A522 /* FolderNavigationViewModelTests.swift */,
374554B71E0322714462588A /* ShareManagementTests.swift */,
);
path = PermanentTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -3384,6 +3387,7 @@
5E9977AE284E8BFC003E0C46 /* DonateTests.swift in Sources */,
F559F88328F9C32E0015A522 /* FolderNavigationViewModelTests.swift in Sources */,
5E9977AC284898C7003E0C46 /* PublicGalleryTests.swift in Sources */,
37455747BFDB890EC35B23E2 /* ShareManagementTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -3692,7 +3696,7 @@
CODE_SIGN_ENTITLEMENTS = Permanent/Assets/Entitlements/Permanent.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 89;
CURRENT_PROJECT_VERSION = 90;
DEVELOPMENT_TEAM = C8YKZNBVWT;
ENV_VARS_FILENAME = "env-vars.sh";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
Expand Down Expand Up @@ -3721,7 +3725,7 @@
CODE_SIGN_ENTITLEMENTS = Permanent/PermanentRelease.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 89;
CURRENT_PROJECT_VERSION = 90;
DEVELOPMENT_TEAM = C8YKZNBVWT;
ENV_VARS_FILENAME = "env-vars.sh";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
Expand Down Expand Up @@ -3929,7 +3933,7 @@
CODE_SIGN_ENTITLEMENTS = ShareExtension/ShareExtensionDebug.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 89;
CURRENT_PROJECT_VERSION = 90;
DEVELOPMENT_TEAM = C8YKZNBVWT;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -3963,7 +3967,7 @@
CODE_SIGN_ENTITLEMENTS = "ShareExtension/ShareExtensionDEV-Debug.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 89;
CURRENT_PROJECT_VERSION = 90;
DEVELOPMENT_TEAM = C8YKZNBVWT;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -3997,7 +4001,7 @@
CODE_SIGN_ENTITLEMENTS = ShareExtension/ShareExtensionRelease.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 89;
CURRENT_PROJECT_VERSION = 90;
DEVELOPMENT_TEAM = C8YKZNBVWT;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -4031,7 +4035,7 @@
CODE_SIGN_ENTITLEMENTS = "ShareExtension/ShareExtensionDEV-Release.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 89;
CURRENT_PROJECT_VERSION = 90;
DEVELOPMENT_TEAM = C8YKZNBVWT;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -4126,7 +4130,7 @@
CODE_SIGN_ENTITLEMENTS = "Permanent/PermanentDEV-Debug.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 89;
CURRENT_PROJECT_VERSION = 90;
DEVELOPMENT_TEAM = C8YKZNBVWT;
ENV_VARS_FILENAME = "env-vars-staging.sh";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
Expand Down Expand Up @@ -4209,7 +4213,7 @@
CODE_SIGN_ENTITLEMENTS = "Permanent/Assets/Entitlements/Permanent-Staging.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 89;
CURRENT_PROJECT_VERSION = 90;
DEVELOPMENT_TEAM = C8YKZNBVWT;
ENV_VARS_FILENAME = "env-vars-staging.sh";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
Expand All @@ -4235,7 +4239,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 89;
CURRENT_PROJECT_VERSION = 90;
DEVELOPMENT_TEAM = C8YKZNBVWT;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
INFOPLIST_FILE = PushExtension/Info.plist;
Expand All @@ -4260,7 +4264,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 89;
CURRENT_PROJECT_VERSION = 90;
DEVELOPMENT_TEAM = C8YKZNBVWT;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
INFOPLIST_FILE = PushExtension/Info.plist;
Expand All @@ -4285,7 +4289,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 89;
CURRENT_PROJECT_VERSION = 90;
DEVELOPMENT_TEAM = C8YKZNBVWT;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
INFOPLIST_FILE = PushExtension/Info.plist;
Expand All @@ -4310,7 +4314,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 89;
CURRENT_PROJECT_VERSION = 90;
DEVELOPMENT_TEAM = C8YKZNBVWT;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
INFOPLIST_FILE = PushExtension/Info.plist;
Expand Down
61 changes: 61 additions & 0 deletions Permanent/Managers/Download/DownloadManagerGCD.swift

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Permanent/Managers/Download/Downloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ protocol Downloader {
completion: VoidAction?)

func cancelDownload()


func getRecord(_ file: FileDownloadInfo, then handler: @escaping GetRecordResponse)
func getFolder(_ file: FileDownloadInfo, then handler: @escaping GetFolderResponse)
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,40 @@ class ShareManagementRemoteDataSource: ShareManagementRemoteDataSourceInterface
return payloadVO
}
}

class ShareManagementMockRemoteDataSource: ShareManagementRemoteDataSourceInterface {
var sharebyURLVODataMock: SharebyURLVOData!
var shareVODataMock: ShareVOData!

private func prepareShareLinkUpdatePayload(forData data: ManageLinkData, shareVO: SharebyURLVOData?) -> SharebyURLVOData? {
return nil
}

func getShareLink(file: FileViewModel, option: ShareLinkOption, then handler: @escaping ShareLinkResponse) {
handler(sharebyURLVODataMock, nil)
}

func revokeLink(shareVO: SharebyURLVOData?, then handler: @escaping ServerResponse) {
handler(.success)
}

func updateLink(model: ManageLinkData, shareVO: SharebyURLVOData?, then handler: @escaping ShareLinkResponse) {
handler(sharebyURLVODataMock, nil)
}

func approveButtonAction(minArchiveVO: MinArchiveVO, accessRole: AccessRole, then handler: @escaping (RequestStatus, ShareVOData?) -> ()) {
handler(.success, shareVODataMock)
}

func approveButtonAction(shareVO: ShareVOData, accessRole: AccessRole, then handler: @escaping (RequestStatus, ShareVOData?) -> ()) {
handler(.success, shareVODataMock)
}

func denyButtonAction(minArchiveVO: MinArchiveVO, then handler: @escaping (RequestStatus) -> Void) {
handler(.success)
}

func denyButtonAction(shareVO: ShareVOData, then handler: @escaping (RequestStatus) -> Void) {
handler(.success)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
class ShareManagementRepository {
let remoteDataSource: ShareManagementRemoteDataSourceInterface

init(remoteDataSource: ShareManagementRemoteDataSource = ShareManagementRemoteDataSource()) {
init(remoteDataSource: ShareManagementRemoteDataSourceInterface = ShareManagementRemoteDataSource()) {
self.remoteDataSource = remoteDataSource
}

Expand Down
65 changes: 0 additions & 65 deletions Permanent/ViewControllers/ShareManagementViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,27 +229,7 @@ class ShareManagementViewController: BaseViewController<ShareLinkViewModel> {
showLinkSettings = shareLink == nil ? true : false
}
}

fileprivate func changeFilePermission(shareVO: ShareVOData, accessRole: AccessRole) {
showSpinner()

viewModel?.approveButtonAction(shareVO: shareVO, accessRole: accessRole, then: { status in
self.hideSpinner()

switch status {
case .success:
self.view.showNotificationBanner(title: "Access role was successfully changed".localized())

case .error(let errorMessage):
self.view.showNotificationBanner(title: errorMessage ?? .errorMessage, backgroundColor: .brightRed, textColor: .white)
}

self.getShareLink(option: .retrieve)
})
actionDialog?.dismiss()
actionDialog = nil
}

func copyLinkAction() {
var emailSubject = "<ACCOUNTNAME> wants to share an item from their Permanent Archive with you".localized()
var emailBody = "<ACCOUNTNAME> wants to share an item from their Permanent Archive with you.\n <LINK>".localized()
Expand All @@ -268,51 +248,6 @@ class ShareManagementViewController: BaseViewController<ShareLinkViewModel> {
present(activityViewController, animated: true, completion: nil)
}

func editArchive(shareVO: ShareVOData) {
guard let archiveVO = shareVO.archiveVO else { return }

let accessRoles = AccessRole.allCases
.filter { $0 != .manager }
.map { $0.groupName }

self.showActionDialog(
styled: .dropdownWithDescription,
withTitle: "The \(archiveVO.fullName ?? "") Archive",
placeholders: [AccessRole.roleForValue(shareVO.accessRole ?? "").groupName],
dropdownValues: accessRoles,
positiveButtonTitle: "Update".localized(),
positiveAction: { [weak self] in
if let fieldsInput = self?.actionDialog?.fieldsInput,
let roleValue = fieldsInput.first {
let accessRole = AccessRole.roleForValue(AccessRole.apiRoleForValue(roleValue))
let fileTypeString: String = FileType(rawValue: shareVO.type ?? "")?.isFolder ?? false ? "folder" : "file"
if accessRole == .owner {
self?.actionDialog?.dismissPopup(
self?.actionDialog,
overlayView: self?.overlayView,
completion: { [weak self] _ in
self?.actionDialog?.removeFromSuperview()
self?.actionDialog = nil
guard var archiveName = archiveVO.fullName else { return }
archiveName = "The \(archiveName) Archive"
self?.showActionDialog(styled: .simpleWithDescription,
withTitle: "Add owner".localized(),
description: "Are you sure you want to share this \(fileTypeString) with <ARCHIVE_NAME> as an owner? This cannot be undone.".localized().replacingOccurrences(of: "<ARCHIVE_NAME>", with: archiveName),
positiveButtonTitle: "Add owner".localized(),
positiveAction: { [weak self] in
self?.changeFilePermission(shareVO: shareVO, accessRole: accessRole)
}, overlayView: self?.overlayView)
}
)
} else {
self?.changeFilePermission(shareVO: shareVO, accessRole: accessRole)
}
}
},
overlayView: self.overlayView
)
}

// MARK: - Network Requests

fileprivate func getShareLink(option: ShareLinkOption) {
Expand Down
19 changes: 4 additions & 15 deletions Permanent/ViewModels/ShareLinkViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ class ShareLinkViewModel: NSObject, ViewModelInterface {
})
}

var downloader: DownloadManagerGCD?
var downloader: Downloader?

let shareManagementRepository: ShareManagementRepository

init(fileViewModel: FileViewModel!, shareManagementRepository: ShareManagementRepository = ShareManagementRepository()) {
init(fileViewModel: FileViewModel!, shareManagementRepository: ShareManagementRepository = ShareManagementRepository(), downloader: Downloader? = DownloadManagerGCD()) {
self.fileViewModel = fileViewModel
self.shareManagementRepository = shareManagementRepository
self.downloader = downloader
}

func getRecord(then handler: @escaping (RecordVO?) -> Void) {
Expand All @@ -56,7 +57,6 @@ class ShareLinkViewModel: NSObject, ViewModelInterface {
parentFolderLinkId: fileViewModel.parentFolderLinkId
)

downloader = DownloadManagerGCD()
downloader?.getRecord(downloadInfo) { (record, error) in
self.recordVO = record?.recordVO

Expand All @@ -71,7 +71,6 @@ class ShareLinkViewModel: NSObject, ViewModelInterface {
parentFolderLinkId: fileViewModel.parentFolderLinkId
)

downloader = DownloadManagerGCD()
downloader?.getFolder(downloadInfo) { (folder, error) in
self.folderVO = folder?.folderVO

Expand Down Expand Up @@ -163,17 +162,7 @@ class ShareLinkViewModel: NSObject, ViewModelInterface {
handler(result)
}
}

func prepareShareLinkUpdatePayload(forData data: ManageLinkData) -> SharebyURLVOData? {
var payloadVO = shareVO
payloadVO?.maxUses = data.maxUses
payloadVO?.previewToggle = data.previewToggle
payloadVO?.autoApproveToggle = data.autoApproveToggle
payloadVO?.expiresDT = data.expiresDT

return payloadVO
}


fileprivate func processShareLinkUpdateModel(_ model: SharebyURLVOData?) {
shareVO?.maxUses = model?.maxUses
shareVO?.previewToggle = model?.previewToggle
Expand Down
Loading

0 comments on commit 7b1fc86

Please sign in to comment.