Skip to content

Commit 02ad75b

Browse files
authored
chore(datastore): integration tests (#1510)
* chore(datastore): refactor auth integ tests infra * chore(datastore): @auth explicit owner test * chore(datastore): clean up after rebase, new config files location * chore(datastore): tests explicit owner * chore(datastore): refactoring tests, add more scenarios * chore(datastore): refactor tests teardown * chore(datastore): refactor tests, re-order models * chore(datastore): refactor OIDC tests, move auth delegate * chore(datastore): add custom owner explicit tests * chore(datastore): update tests description * init IAM tests * chore(datastore): add IAM tests
1 parent 4594e70 commit 02ad75b

File tree

35 files changed

+1590
-799
lines changed

35 files changed

+1590
-799
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Copyright Amazon.com Inc. or its affiliates.
3+
// All Rights Reserved.
4+
//
5+
// SPDX-License-Identifier: Apache-2.0
6+
//
7+
8+
import Amplify
9+
import Combine
10+
import Foundation
11+
import AWSPluginsCore
12+
13+
@available(iOS 13.0, *)
14+
extension RemoteSyncEngine: AuthModeStrategyDelegate {
15+
func isUserLoggedIn() -> Bool {
16+
// if OIDC is used as authentication provider
17+
// use `getLatestAuthToken`
18+
var isLoggedInWithOIDC = false
19+
20+
if let authProviderFactory = api as? APICategoryAuthProviderFactoryBehavior,
21+
let oidcAuthProvider = authProviderFactory.apiAuthProviderFactory().oidcAuthProvider() {
22+
switch oidcAuthProvider.getLatestAuthToken() {
23+
case .failure:
24+
isLoggedInWithOIDC = false
25+
case .success:
26+
isLoggedInWithOIDC = true
27+
}
28+
29+
return isLoggedInWithOIDC
30+
}
31+
32+
let isSignedIn = auth?.getCurrentUser() != nil
33+
return isSignedIn
34+
}
35+
}

AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/Sync/RemoteSyncEngine.swift

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -416,25 +416,6 @@ class RemoteSyncEngine: RemoteSyncEngineBehavior {
416416
@available(iOS 13.0, *)
417417
extension RemoteSyncEngine: DefaultLogger { }
418418

419-
@available(iOS 13.0, *)
420-
extension RemoteSyncEngine: AuthModeStrategyDelegate {
421-
func isUserLoggedIn() -> Bool {
422-
// if OIDC is used as authentication provider
423-
// use `getLatestAuthToken`
424-
if let authProviderFactory = api as? APICategoryAuthProviderFactoryBehavior,
425-
let oidcAuthProvider = authProviderFactory.apiAuthProviderFactory().oidcAuthProvider() {
426-
switch oidcAuthProvider.getLatestAuthToken() {
427-
case .failure:
428-
return false
429-
case .success:
430-
return true
431-
}
432-
}
433-
434-
return auth?.getCurrentUser() != nil
435-
}
436-
}
437-
438419
@available(iOS 13.0, *)
439420
extension RemoteSyncEngine: Resettable {
440421
func reset(onComplete: @escaping BasicClosure) {

AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/Sync/SubscriptionSync/ReconcileAndLocalSave/ReconcileAndLocalSaveOperation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ class ReconcileAndLocalSaveOperation: AsynchronousOperation {
148148
)
149149
.store(in: &cancellables)
150150
}
151-
} catch let dataSotoreError as DataStoreError {
152-
stateMachine.notify(action: .errored(dataSotoreError))
151+
} catch let dataStoreError as DataStoreError {
152+
stateMachine.notify(action: .errored(dataStoreError))
153153
} catch {
154154
let dataStoreError = DataStoreError.invalidOperation(causedBy: error)
155155
stateMachine.notify(action: .errored(dataStoreError))

0 commit comments

Comments
 (0)