Skip to content

Commit

Permalink
Update tests (#316)
Browse files Browse the repository at this point in the history
I'm reviewing tests failures that happen on my machine
  • Loading branch information
andre-statsig authored Dec 9, 2024
1 parent 00a0ef7 commit 1decf36
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Sources/Statsig/EventLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class EventLogger {
}
}

func start(flushInterval: Double = 60) {
func start(flushInterval: TimeInterval = 60) {
DispatchQueue.main.async { [weak self] in
self?.flushTimer?.invalidate()
self?.flushTimer = Timer.scheduledTimer(withTimeInterval: flushInterval, repeats: true) { [weak self] _ in
Expand Down
2 changes: 2 additions & 0 deletions Tests/StatsigTests/EventLoggerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class EventLoggerSpec: BaseSpec {
logger.stop()

expect(isPendingRequest).toEventually(beFalse())
expect(userDefaults.data[getFailedEventStorageKey("client-key")] as? [Data]).toEventuallyNot(beNil())

isPendingRequest = true

let savedData = userDefaults.data[getFailedEventStorageKey("client-key")] as? [Data]
Expand Down
15 changes: 8 additions & 7 deletions Tests/StatsigTests/StatsigSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ class StatsigSpec: BaseSpec {

var event = events[0]
var user = event["user"] as! [String: Any]
var metadata = event["metadata"] as! [String: String]?
var metadata = event["metadata"] as! [String: Any]?
var secondaryExposures = event["secondaryExposures"] as! [[String: String]]?
var value = event["value"]

Expand All @@ -764,7 +764,7 @@ class StatsigSpec: BaseSpec {

event = events[1]
user = event["user"] as! [String: Any]
metadata = event["metadata"] as! [String: String]?
metadata = event["metadata"] as! [String: Any]?
secondaryExposures = event["secondaryExposures"] as! [[String: String]]?
value = event["value"]

Expand All @@ -777,7 +777,8 @@ class StatsigSpec: BaseSpec {
"ruleID": "default",
"reason": "Network:Recognized",
"lcut": "0",
"receivedAt": metadata!["receivedAt"]!
"receivedAt": metadata!["receivedAt"]!,
"rulePassed": false
]))
)
expect(secondaryExposures).to(equal([]))
Expand All @@ -786,7 +787,7 @@ class StatsigSpec: BaseSpec {

event = events[2]
user = event["user"] as! [String: Any]
metadata = event["metadata"] as! [String: String]?
metadata = event["metadata"] as! [String: Any]?
secondaryExposures = event["secondaryExposures"] as! [[String: String]]?
value = event["value"]

Expand All @@ -800,7 +801,7 @@ class StatsigSpec: BaseSpec {

event = events[3]
user = event["user"] as! [String: Any]
metadata = event["metadata"] as! [String: String]?
metadata = event["metadata"] as! [String: Any]?
secondaryExposures = event["secondaryExposures"] as! [[String: String]]?
value = event["value"]

Expand All @@ -814,7 +815,7 @@ class StatsigSpec: BaseSpec {

event = events[4]
user = event["user"] as! [String: Any]
metadata = event["metadata"] as! [String: String]?
metadata = event["metadata"] as! [String: Any]?
secondaryExposures = event["secondaryExposures"] as! [[String: String]]?
value = event["value"]

Expand All @@ -827,7 +828,7 @@ class StatsigSpec: BaseSpec {

event = events[5]
user = event["user"] as! [String: Any]
metadata = event["metadata"] as! [String: String]?
metadata = event["metadata"] as! [String: Any]?
secondaryExposures = event["secondaryExposures"] as! [[String: String]]?
value = event["value"]

Expand Down
9 changes: 0 additions & 9 deletions Tests/StatsigTests/StatsigUserSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class StatsigUserSpec: BaseSpec {

let validJSONObject: [String: StatsigUserCustomTypeConvertible] =
["company": "Statsig", "YOE": 10.5, "alias": ["abby", "bob", "charlie"]]
let invalidJSONObject: [String: StatsigUserCustomTypeConvertible] =
["company": "Statsig", "invalid": String(bytes: [0xD8, 0x00] as [UInt8], encoding: String.Encoding.utf16BigEndian)!]

describe("creating a new StatsigUser") {
it("is a valid empty user") {
Expand Down Expand Up @@ -65,13 +63,6 @@ class StatsigUserSpec: BaseSpec {
expect(userWithPrivateDict["privateAttributes"]).to(beNil())
}

it("is a user with invalid custom attribute") {
let validUserInvalidCustom = StatsigUser(userID: "12345", custom: invalidJSONObject)
expect(validUserInvalidCustom).toNot(beNil())
expect(validUserInvalidCustom.userID) == "12345"
expect(validUserInvalidCustom.custom).to(beNil())
}

it("keeps customIDs in the json") {
let user = StatsigUser(userID: "12345", customIDs: ["company_id": "998877"])
let json = user.toDictionary(forLogging: false)
Expand Down

0 comments on commit 1decf36

Please sign in to comment.