77
88import XCTest
99@testable import Amplify
10+ import AmplifyTestCommon
1011import AWSCognitoAuthPlugin
12+ #if COCOAPODS
13+ import AWSMobileClient
14+ #else
15+ import AWSMobileClientXCF
16+ #endif
1117
1218class AuthDeviceOperationTests : AWSAuthBaseTest {
1319
@@ -22,20 +28,60 @@ class AuthDeviceOperationTests: AWSAuthBaseTest {
2228 sleep ( 2 )
2329 }
2430
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+
2557 /// Test if forgetDevice returns deviceNotTracked error for a unknown device
2658 ///
27- /// - Given: A test with the device not tracked
59+ /// - Given: A test with a device not tracked
2860 /// - When:
2961 /// - I invoke forgetDevice
3062 /// - Then:
3163 /// - I should get a deviceNotTracked error.
3264 ///
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+
3479 let forgetDeviceExpectation = expectation ( description: " Received event result from forgetDevice " )
3580 _ = Amplify . Auth. forgetDevice { result in
81+ forgetDeviceExpectation. fulfill ( )
3682 switch result {
3783 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" )
3985 case . failure( let error) :
4086 guard let cognitoError = error. underlyingError as? AWSCognitoAuthError ,
4187 case . deviceNotTracked = cognitoError else {
@@ -44,7 +90,6 @@ class AuthDeviceOperationTests: AWSAuthBaseTest {
4490 }
4591
4692 }
47- forgetDeviceExpectation. fulfill ( )
4893 }
4994 wait ( for: [ forgetDeviceExpectation] , timeout: networkTimeout)
5095 }
0 commit comments