-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TP 147318] - fix crash that occurs in the test app (#37)
* ensure api key is set before attempting to track an event
- Loading branch information
Showing
6 changed files
with
70 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// LoggerClient.swift | ||
// KlaviyoSwift | ||
// | ||
// Created by Noah Durell on 10/21/22. | ||
// | ||
|
||
import Foundation | ||
import os | ||
|
||
struct LoggerClient { | ||
var error: (String) -> () | ||
static let production = Self(error: { message in os_log("%{public}@", type: .error) }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,13 @@ class Tests: XCTestCase { | |
super.setUp() | ||
Klaviyo.setupWithPublicAPIKey(apiKey: "wbg7GT") | ||
klaviyo = Klaviyo.sharedInstance | ||
environment = KlaviyoEnvironment.test | ||
} | ||
|
||
override func tearDown() { | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
super.tearDown() | ||
LoggerClient.lastLoggedMessage = nil | ||
} | ||
|
||
func testAPIKeyExists() { | ||
|
@@ -90,4 +92,24 @@ class Tests: XCTestCase { | |
} | ||
} | ||
|
||
func testTrackEventWithNoApiKey() { | ||
klaviyo.apiKey = nil | ||
|
||
klaviyo.trackEvent(eventName: "foo") | ||
|
||
XCTAssertEqual(LoggerClient.lastLoggedMessage, "Track event called before API was set.") | ||
|
||
} | ||
|
||
func testTrackPersonWithNoApiKey() { | ||
klaviyo.apiKey = nil | ||
|
||
let emailDict: NSMutableDictionary = [klaviyo.KLPersonEmailDictKey: "[email protected]"] | ||
|
||
klaviyo.trackPersonWithInfo(personDictionary: emailDict) | ||
|
||
XCTAssertEqual(LoggerClient.lastLoggedMessage, "Track person called before setting the API Key.") | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters