Skip to content

Commit

Permalink
Merge pull request #65 from button/paul/clear_pending_tasks
Browse files Browse the repository at this point in the history
Clear pending tasks when clearAllData is called
  • Loading branch information
Paul Fleiner authored Jul 29, 2020
2 parents cae68ef + 782eddb commit 3786ac3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Source/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal protocol ClientType: class {
var session: URLSessionType { get }
var userAgent: UserAgentType { get }
var defaults: ButtonDefaultsType { get }
var pendingTasks: [PendingTask] { get }
var pendingTasks: [PendingTask] { get set }
func fetchPostInstallURL(parameters: [String: Any], _ completion: @escaping (URL?, String?) -> Void)
func reportOrder(orderRequest: ReportOrderRequestType, _ completion: ((Error?) -> Void)?)
func reportEvents(_ events: [AppEvent], ifa: String?, _ completion: ((Error?) -> Void)?)
Expand Down
1 change: 1 addition & 0 deletions Source/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ final internal class Core: CoreType {
*/
func clearAllData() {
buttonDefaults.clearAllData()
client.pendingTasks.removeAll()
}

/**
Expand Down
17 changes: 17 additions & 0 deletions Tests/UnitTests/CoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,23 @@ class CoreTests: XCTestCase {
// Assert
XCTAssertTrue(testDefaults.didCallClearAllData)
}

func testClearAllDataRemovesPendingTasks() {
// Arrange
let request = URLRequest(url: URL(string: "https://example.com")!)
let task = PendingTask(urlRequest: request) { _, _ in }
testClient.pendingTasks.append(task)
let core = Core(buttonDefaults: TestButtonDefaults(userDefaults: TestUserDefaults()),
client: testClient,
system: TestSystem(),
notificationCenter: TestNotificationCenter())

// Act
core.clearAllData()

// Assert
XCTAssertTrue(testClient.pendingTasks.isEmpty)
}

func testHandlePostInstallURL() {
// Arrange
Expand Down

0 comments on commit 3786ac3

Please sign in to comment.