@@ -70,6 +70,40 @@ class AWSPinpointAnalyticsPluginIntergrationTests: XCTestCase {
70
70
Amplify . Analytics. identifyUser ( userId, withProfile: userProfile)
71
71
72
72
wait ( for: [ identifyUserEvent] , timeout: TestCommonConstants . networkTimeout)
73
+
74
+ // Remove userId from the current endpoint
75
+ let targetingClient = escapeHatch ( ) . targetingClient
76
+ let currentProfile = targetingClient. currentEndpointProfile ( )
77
+ currentProfile. user? . userId = " "
78
+ targetingClient. update ( currentProfile)
79
+ }
80
+
81
+ /// Run this test when the number of endpoints for the userId exceeds the limit.
82
+ /// The profile should have permissions to run the "mobiletargeting:DeleteUserEndpoints" action.
83
+ func skip_testDeleteEndpointsForUser( ) throws {
84
+ let userId = " userId "
85
+ let escapeHatch = escapeHatch ( )
86
+ let applicationId = escapeHatch. configuration. appId
87
+ guard let targetingConfiguration = escapeHatch. configuration. targetingServiceConfiguration else {
88
+ XCTFail ( " Targeting configuration is not defined. " )
89
+ return
90
+ }
91
+
92
+ let deleteEndpointsRequest = AWSPinpointTargetingDeleteUserEndpointsRequest ( ) !
93
+ deleteEndpointsRequest. userId = userId
94
+ deleteEndpointsRequest. applicationId = applicationId
95
+
96
+ let deleteExpectation = expectation ( description: " Delete endpoints " )
97
+ let lowLevelClient = lowLevelClient ( from: targetingConfiguration)
98
+ lowLevelClient. deleteUserEndpoints ( deleteEndpointsRequest) { response, error in
99
+ guard error == nil else {
100
+ XCTFail ( " Unexpected error when attempting to delete endpoints " )
101
+ deleteExpectation. fulfill ( )
102
+ return
103
+ }
104
+ deleteExpectation. fulfill ( )
105
+ }
106
+ wait ( for: [ deleteExpectation] , timeout: 1 )
73
107
}
74
108
75
109
func testRecordEventsAreFlushed( ) {
@@ -79,6 +113,7 @@ class AWSPinpointAnalyticsPluginIntergrationTests: XCTestCase {
79
113
// TODO: Remove exposing AWSPinpointEvent
80
114
guard let pinpointEvents = payload. data as? [ PinpointEvent ] else {
81
115
XCTFail ( " Missing data " )
116
+ flushEventsInvoked. fulfill ( )
82
117
return
83
118
}
84
119
XCTAssertNotNil ( pinpointEvents)
@@ -112,4 +147,17 @@ class AWSPinpointAnalyticsPluginIntergrationTests: XCTestCase {
112
147
let awsPinpoint = pinpointAnalyticsPlugin. getEscapeHatch ( )
113
148
XCTAssertNotNil ( awsPinpoint)
114
149
}
150
+
151
+ private func escapeHatch( ) -> AWSPinpoint {
152
+ guard let plugin = try ? Amplify . Analytics. getPlugin ( for: " awsPinpointAnalyticsPlugin " ) ,
153
+ let analyticsPlugin = plugin as? AWSPinpointAnalyticsPlugin else {
154
+ fatalError ( " Unable to retrieve configuration " )
155
+ }
156
+ return analyticsPlugin. getEscapeHatch ( )
157
+ }
158
+
159
+ private func lowLevelClient( from configuration: AWSServiceConfiguration ) -> AWSPinpointTargeting {
160
+ AWSPinpointTargeting . register ( with: configuration, forKey: " integrationTestsTargetingConfiguration " )
161
+ return AWSPinpointTargeting . init ( forKey: " integrationTestsTargetingConfiguration " )
162
+ }
115
163
}
0 commit comments