Skip to content

Commit

Permalink
Added Status to UserOperation and removed HistoryEntry (#162)
Browse files Browse the repository at this point in the history
* Fix #159: Add Status to UserOperation and remove HistoryEntry

* Add change to changelog
  • Loading branch information
Hopsaheysa authored Oct 9, 2024
1 parent 0d2f91c commit 93129dc
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 460 deletions.
2 changes: 2 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Upgraded to PowerAuth 1.9.x [(#165)](https://github.com/wultra/mtoken-sdk-ios/pull/165)
- Document fixes and improvements
- Added status to `UserOperation` and removed redundant `OperationHistoryEntry` [(#171)](https://github.com/wultra/mtoken-sdk-ios/pull/171)
- Removed deprecated `IOperationsService` methods in 1.5.0. [(#171)](https://github.com/wultra/mtoken-sdk-ios/pull/171)

## 1.11.1 (Aug, 2024)

Expand Down
50 changes: 50 additions & 0 deletions docs/Migration-1.12.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Migration from 1.11.x to 1.12.x

This guide contains instructions for migration from Wultra Mobile Token SDK for Android version `1.11.x` to version `1.12.x`.

## 1. Implement status in UserOperation

### Added Functionality

The following status property was added to the `WMTUserOperations`:

```kotlin
val status: UserOperationStatus

/** Processing status of the operation */
enum class UserOperationStatus {
/** Operation was approved */
APPROVED,
/** Operation was rejected */
REJECTED,
/** Operation is pending its resolution */
PENDING,
/** Operation was canceled */
CANCELED,
/** Operation expired */
EXPIRED,
/** Operation failed */
FAILED
}
```

The `UserOperationStatus` within `UserOperation.status` now represents the status of an operation, making the `OperationHistoryEntryStatus` and `OperationHistoryEntry` redundant. As a result, `OperationHistoryEntry` has been removed. In all instances where `OperationHistoryEntry` was previously used, `UserOperation` is used instead.

### Replaced at

In the `getHistory` method of `IOperationsService`, `OperationHistoryEntry` has been replaced by `UserOperation` for retrieving user operation history.

```kotlin
/// Retrieves the history of operations
/// - Parameters:
/// - authentication: Authentication object for signing.
/// - completion: Result completion.
/// This completion is always called on the main thread.
/// - Returns: Operation object for its state observation.
fun getHistory(authentication: PowerAuthAuthentication, callback: (result: Result<List<UserOperation>>) -> Unit)
```

## 2. Deprecated methods removal

`IOperationsService` Methods which were deprecated in version 1.5.0 are no more available. For further assistance consult [Migration from 1.4.x to 1.5.x](Migration-1.5.md)

40 changes: 7 additions & 33 deletions library/src/androidTest/java/IntegrationTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

package com.wultra.android.mtokensdk.test

import com.wultra.android.mtokensdk.api.operation.model.OperationHistoryEntry
import com.wultra.android.mtokensdk.api.operation.model.OperationHistoryEntryStatus
import com.wultra.android.mtokensdk.api.operation.model.PreApprovalScreen
import com.wultra.android.mtokensdk.api.operation.model.ProximityCheck
import com.wultra.android.mtokensdk.api.operation.model.ProximityCheckType
import com.wultra.android.mtokensdk.api.operation.model.QROperationParser
import com.wultra.android.mtokensdk.api.operation.model.UserOperation
import com.wultra.android.mtokensdk.api.operation.model.UserOperationStatus
import com.wultra.android.mtokensdk.operation.*
import com.wultra.android.mtokensdk.operation.RejectionData
import com.wultra.android.powerauth.networking.error.ApiError
Expand Down Expand Up @@ -124,31 +123,6 @@ class IntegrationTests {
// Assert.assertNull(opFuture.get(20, TimeUnit.SECONDS))
// }
//
// @Test
// fun testRejectLogin() {
// IntegrationUtils.createOperation(true)
// val future = CompletableFuture<List<UserOperation>>()
// ops.getOperations(object : IGetOperationListener {
// override fun onSuccess(operations: List<UserOperation>) {
// future.complete(operations)
// }
// override fun onError(error: ApiError) {
// future.completeExceptionally(error.e)
// }
// })
// val operations = future.get(20, TimeUnit.SECONDS)
// Assert.assertTrue("Missing operation", operations.count() == 1)
// val opFuture = CompletableFuture<Any?>()
// ops.rejectOperation(operations.first(), RejectionReason.UNEXPECTED_OPERATION, object : IRejectOperationListener {
// override fun onSuccess() {
// opFuture.complete(null)
// }
// override fun onError(error: ApiError) {
// opFuture.completeExceptionally(error.e)
// }
// })
// Assert.assertNull(opFuture.get(20, TimeUnit.SECONDS))
// }

@Test
fun testApprovePayment() {
Expand Down Expand Up @@ -235,7 +209,7 @@ class IntegrationTests {
// lets create 1 operation and leave it in the state of "pending"
val op = IntegrationUtils.createOperation(IntegrationUtils.Companion.Factors.F_2FA)
val auth = PowerAuthAuthentication.possessionWithPassword(pin)
val future = CompletableFuture<List<OperationHistoryEntry>?>()
val future = CompletableFuture<List<UserOperation>?>()
ops.getHistory(auth) { result ->
result.onSuccess { future.complete(it) }
.onFailure { future.completeExceptionally(it) }
Expand All @@ -247,9 +221,9 @@ class IntegrationTests {
return
}

val opRecord = operations.firstOrNull { it.operation.id == op.operationId }
val opRecord = operations.firstOrNull { it.id == op.operationId }
Assert.assertNotNull(opRecord)
Assert.assertTrue(opRecord?.status == OperationHistoryEntryStatus.PENDING)
Assert.assertTrue(opRecord?.status == UserOperationStatus.PENDING)
}

@Test
Expand Down Expand Up @@ -333,7 +307,7 @@ class IntegrationTests {
// cancel the operation
IntegrationUtils.cancelOperation(op.operationId, cancelReason)

val future = CompletableFuture<List<OperationHistoryEntry>?>()
val future = CompletableFuture<List<UserOperation>?>()
val auth = PowerAuthAuthentication.possessionWithPassword(pin)
ops.getHistory(auth) { result ->
result.onSuccess { future.complete(it) }
Expand All @@ -346,8 +320,8 @@ class IntegrationTests {
return
}

val opRecord = operations.firstOrNull { it.operation.id == op.operationId }
val opRecord = operations.firstOrNull { it.id == op.operationId }
Assert.assertNotNull(opRecord)
Assert.assertTrue("${opRecord?.operation?.statusReason} should be PREARRANGED_REASON", opRecord?.operation?.statusReason == "PREARRANGED_REASON")
Assert.assertTrue("${opRecord?.statusReason} should be PREARRANGED_REASON", opRecord?.statusReason == "PREARRANGED_REASON")
}
}
Loading

0 comments on commit 93129dc

Please sign in to comment.