Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added statusReason to WMTUserOperation #156

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ open class WMTUserOperation: WMTOperation, Codable {

/// Proximity Check Data to be passed when OTP is handed to the app
public var proximityCheck: WMTProximityCheck?

/// Enum-like reason why the status has changed.
///
/// Max 32 characters are expected. Possible values depend on the backend implementation and configuration.
public let statusReason: String?
}
10 changes: 10 additions & 0 deletions WultraMobileTokenSDKTests/IntegrationProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ class IntegrationProxy {
}
}

func cancelOperation(operationId: String, reason: String, completion: @escaping (CancelObject?) -> Void) {
DispatchQueue.global().async {
completion(self.makeRequest(url: URL(string: "\(self.config.cloudServerUrl)/v2/operations/\(operationId)?statusReason=\(reason)")!, body: "", httpMethod: "DELETE"))
}
}

func createNonPersonalisedPACOperation(_ factors: Factors = .F_2FA, completion: @escaping (NonPersonalisedTOTPOperationObject?) -> Void) {
DispatchQueue.global().async {
let opBody: String
Expand Down Expand Up @@ -261,6 +267,10 @@ private struct CommitObject: Codable {
let status: String
}

struct CancelObject: Codable {
let status: String
}

struct OperationObject: Codable {
let operationId: String
let userId: String
Expand Down
37 changes: 37 additions & 0 deletions WultraMobileTokenSDKTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,43 @@ class IntegrationTests: XCTestCase {
waitForExpectations(timeout: 5, handler: nil)
}

func testOperationCanceledWithReason() {
let exp = expectation(description: "Cancel operation with reason")
let cancelReason = "PREARRANGED_REASON"

proxy.createOperation { op in
guard let op else {
XCTFail("Failed to create operation")
exp.fulfill()
return
}
self.proxy.cancelOperation(operationId: op.operationId, reason: cancelReason) { cancelOp in
if cancelOp != nil {
let auth = PowerAuthAuthentication.possessionWithPassword(password: self.pin)
DispatchQueue.main.async {
_ = self.ops.getHistory(authentication: auth) { result in
switch result {
case .success(let ops):
if let opFromList = ops.first(where: { $0.operation.id == op.operationId }) {
XCTAssertEqual(opFromList.operation.statusReason, cancelReason, "statusReason and cancelReason must be the same")
} else {
XCTFail("Created operation was not in the history")
}
case .failure:
XCTFail("History was not retrieved")
}
exp.fulfill()
}
}
} else {
XCTFail("Failed to cancel operation")
exp.fulfill()
}
}
}
waitForExpectations(timeout: 20, handler: nil)
}

/// Operation IDs should be equal
func testClaim() {
let exp = expectation(description: "Operation Claim should return UserOperation with operation.id")
Expand Down
5 changes: 5 additions & 0 deletions docs/Using-Operations-Service.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,11 @@ class WMTUserOperation: WMTOperation {

/// Proximity Check Data to be passed when OTP is handed to the app
public var proximityCheck: WMTProximityCheck?

/// Enum-like reason why the status has changed.
///
/// Max 32 characters are expected. Possible values depend on the backend implementation and configuration.
public let statusReason: String?
}
```

Expand Down
Loading