Skip to content

Commit

Permalink
Added statusReason to UserOperation (#148)
Browse files Browse the repository at this point in the history
* Add statusReason to UserOperation, docs and integration test

* Fix ktlint
  • Loading branch information
Hopsaheysa committed Jun 5, 2024
1 parent c34d9f4 commit bd19a1d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/Using-Operations-Service.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,14 @@ class UserOperation: IOperation {

/** Proximity Check Data to be passed when OTP is handed to the app */
var proximityCheck: ProximityCheck? = null


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

Expand Down
26 changes: 26 additions & 0 deletions library/src/androidTest/java/IntegrationTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,30 @@ class IntegrationTests {
}
Assert.assertNull(authorizedFuture2.get(20, TimeUnit.SECONDS))
}

@Test
fun testOperationCanceledWithReason() {
// create regular operation
val op = IntegrationUtils.createOperation(IntegrationUtils.Companion.Factors.F_2FA)
val cancelReason = "PREARRANGED_REASON"
// cancel the operation
IntegrationUtils.cancelOperation(op.operationId, cancelReason)

val future = CompletableFuture<List<OperationHistoryEntry>?>()
val auth = PowerAuthAuthentication.possessionWithPassword(pin)
ops.getHistory(auth) { result ->
result.onSuccess { future.complete(it) }
.onFailure { future.completeExceptionally(it) }
}

val operations = future.get(20, TimeUnit.SECONDS)
Assert.assertNotNull("Operations not retrieved", operations)
if (operations == null) {
return
}

val opRecord = operations.firstOrNull { it.operation.id == op.operationId }
Assert.assertNotNull(opRecord)
Assert.assertTrue("${opRecord?.operation?.statusReason} should be PREARRANGED_REASON", opRecord?.operation?.statusReason == "PREARRANGED_REASON")
}
}
5 changes: 5 additions & 0 deletions library/src/androidTest/java/IntegrationUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ class IntegrationUtils {
return makeCall(opBody, "$cloudServerUrl/v2/operations")
}

@Throws
fun cancelOperation(operationId: String, reason: String): StatusResponse {
return makeCall("", "$cloudServerUrl/v2/operations/$operationId?statusReason=$reason", "DELETE")
}

@Throws
fun createNonPersonalizedPACOperation(factors: Factors): NonPersonalisedTOTPOperationObject {
val opBody = when (factors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ open class UserOperation(
* Proximity Check Data to be passed when OTP is handed to the app
*/
@SerializedName("proximityCheck")
override var proximityCheck: ProximityCheck? = null
override var proximityCheck: ProximityCheck? = null,

/**
* Enum-like reason why the status has changed.
*
* Max 32 characters are expected. Possible values depend on the backend implementation and configuration.
*/
@SerializedName("statusReason")
val statusReason: String?
) : IOperation, ExpirableOperation

/**
Expand Down

0 comments on commit bd19a1d

Please sign in to comment.