Skip to content

Commit

Permalink
test: add unit test for plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Alyssa.Yu authored and Alyssa.Yu committed Feb 23, 2024
1 parent 99e5abe commit d2da89b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Tests/AmplitudeTests/AmplitudeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 13 additions & 0 deletions Tests/AmplitudeTests/Supports/TestUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down

0 comments on commit d2da89b

Please sign in to comment.