Skip to content

Commit c4e871e

Browse files
sebalandroyjit
authored andcommitted
chore(IntegrationTests): Fixing Analytics and Auth integration tests.
1 parent bf768ff commit c4e871e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Diff for: AmplifyPlugins/Analytics/AWSPinpointAnalyticsPluginIntegrationTests/AWSPinpointAnalyticsPluginIntegrationTests.swift

+48
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,40 @@ class AWSPinpointAnalyticsPluginIntergrationTests: XCTestCase {
7070
Amplify.Analytics.identifyUser(userId, withProfile: userProfile)
7171

7272
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)
73107
}
74108

75109
func testRecordEventsAreFlushed() {
@@ -79,6 +113,7 @@ class AWSPinpointAnalyticsPluginIntergrationTests: XCTestCase {
79113
// TODO: Remove exposing AWSPinpointEvent
80114
guard let pinpointEvents = payload.data as? [PinpointEvent] else {
81115
XCTFail("Missing data")
116+
flushEventsInvoked.fulfill()
82117
return
83118
}
84119
XCTAssertNotNil(pinpointEvents)
@@ -112,4 +147,17 @@ class AWSPinpointAnalyticsPluginIntergrationTests: XCTestCase {
112147
let awsPinpoint = pinpointAnalyticsPlugin.getEscapeHatch()
113148
XCTAssertNotNil(awsPinpoint)
114149
}
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+
}
115163
}

0 commit comments

Comments
 (0)