Skip to content

Commit

Permalink
Remove canceling ongoing requests in reset method. (segmentio#691)
Browse files Browse the repository at this point in the history
* remove canceling ongoing batchRequest and remove cache deletion

* add tests for reset
  • Loading branch information
aleksandergrzyb authored and tonyxiao committed May 31, 2017
1 parent 4090886 commit f4900bc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 0 additions & 5 deletions Analytics/Classes/Internal/SEGSegmentIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -513,18 +513,13 @@ - (void)reset
[self.storage removeKey:SEGUserIdKey];
#if TARGET_OS_TV
[self.storage removeKey:SEGTraitsKey];
[self.storage removeKey:SEGQueueKey];
#else
[self.storage removeKey:kSEGUserIdFilename];
[self.storage removeKey:kSEGTraitsFilename];
[self.storage removeKey:kSEGQueueFilename];
#endif

self.userId = nil;
self.traits = [NSMutableDictionary dictionary];
self.queue = [NSMutableArray array];
[self.batchRequest cancel];
self.batchRequest = nil;
}];
}

Expand Down
7 changes: 7 additions & 0 deletions AnalyticsTests/AnalyticsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ class AnalyticsTests: QuickSpec {
expect(referrer?["url"] as? String) == "http://www.segment.com"
}

it("clears user data") {
analytics.identify("testUserId1", traits: [ "Test trait key" : "Test trait value"])
analytics.reset()
expect(analytics.test_integrationsManager()?.test_segmentIntegration()?.test_userId()).toEventually(beNil())
expect(analytics.test_integrationsManager()?.test_segmentIntegration()?.test_traits()?.count).toEventually(equal(0))
}

it("fires Application Opened for UIApplicationDidFinishLaunching") {
testMiddleware.swallowEvent = true
NotificationCenter.default.post(name: .UIApplicationDidFinishLaunching, object: nil, userInfo: [
Expand Down
3 changes: 3 additions & 0 deletions AnalyticsTests/Utils/TestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ extension SEGSegmentIntegration {
func test_userId() -> String? {
return self.value(forKey: "userId") as? String
}
func test_traits() -> [String: AnyObject]? {
return self.value(forKey: "traits") as? [String: AnyObject]
}
}


Expand Down

0 comments on commit f4900bc

Please sign in to comment.