-
Notifications
You must be signed in to change notification settings - Fork 16
/
APITest.swift
82 lines (66 loc) · 3.02 KB
/
APITest.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import CioInternalCommon // do not use `@testable` so we can test functions are made public and not `internal`.
import Foundation
import SharedTests
import XCTest
/**
Contains an example of every public facing SDK function call. This file helps
us prevent introducing breaking changes to the SDK by accident. If a public function
of the SDK is modified, this test class will not successfully compile. By not compiling,
that is a reminder to either fix the compilation and introduce the breaking change or
fix the mistake and not introduce the breaking change in the code base.
*/
class CommonAPITest: UnitTest {
// Test that public functions are accessible by mocked instances
let mock = CustomerIOInstanceMock()
let dictionaryData: [String: Any] = ["foo": true, "bar": ""]
struct CodableExample: Codable {
let foo: String
}
let codedData = CodableExample(foo: "")
func test_allPublicStaticPropertiesAvailable() throws {
try skipRunningTest()
_ = CustomerIO.version
}
// This function checks that public functions exist for the SDK and they are callable.
// Maybe we forgot to add a function? Maybe we forgot to make a function `public`?
func test_allPublicTrackingFunctions() throws {
try skipRunningTest()
// Reference some objects that should be public in the Tracking module
let _: Region = .EU
let _: CioLogLevel = .debug
mock.identify(userId: "", traits: nil)
mock.identify(userId: "", traits: dictionaryData)
mock.identify(userId: "", traits: codedData)
// clear identify
mock.clearIdentify()
// event tracking
mock.track(name: "", properties: nil)
mock.track(name: "", properties: dictionaryData)
mock.track(name: "", properties: codedData)
// screen tracking
mock.screen(title: "", properties: nil)
mock.screen(title: "", properties: dictionaryData)
mock.screen(title: "", properties: codedData)
// register push token
mock.registerDeviceToken("")
// delete push token
mock.deleteDeviceToken()
// track push metric
let metric = Metric.delivered
mock.trackMetric(deliveryID: "", event: metric, deviceToken: "")
// profile attributes
mock.profileAttributes = dictionaryData
// device attributes
mock.deviceAttributes = dictionaryData
}
// This function checks that SdkConfig is accessible and can be created using the factory.
func test_createSdkConfig() {
// Outside of the Common module, we should be able to create a `SdkConfig` using the factory.
_ = SdkConfig.Factory.create(logLevel: .debug)
// Factory method should allow nil values for `SdkConfig` to enable fallback to defaults.
_ = SdkConfig.Factory.create(logLevel: nil)
// Wrapper SDKs should be able to create a `SdkConfig` from a dictionary.
let configOptions: [String: Any] = [:]
_ = SdkConfig.Factory.create(from: configOptions)
}
}