diff --git a/Tests/AmplitudeTests/AmplitudeTests.swift b/Tests/AmplitudeTests/AmplitudeTests.swift index de7cc66f..21ff7c8e 100644 --- a/Tests/AmplitudeTests/AmplitudeTests.swift +++ b/Tests/AmplitudeTests/AmplitudeTests.swift @@ -82,6 +82,28 @@ final class AmplitudeTests: XCTestCase { XCTAssertEqual(lastEvent?.language!.isEmpty, false) } + func testFilterAndEnrichmentPlugin() { + let apiKey = "testFilterAndEnrichmentPlugin" + storageTest = TestPersistentStorage(storagePrefix: "storage") + let amplitude = Amplitude(configuration: Configuration( + apiKey: apiKey, + storageProvider: storageTest + )) + + let testPlugin = TestFilterAndEnrichmentPlugin() + amplitude.add(plugin: testPlugin) + amplitude.track(event: BaseEvent(eventType: "Enriched Event")) + amplitude.track(event: BaseEvent(eventType: "Other Event")) + + let events = storageTest.events() + XCTAssertEqual(events[0].eventType, "Enriched Event") + XCTAssertEqual(getDictionary(events[0].eventProperties!), [ + "testPropertyKey": "testPropertyValue" + ]) + + XCTAssertEqual(events.count, 1) + } + func testContextWithDisableTrackingOptions() { let apiKey = "testApiKeyForDisableTrackingOptions" let trackingOptions = TrackingOptions() diff --git a/Tests/AmplitudeTests/Supports/TestUtilities.swift b/Tests/AmplitudeTests/Supports/TestUtilities.swift index d16bd923..e4a84044 100644 --- a/Tests/AmplitudeTests/Supports/TestUtilities.swift +++ b/Tests/AmplitudeTests/Supports/TestUtilities.swift @@ -23,6 +23,19 @@ class TestEnrichmentPlugin: EnrichmentPlugin { } } +class TestFilterAndEnrichmentPlugin: EnrichmentPlugin { + override func execute(event: BaseEvent) -> BaseEvent? { + if event.eventType == "Enriched Event" { + if event.eventProperties == nil { + event.eventProperties = [:] + } + event.eventProperties!["testPropertyKey"] = "testPropertyValue" + return event + } + return nil + } +} + class OutputReaderPlugin: DestinationPlugin { var lastEvent: BaseEvent?