|
5 | 5 | // SPDX-License-Identifier: Apache-2.0
|
6 | 6 | //
|
7 | 7 |
|
8 |
| -@testable import Amplify |
9 |
| -import AWSMobileClient |
| 8 | +import XCTest |
| 9 | +import AmplifyPlugins |
10 | 10 | import AWSPinpoint
|
| 11 | + |
| 12 | +@testable import Amplify |
11 | 13 | @testable import AWSPinpointAnalyticsPlugin
|
12 |
| -import XCTest |
| 14 | +@testable import AmplifyTestCommon |
13 | 15 |
|
14 | 16 | // swiftlint:disable:next type_name
|
15 | 17 | class AWSPinpointAnalyticsPluginIntergrationTests: XCTestCase {
|
16 |
| - /* |
17 |
| - Set up |
18 |
| - `amplify init` |
19 |
| - `amplify add analytics` |
20 |
| - * Apps need authorization to send analytics events. Do you want to allow guests and unauthenticated users to send |
21 |
| - analytics events? (we recommend you allow this when getting started) `Yes` |
22 |
| - `amplify push` |
23 |
| - |
24 |
| - Pinpoint URL to track events |
25 |
| - https://us-west-2.console.aws.amazon.com/pinpoint/home/?region=us-west-2#/apps/xxx/analytics/overview |
26 | 18 |
|
27 |
| - awsconfiguration.json |
28 |
| - { |
29 |
| - "UserAgent": "aws-amplify/cli", |
30 |
| - "Version": "0.1.0", |
31 |
| - "IdentityManager": { |
32 |
| - "Default": {} |
33 |
| - }, |
34 |
| - "CredentialsProvider": { |
35 |
| - "CognitoIdentity": { |
36 |
| - "Default": { |
37 |
| - "PoolId": "us-west-2:xxx", |
38 |
| - "Region": "us-west-2" |
39 |
| - } |
40 |
| - } |
41 |
| - }, |
42 |
| - "PinpointAnalytics": { |
43 |
| - "Default": { |
44 |
| - "AppId": "xxx", |
45 |
| - "Region": "us-west-2" |
46 |
| - } |
47 |
| - }, |
48 |
| - "PinpointTargeting": { |
49 |
| - "Default": { |
50 |
| - "Region": "us-west-2" |
51 |
| - } |
52 |
| - } |
53 |
| - } |
54 |
| - |
55 |
| - amplifyconfiguration.json |
56 |
| - { |
57 |
| - "UserAgent": "aws-amplify-cli/2.0", |
58 |
| - "Version": "1.0", |
59 |
| - "analytics": { |
60 |
| - "plugins": { |
61 |
| - "awsPinpointAnalyticsPlugin": { |
62 |
| - "pinpointAnalytics": { |
63 |
| - "appId": "xxxx", |
64 |
| - "region": "us-west-2" |
65 |
| - }, |
66 |
| - "pinpointTargeting": { |
67 |
| - "region": "us-west-2" |
68 |
| - } |
69 |
| - } |
70 |
| - } |
71 |
| - } |
72 |
| - } |
73 |
| - */ |
74 |
| - let analyticsPluginKey = "awsPinpointAnalyticsPlugin" |
| 19 | + static let amplifyConfiguration = "AWSPinpointAnalyticsPluginIntegrationTests-amplifyconfiguration" |
| 20 | + static let analyticsPluginKey = "awsPinpointAnalyticsPlugin" |
75 | 21 |
|
76 | 22 | override func setUp() {
|
77 |
| - let config = [ |
78 |
| - "CredentialsProvider": [ |
79 |
| - "CognitoIdentity": [ |
80 |
| - "Default": [ |
81 |
| - "PoolId": "us-west-2:xxx", |
82 |
| - "Region": "us-west-2" |
83 |
| - ] |
84 |
| - ] |
85 |
| - ] |
86 |
| - ] |
87 |
| - AWSInfo.configureDefaultAWSInfo(config) |
88 |
| - |
89 |
| - let mobileClientIsInitialized = expectation(description: "AWSMobileClient is initialized") |
90 |
| - AWSMobileClient.default().initialize { userState, error in |
91 |
| - guard error == nil else { |
92 |
| - XCTFail("Error initializing AWSMobileClient. Error: \(error!.localizedDescription)") |
93 |
| - return |
94 |
| - } |
95 |
| - guard let userState = userState else { |
96 |
| - XCTFail("userState is unexpectedly empty initializing AWSMobileClient") |
97 |
| - return |
98 |
| - } |
99 |
| - if userState != UserState.signedOut { |
100 |
| - AWSMobileClient.default().signOut() |
101 |
| - } |
102 |
| - mobileClientIsInitialized.fulfill() |
103 |
| - } |
104 |
| - wait(for: [mobileClientIsInitialized], timeout: 100) |
105 |
| - print("AWSMobileClient Initialized") |
106 |
| - |
107 |
| - let analyticsConfig = AnalyticsCategoryConfiguration( |
108 |
| - plugins: [ |
109 |
| - "awsPinpointAnalyticsPlugin": [ |
110 |
| - "pinpointAnalytics": [ |
111 |
| - "appId": "xxxxx", |
112 |
| - "region": "us-west-2" |
113 |
| - ], |
114 |
| - "pinpointTargeting": [ |
115 |
| - "region": "us-west-2" |
116 |
| - ], |
117 |
| - "autoFlushEventsInterval": 10, |
118 |
| - "trackAppSessions": true, |
119 |
| - "autoSessionTrackingInterval": 2 |
120 |
| - ] |
121 |
| - ]) |
122 |
| - |
123 |
| - let amplifyConfig = AmplifyConfiguration(analytics: analyticsConfig) |
124 |
| - |
125 | 23 | do {
|
| 24 | + let config = try TestConfigHelper.retrieveAmplifyConfiguration( |
| 25 | + forResource: AWSPinpointAnalyticsPluginIntergrationTests.amplifyConfiguration) |
| 26 | + try Amplify.add(plugin: AWSAuthPlugin()) |
126 | 27 | try Amplify.add(plugin: AWSPinpointAnalyticsPlugin())
|
127 |
| - try Amplify.configure(amplifyConfig) |
| 28 | + try Amplify.configure(config) |
128 | 29 | } catch {
|
129 |
| - XCTFail("Failed to initialize and configure Amplify") |
| 30 | + XCTFail("Failed to initialize and configure Amplify \(error)") |
130 | 31 | }
|
131 |
| - |
132 |
| - print("Amplify initialized") |
133 | 32 | }
|
134 | 33 |
|
135 | 34 | override func tearDown() {
|
136 |
| - print("Amplify reset") |
137 | 35 | Amplify.reset()
|
138 | 36 | }
|
139 | 37 |
|
@@ -171,7 +69,7 @@ class AWSPinpointAnalyticsPluginIntergrationTests: XCTestCase {
|
171 | 69 | properties: properties)
|
172 | 70 | Amplify.Analytics.identifyUser(userId, withProfile: userProfile)
|
173 | 71 |
|
174 |
| - wait(for: [identifyUserEvent], timeout: 20) |
| 72 | + wait(for: [identifyUserEvent], timeout: TestCommonConstants.networkTimeout) |
175 | 73 | }
|
176 | 74 |
|
177 | 75 | func testRecordEventsAreFlushed() {
|
@@ -199,12 +97,14 @@ class AWSPinpointAnalyticsPluginIntergrationTests: XCTestCase {
|
199 | 97 | "eventPropertyBoolKey": true] as [String: AnalyticsPropertyValue]
|
200 | 98 | let event = BasicAnalyticsEvent(name: "eventName", properties: properties)
|
201 | 99 | Amplify.Analytics.record(event: event)
|
| 100 | + Amplify.Analytics.flushEvents() |
202 | 101 |
|
203 |
| - wait(for: [flushEventsInvoked], timeout: 20) |
| 102 | + wait(for: [flushEventsInvoked], timeout: TestCommonConstants.networkTimeout) |
204 | 103 | }
|
205 | 104 |
|
206 | 105 | func testGetEscapeHatch() throws {
|
207 |
| - let plugin = try Amplify.Analytics.getPlugin(for: analyticsPluginKey) |
| 106 | + let plugin = try Amplify.Analytics.getPlugin( |
| 107 | + for: AWSPinpointAnalyticsPluginIntergrationTests.analyticsPluginKey) |
208 | 108 | guard let pinpointAnalyticsPlugin = plugin as? AWSPinpointAnalyticsPlugin else {
|
209 | 109 | XCTFail("Could not get plugin of type AWSPinpointAnalyticsPlugin")
|
210 | 110 | return
|
|
0 commit comments