Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: feature_flag_called after reloadFeatureFlags #232

Merged
merged 8 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion PostHog/PostHogSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,10 @@ let maxRetryDelay = 30.0
distinctId: storageManager.getDistinctId(),
anonymousId: storageManager.getAnonymousId(),
groups: groups ?? [:],
callback: callback
callback: {
self.flagCallReported.removeAll()
ioannisj marked this conversation as resolved.
Show resolved Hide resolved
callback()
}
)
}

Expand Down
32 changes: 32 additions & 0 deletions PostHogTests/PostHogSDKTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,38 @@ class PostHogSDKTest: QuickSpec {
sut.reset()
sut.close()
}

it("captures $feature_flag_called when feature flag is called") {
let sut = self.getSut(sendFeatureFlagEvent: true)
ioannisj marked this conversation as resolved.
Show resolved Hide resolved
let group = DispatchGroup()
group.enter()
ioannisj marked this conversation as resolved.
Show resolved Hide resolved

_ = sut.getFeatureFlag("some_key")

let event = getBatchedEvents(server)
expect(event.first!.event).to(equal("$feature_flag_called"))
}

it("captures a second $feature_flag_called when feature flag is called after flags are reloaded") {
let sut = self.getSut(sendFeatureFlagEvent: true)
_ = sut.getFeatureFlag("some_key")

let event = getBatchedEvents(server)
expect(event.first!.event).to(equal("$feature_flag_called"))

server.start()

let group = DispatchGroup()

sut.reloadFeatureFlags {
_ = sut.getFeatureFlag("some_key")
sut.flush()
}

let secondEvent = getBatchedEvents(server)

expect(secondEvent.first!.event).to(equal("$feature_flag_called"))
}
}
}

Expand Down
Loading