Skip to content

Commit

Permalink
feat: Add missing values in SignRequestSignerInputContentType and `…
Browse files Browse the repository at this point in the history
…SignRequestStatus` along with the tests (#907)
  • Loading branch information
arjankowski authored Jul 18, 2023
1 parent 1efb295 commit 56a8250
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 53 deletions.
4 changes: 4 additions & 0 deletions BoxSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
05EFAB2326F0F01100DF1830 /* Quick.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 05EFAB2026F0F01100DF1830 /* Quick.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
05EFAB2426F0F01100DF1830 /* OHHTTPStubs.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 05EFAB2126F0F01100DF1830 /* OHHTTPStubs.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
05F1113E27D8FCF300079978 /* CCGAuthSessionSpecs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05F1113D27D8FCF300079978 /* CCGAuthSessionSpecs.swift */; };
05F2A1A12A6532C400C8BD92 /* SignRequestsModuleIntegrationSpecs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05F2A1A02A6532C400C8BD92 /* SignRequestsModuleIntegrationSpecs.swift */; };
05F2E39D274FBC5500C32A34 /* GetEnterpriseEventsStreaming.json in Resources */ = {isa = PBXBuildFile; fileRef = 05F2E39C274FBC5500C32A34 /* GetEnterpriseEventsStreaming.json */; };
05F59F0626FC740100D9A539 /* FileRepresentationSpecs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05F59F0526FC740100D9A539 /* FileRepresentationSpecs.swift */; };
05F59F0926FC871A00D9A539 /* SharedItemSpecs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05F59F0826FC871A00D9A539 /* SharedItemSpecs.swift */; };
Expand Down Expand Up @@ -732,6 +733,7 @@
05EFAB2026F0F01100DF1830 /* Quick.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Quick.xcframework; path = Carthage/Build/Quick.xcframework; sourceTree = "<group>"; };
05EFAB2126F0F01100DF1830 /* OHHTTPStubs.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = OHHTTPStubs.xcframework; path = Carthage/Build/OHHTTPStubs.xcframework; sourceTree = "<group>"; };
05F1113D27D8FCF300079978 /* CCGAuthSessionSpecs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCGAuthSessionSpecs.swift; sourceTree = "<group>"; };
05F2A1A02A6532C400C8BD92 /* SignRequestsModuleIntegrationSpecs.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignRequestsModuleIntegrationSpecs.swift; sourceTree = "<group>"; };
05F2E39C274FBC5500C32A34 /* GetEnterpriseEventsStreaming.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = GetEnterpriseEventsStreaming.json; sourceTree = "<group>"; };
05F59F0526FC740100D9A539 /* FileRepresentationSpecs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileRepresentationSpecs.swift; sourceTree = "<group>"; };
05F59F0826FC871A00D9A539 /* SharedItemSpecs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedItemSpecs.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1327,6 +1329,7 @@
05EA725A27621FA7001ECFF3 /* FileModuleIntegrationSpecs.swift */,
0579F6FF27577FD200473A3C /* FolderModuleIntegrationSpecs.swift */,
0BD51EDB28CF257E000DE69E /* RetentionPoliciesModuleIntegrationSpecs.swift */,
05F2A1A02A6532C400C8BD92 /* SignRequestsModuleIntegrationSpecs.swift */,
052A03F9287C1FC20063513C /* UsersModuleIntegrationSpecs.swift */,
0571FC6228F7FA07004846E4 /* WebhooksModuleIntegrationSpecs.swift */,
054D536B283CFAB800CC2CBC /* Async */,
Expand Down Expand Up @@ -2885,6 +2888,7 @@
files = (
0571FC6328F7FA07004846E4 /* WebhooksModuleIntegrationSpecs.swift in Sources */,
0BD51EDC28CF257E000DE69E /* RetentionPoliciesModuleIntegrationSpecs.swift in Sources */,
05F2A1A12A6532C400C8BD92 /* SignRequestsModuleIntegrationSpecs.swift in Sources */,
0547B73E276C99AA002D9E7A /* CryptographyUtil.swift in Sources */,
053637BD276C96E400C18D26 /* IntegrationTestResources.swift in Sources */,
057C8CE4276799760092A6EC /* Date+Extensions.swift in Sources */,
Expand Down
124 changes: 124 additions & 0 deletions IntegrationTests/SignRequestsModuleIntegrationSpecs.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//
// SignRequestsModuleIntegrationSpecs.swift
// BoxSDKIntegrationTests-iOS
//
// Created by Artur Jankowski on 17/07/2023.
// Copyright © 2023 box. All rights reserved.
//

@testable import BoxSDK
import Nimble
import Quick

class SignRequestsModuleIntegrationSpecs: QuickSpec {

override class func spec() {
var client: BoxClient!
var rootFolder: Folder!

beforeSuite {
initializeClient { createdClient in client = createdClient }
createFolder(client: client, name: NameGenerator.getUniqueFolderName(for: "SignRequestsModule")) { createdFolder in rootFolder = createdFolder }
}

afterSuite {
deleteFolder(client: client, folder: rootFolder, recursive: true)
}

describe("Sign Requests") {
context("live cycle") {
var fileToSign1: File?
var fileToSign2: File?
var signRequest: SignRequest?

beforeEach {
uploadFile(client: client, fileName: "file_1.txt", dataContent: "content_1".data(using: .utf8)!, toFolder: rootFolder.id) { uploadedFile in fileToSign1 = uploadedFile }
uploadFile(client: client, fileName: "file_2.txt", dataContent: "content_2".data(using: .utf8)!, toFolder: rootFolder.id) { uploadedFile in fileToSign2 = uploadedFile }
}

afterEach {
deleteFile(client: client, file: fileToSign1)
deleteFile(client: client, file: fileToSign2)
}

it("should correctly create get cancel") {
guard let fileToSign1 = fileToSign1, let fileToSign2 = fileToSign2 else {
fail("An error occurred during setup initial data")
return
}

let signer = SignRequestCreateSigner(
email: "sdk_integration_test@boxdemo.com",
role: .signer,
redirectUrl: "https://www.box.com/redirect_url_signer_1",
declinedRedirectUrl: "https://www.box.com/declined_redirect_url_singer_1"
)

let signParameters = SignRequestCreateParameters(
redirectUrl: "https://www.box.com/redirect_url",
declinedRedirectUrl: "https://www.box.com/declined_redirect_url"
)

// Create
waitUntil(timeout: .seconds(Constants.Timeout.large)) { done in
client.signRequests.create(
signers: [signer],
sourceFiles: [
SignRequestCreateSourceFile(id: fileToSign1.id),
SignRequestCreateSourceFile(id: fileToSign2.id)
],
parentFolder: SignRequestCreateParentFolder(id: rootFolder.id),
parameters: signParameters
) { result in
switch result {
case let .success(signRequestResult):
signRequest = signRequestResult
expect(signRequest?.redirectUrl).to(equal(signParameters.redirectUrl))
expect(signRequest?.declinedRedirectUrl).to(equal(signParameters.declinedRedirectUrl))
expect(signRequest?.parentFolder.id).to(equal(rootFolder.id))
expect(signRequest?.signFiles?.files?.count).to(equal(2))
case let .failure(error):
fail("Expected create call to succeed, but instead got \(error)")
}

done()
}
}

guard let signRequest = signRequest else { return }

// Get
waitUntil(timeout: .seconds(Constants.Timeout.default)) { done in
client.signRequests.getById(id: signRequest.id) { result in
switch result {
case let .success(signRequestResult):
expect(signRequestResult.redirectUrl).to(equal(signParameters.redirectUrl))
expect(signRequestResult.declinedRedirectUrl).to(equal(signParameters.declinedRedirectUrl))
expect(signRequestResult.parentFolder.id).to(equal(rootFolder.id))
expect(signRequestResult.signFiles?.files?.count).to(equal(2))
case let .failure(error):
fail("Expected get call to succeed, but instead got \(error)")
}

done()
}
}

// Cancel
waitUntil(timeout: .seconds(Constants.Timeout.default)) { done in
client.signRequests.cancelById(id: signRequest.id) { result in
switch result {
case let .success(signRequestResult):
expect(signRequestResult.status).to(equal(.cancelled))
case let .failure(error):
fail("Expected cancel call to succeed, but instead got \(error)")
}

done()
}
}
}
}
}
}
}
20 changes: 10 additions & 10 deletions Sources/Core/Extensions/UIColorExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
//

#if canImport(UIKit)
import UIKit
import UIKit

/// The color type used natively on the target platform.
public typealias PlatformColor = UIColor
/// The color type used natively on the target platform.
public typealias PlatformColor = UIColor
#elseif canImport(AppKit)
import AppKit
import AppKit

/// The color type used natively on the target platform.
public typealias PlatformColor = NSColor
/// The color type used natively on the target platform.
public typealias PlatformColor = NSColor
#endif

extension PlatformColor {
Expand All @@ -24,23 +24,23 @@ extension PlatformColor {
if hex.hasPrefix("#") {
let start = hex.index(hex.startIndex, offsetBy: 1)
let hexColor = String(hex[start...])

if hexColor.count == 6 {
let scanner = Scanner(string: hexColor)
var hexNumber: UInt64 = 0

if scanner.scanHexInt64(&hexNumber) {
red = CGFloat((hexNumber & 0xFF0000) >> 16) / 255
green = CGFloat((hexNumber & 0x00FF00) >> 8) / 255
blue = CGFloat(hexNumber & 0x0000FF) / 255
alpha = CGFloat(1.0)

self.init(red: red, green: green, blue: blue, alpha: alpha)
return
}
}
}

return nil
}
}
2 changes: 1 addition & 1 deletion Sources/Modules/SignRequestsModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SignRequestsModule {
///
/// - Parameters:
/// - signers: List of signers for the sign request. 35 is the max number of signers permitted.
/// - sourceFiles: List of files to create a signing document from.
/// - sourceFiles: List of files to create a signing document from. This is currently limited to ten files.
/// - parentFolder: The destination folder to place final, signed document and signing log.
/// The root folder, folder ID `0`, cannot be used.
/// - parameters: The optional parameters.
Expand Down
12 changes: 12 additions & 0 deletions Sources/Responses/SignRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public enum SignRequestStatus: BoxEnum {
case errorSending
/// Expired status.
case expired
/// Finalizing status.
case finalizing
/// Error finalizing status.
case errorFinalizing
/// Custom value for enum values not yet implemented in the SDK
case customValue(String)

Expand All @@ -57,6 +61,10 @@ public enum SignRequestStatus: BoxEnum {
self = .errorSending
case "expired":
self = .expired
case "finalizing":
self = .finalizing
case "error_finalizing":
self = .errorFinalizing
default:
self = .customValue(value)
}
Expand Down Expand Up @@ -84,6 +92,10 @@ public enum SignRequestStatus: BoxEnum {
return "error_sending"
case .expired:
return "expired"
case .finalizing:
return "finalizing"
case .errorFinalizing:
return "error_finalizing"
case let .customValue(value):
return value
}
Expand Down
6 changes: 6 additions & 0 deletions Sources/Responses/SignRequestSignerInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public enum SignRequestSignerInputContentType: BoxEnum {
case date
/// Checkbox
case checkbox
/// Attachment
case attachment
/// Custom value for enum values not yet implemented in the SDK
case customValue(String)

Expand Down Expand Up @@ -111,6 +113,8 @@ public enum SignRequestSignerInputContentType: BoxEnum {
self = .date
case "checkbox":
self = .checkbox
case "attachment":
self = .attachment
default:
self = .customValue(value)
}
Expand Down Expand Up @@ -142,6 +146,8 @@ public enum SignRequestSignerInputContentType: BoxEnum {
return "date"
case .checkbox:
return "checkbox"
case .attachment:
return "attachment"
case let .customValue(value):
return value
}
Expand Down
20 changes: 10 additions & 10 deletions Tests/Helpers/TestAssets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@
import Foundation

#if canImport(UIKit)
import UIKit
import UIKit
#endif

final class TestAssets {

static let resourceBundle: Bundle = {
Bundle(for: TestAssets.self)
}()

static func url(forResource name: String) -> URL? {
resourceBundle.url(forResource: name, withExtension: nil)
}

static func path(forResource name: String) -> String? {
resourceBundle.path(forResource: name, ofType: nil)
}
#if canImport(UIKit)
static func image(named: String) -> UIImage? {
UIImage(named: named, in: resourceBundle, compatibleWith: nil)
}
#endif

#if canImport(UIKit)
static func image(named: String) -> UIImage? {
UIImage(named: named, in: resourceBundle, compatibleWith: nil)
}
#endif
}
Loading

0 comments on commit 56a8250

Please sign in to comment.