7
7
8
8
import XCTest
9
9
@testable import Amplify
10
+ import AmplifyTestCommon
10
11
import AWSCognitoAuthPlugin
12
+ #if COCOAPODS
13
+ import AWSMobileClient
14
+ #else
15
+ import AWSMobileClientXCF
16
+ #endif
11
17
12
18
class AuthDeviceOperationTests : AWSAuthBaseTest {
13
19
@@ -22,20 +28,60 @@ class AuthDeviceOperationTests: AWSAuthBaseTest {
22
28
sleep ( 2 )
23
29
}
24
30
31
+ /// Test if forgetDevice returns deviceNotTracked error for a signed out user
32
+ ///
33
+ /// - Given: A test with the user not signed in
34
+ /// - When:
35
+ /// - I invoke forgetDevice
36
+ /// - Then:
37
+ /// - I should get a notSignedIn error.
38
+ ///
39
+ func testForgetDeviceWithSignedOutUser( ) {
40
+ let forgetDeviceExpectation = expectation ( description: " Received event result from forgetDevice " )
41
+ _ = Amplify . Auth. forgetDevice { result in
42
+ forgetDeviceExpectation. fulfill ( )
43
+ switch result {
44
+ case . success:
45
+ XCTFail ( " Forget device with signed out user should not return success " )
46
+ case . failure( let error) :
47
+ guard let cognitoError = error. underlyingError as? AWSMobileClientError ,
48
+ case . notSignedIn = cognitoError else {
49
+ XCTFail ( " Should return notSignedIn " )
50
+ return
51
+ }
52
+ }
53
+ }
54
+ wait ( for: [ forgetDeviceExpectation] , timeout: networkTimeout)
55
+ }
56
+
25
57
/// Test if forgetDevice returns deviceNotTracked error for a unknown device
26
58
///
27
- /// - Given: A test with the device not tracked
59
+ /// - Given: A test with a device not tracked
28
60
/// - When:
29
61
/// - I invoke forgetDevice
30
62
/// - Then:
31
63
/// - I should get a deviceNotTracked error.
32
64
///
33
- func testForgetDeviceWithUnknowdevice( ) {
65
+ func testForgetDeviceWithUntrackedDevice( ) {
66
+ let username = " integTest \( UUID ( ) . uuidString) "
67
+ let password = " P123@ \( UUID ( ) . uuidString) "
68
+ let signInExpectation = expectation ( description: " SignIn operation should complete " )
69
+ AuthSignInHelper . registerAndSignInUser ( username: username, password: password,
70
+ email: email) { didSucceed, error in
71
+ signInExpectation. fulfill ( )
72
+ XCTAssertTrue ( didSucceed, " SignIn operation failed - \( String ( describing: error) ) " )
73
+ }
74
+ wait ( for: [ signInExpectation] , timeout: networkTimeout)
75
+
76
+ let user = Amplify . Auth. getCurrentUser ( )
77
+ XCTAssertNotNil ( user)
78
+
34
79
let forgetDeviceExpectation = expectation ( description: " Received event result from forgetDevice " )
35
80
_ = Amplify . Auth. forgetDevice { result in
81
+ forgetDeviceExpectation. fulfill ( )
36
82
switch result {
37
83
case . success:
38
- XCTFail ( " Confirm signUp with non existing user should not return result" )
84
+ XCTFail ( " Forget device with untracked device should not return result" )
39
85
case . failure( let error) :
40
86
guard let cognitoError = error. underlyingError as? AWSCognitoAuthError ,
41
87
case . deviceNotTracked = cognitoError else {
@@ -44,7 +90,6 @@ class AuthDeviceOperationTests: AWSAuthBaseTest {
44
90
}
45
91
46
92
}
47
- forgetDeviceExpectation. fulfill ( )
48
93
}
49
94
wait ( for: [ forgetDeviceExpectation] , timeout: networkTimeout)
50
95
}
0 commit comments