-
Notifications
You must be signed in to change notification settings - Fork 332
/
Copy pathContextTest.swift
81 lines (67 loc) · 2.31 KB
/
ContextTest.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
//
// ContextTest.swift
// Analytics
//
// Created by Tony Xiao on 9/20/16.
// Copyright © 2016 Segment. All rights reserved.
//
import Segment
import XCTest
class ContextTests: XCTestCase {
var analytics: Analytics!
override func setUp() {
super.setUp()
let config = AnalyticsConfiguration(writeKey: "foobar")
analytics = Analytics(configuration: config)
}
func testThrowsWhenUsedIncorrectly() {
var context: Context?
var exception: NSException?
exception = objc_tryCatch {
context = Context()
}
XCTAssertNil(context)
XCTAssertNotNil(exception)
}
func testInitializedCorrectly() {
let context = Context(analytics: analytics)
XCTAssertEqual(context._analytics, analytics)
XCTAssertEqual(context.eventType, EventType.undefined)
}
func testAcceptsModifications() {
let context = Context(analytics: analytics)
let newContext = context.modify { context in
context.payload = TrackPayload()
context.payload?.userId = "sloth"
context.eventType = .track
}
XCTAssertEqual(newContext.payload?.userId, "sloth")
XCTAssertEqual(newContext.eventType, EventType.track)
}
func testModifiesCopyInDebugMode() {
let context = Context(analytics: analytics).modify { context in
context.debug = true
context.eventType = .track
}
XCTAssertEqual(context.debug, true)
let newContext = context.modify { context in
context.eventType = .identify
}
XCTAssertNotEqual(context, newContext)
XCTAssertEqual(newContext.eventType, .identify)
XCTAssertEqual(context.eventType, .track)
}
func testModifiesSelfInNonDebug() {
let context = Context(analytics: analytics).modify { context in
context.debug = false
context.eventType = .track
}
XCTAssertFalse(context.debug)
let newContext = context.modify { context in
context.eventType = .identify
}
XCTAssertEqual(context, newContext)
XCTAssertEqual(newContext.eventType, .identify)
XCTAssertEqual(context.eventType, .identify)
}
}