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 e10e50e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Tests/AmplitudeTests/AmplitudeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,41 @@ final class AmplitudeTests: XCTestCase {
XCTAssertEqual(lastEvent?.language!.isEmpty, false)
}

func testFilterAndEnrichmentPlugin() {
let apiKey = "testFilterAndEnrichmentPlugin"
let enrichedEventType = "Enriched Event"
storageTest = TestPersistentStorage(storagePrefix: "storage-\(apiKey)")
let amplitude = Amplitude(configuration: Configuration(
apiKey: apiKey,
storageProvider: storageTest
))

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
}
}
let testPlugin = TestFilterAndEnrichmentPlugin()
amplitude.add(plugin: testPlugin)
amplitude.track(event: BaseEvent(eventType: enrichedEventType))
amplitude.track(event: BaseEvent(eventType: "Other Event"))

let events = storageTest.events()
XCTAssertEqual(events[0].eventType, enrichedEventType)
XCTAssertEqual(getDictionary(events[0].eventProperties!), [
"testPropertyKey": "testPropertyValue"
])

XCTAssertEqual(events.count, 1)
}

func testContextWithDisableTrackingOptions() {
let apiKey = "testApiKeyForDisableTrackingOptions"
let trackingOptions = TrackingOptions()
Expand Down

0 comments on commit e10e50e

Please sign in to comment.