Skip to content

Commit

Permalink
Added statusReason to WMTUserOperation (#156)
Browse files Browse the repository at this point in the history
* Add statusReason to WMTUserOperation, doc and integration test

* Improve docs
  • Loading branch information
Hopsaheysa committed Jun 5, 2024
1 parent 7b47ece commit 7312646
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
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

0 comments on commit 7312646

Please sign in to comment.