Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mscwilson committed Sep 21, 2023
1 parent 9a72c26 commit 8a3d0d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
14 changes: 7 additions & 7 deletions Tests/Global Contexts/TestGlobalContexts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class TestGlobalContexts: XCTestCase {
let serviceProvider = getServiceProviderWithGlobalContextGenerators(&globalContexts)

let event = Structured(category: "Category", action: "Action")
let trackerEvent = TrackerEvent(event: event, state: nil)
let trackerEvent = TrackerEvent(event: event, eventId: UUID(), state: nil)

serviceProvider.tracker.addStateMachineEntities(event: trackerEvent)
XCTAssertTrue(trackerEvent.entities.count == 1)
Expand Down Expand Up @@ -163,7 +163,7 @@ class TestGlobalContexts: XCTestCase {
let serviceProvider = getServiceProviderWithGlobalContextGenerators(&globalContexts)

let event = Structured(category: stringToMatch, action: "Action")
let trackerEvent = TrackerEvent(event: event, state: nil)
let trackerEvent = TrackerEvent(event: event, eventId: UUID(), state: nil)

serviceProvider.tracker.addStateMachineEntities(event: trackerEvent)
XCTAssertTrue(trackerEvent.entities.count == 1)
Expand All @@ -187,21 +187,21 @@ class TestGlobalContexts: XCTestCase {

// Not matching primitive event
let primitiveEvent = Structured(category: "Category", action: "Action")
var trackerEvent = TrackerEvent(event: primitiveEvent, state: nil)
var trackerEvent = TrackerEvent(event: primitiveEvent, eventId: UUID(), state: nil)
serviceProvider.tracker.addStateMachineEntities(event: trackerEvent)
XCTAssertTrue(trackerEvent.entities.count == 0)

// Not matching self-describing event with mobile schema
let screenView = ScreenView(name: "Name", screenId: nil)
screenView.type = "Type"
trackerEvent = TrackerEvent(event: screenView, state: nil)
trackerEvent = TrackerEvent(event: screenView, eventId: UUID(), state: nil)
serviceProvider.tracker.addStateMachineEntities(event: trackerEvent)
XCTAssertTrue(trackerEvent.entities.count == 0)

// Matching self-describing event with general schema
let timing = Timing(category: "Category", variable: "Variable", timing: 123)
timing.label = "Label"
trackerEvent = TrackerEvent(event: timing, state: nil)
trackerEvent = TrackerEvent(event: timing, eventId: UUID(), state: nil)
serviceProvider.tracker.addStateMachineEntities(event: trackerEvent)
XCTAssertTrue(trackerEvent.entities.count == 1)
XCTAssertEqual(trackerEvent.entities[0].schema, "schema")
Expand All @@ -220,7 +220,7 @@ class TestGlobalContexts: XCTestCase {
let serviceProvider = getServiceProviderWithGlobalContextGenerators(&generators)

let event = Structured(category: "Category", action: "Action")
let trackerEvent = TrackerEvent(event: event, state: nil)
let trackerEvent = TrackerEvent(event: event, eventId: UUID(), state: nil)

serviceProvider.tracker.addStateMachineEntities(event: trackerEvent)
XCTAssertTrue(trackerEvent.entities.count == 1)
Expand All @@ -235,7 +235,7 @@ class TestGlobalContexts: XCTestCase {
let serviceProvider = getServiceProviderWithGlobalContextGenerators(&generators)

let event = Structured(category: "StringToMatch", action: "Action")
let trackerEvent = TrackerEvent(event: event, state: nil)
let trackerEvent = TrackerEvent(event: event, eventId: UUID(), state: nil)

serviceProvider.tracker.addStateMachineEntities(event: trackerEvent)
XCTAssertTrue(trackerEvent.entities.count == 1)
Expand Down
11 changes: 1 addition & 10 deletions Tests/Legacy Tests/LegacyTestTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class LegacyTestTracker: XCTestCase {
}

let event = Structured(category: "Category", action: "Action")
let trackerEvent = TrackerEvent(event: event, state: nil)
let trackerEvent = TrackerEvent(event: event, eventId: UUID(), state: nil)
var payload = tracker.payload(with: trackerEvent)
var payloadDict = payload!.dictionary

Expand All @@ -135,14 +135,5 @@ class LegacyTestTracker: XCTestCase {
XCTAssertEqual(payloadDict[kSPAppId] as? String, "newAppId")
XCTAssertEqual(payloadDict[kSPNamespace] as? String, "newNamespace")
}

func testEventIdNotDuplicated() {
let event = Structured(category: "Category", action: "Action")
let eventId = TrackerEvent(event: event, state: nil).eventId
XCTAssertNotNil(eventId)
let newEventId = TrackerEvent(event: event, state: nil).eventId
XCTAssertNotNil(newEventId)
XCTAssertNotEqual(eventId, newEventId)
}
}
//#pragma clang diagnostic pop
18 changes: 9 additions & 9 deletions Tests/TestStateManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,31 @@ class TestStateManager: XCTestCase {
var trackerState = stateManager.trackerState(forProcessedEvent: eventInc)
let mockState = trackerState?.state(withStateMachine: stateMachine) as? MockState
XCTAssertEqual(1, mockState?.value)
var e = TrackerEvent(event: eventInc, state: trackerState)
var e = TrackerEvent(event: eventInc, eventId: UUID(), state: trackerState)
var entities = stateManager.entities(forProcessedEvent: e)
XCTAssertEqual(1, ((entities[0].data) as? [String : Int])?["value"])
XCTAssertTrue(stateManager.addPayloadValues(to: e))
XCTAssertNil((e.payload)["newParam"])

trackerState = stateManager.trackerState(forProcessedEvent: eventInc)
XCTAssertEqual(2, (trackerState?.state(withStateMachine: stateMachine) as? MockState)?.value)
e = TrackerEvent(event: eventInc, state: trackerState)
e = TrackerEvent(event: eventInc, eventId: UUID(), state: trackerState)
entities = stateManager.entities(forProcessedEvent: e)
XCTAssertEqual(2, ((entities[0].data) as? [String : Int])?["value"])
XCTAssertTrue(stateManager.addPayloadValues(to: e))
XCTAssertNil((e.payload)["newParam"])

trackerState = stateManager.trackerState(forProcessedEvent: eventDec)
XCTAssertEqual(1, (trackerState?.state(withStateMachine: stateMachine) as? MockState)?.value)
e = TrackerEvent(event: eventDec, state: trackerState)
e = TrackerEvent(event: eventDec, eventId: UUID(), state: trackerState)
entities = stateManager.entities(forProcessedEvent: e)
XCTAssertEqual(1, ((entities[0].data) as? [String : Int])?["value"])
XCTAssertTrue(stateManager.addPayloadValues(to: e))
XCTAssertNil((e.payload)["newParam"])

trackerState = stateManager.trackerState(forProcessedEvent: event)
XCTAssertEqual(1, (trackerState?.state(withStateMachine: stateMachine) as? MockState)?.value)
e = TrackerEvent(event: event, state: trackerState)
e = TrackerEvent(event: event, eventId: UUID(), state: trackerState)
entities = stateManager.entities(forProcessedEvent: e)
XCTAssertEqual(1, ((entities[0].data) as? [String : Int])?["value"])
XCTAssertTrue(stateManager.addPayloadValues(to: e))
Expand All @@ -166,7 +166,7 @@ class TestStateManager: XCTestCase {
let trackerState = stateManager.trackerState(forProcessedEvent: eventInc)
let mockState = trackerState?.state(withIdentifier: "identifier") as? MockState
XCTAssertNil(mockState)
let e = TrackerEvent(event: eventInc, state: trackerState)
let e = TrackerEvent(event: eventInc, eventId: UUID(), state: trackerState)
let entities = stateManager.entities(forProcessedEvent: e)
XCTAssertEqual(0, entities.count)
}
Expand All @@ -181,7 +181,7 @@ class TestStateManager: XCTestCase {
])

let trackerState = stateManager.trackerState(forProcessedEvent: eventInc)
let e = TrackerEvent(event: eventInc, state: trackerState)
let e = TrackerEvent(event: eventInc, eventId: UUID(), state: trackerState)
let entities = stateManager.entities(forProcessedEvent: e)
XCTAssertEqual(2, entities.count)
}
Expand All @@ -196,7 +196,7 @@ class TestStateManager: XCTestCase {
])

let trackerState = stateManager.trackerState(forProcessedEvent: eventInc)
let e = TrackerEvent(event: eventInc, state: trackerState)
let e = TrackerEvent(event: eventInc, eventId: UUID(), state: trackerState)
let entities = stateManager.entities(forProcessedEvent: e)
XCTAssertEqual(1, entities.count)
}
Expand Down Expand Up @@ -234,13 +234,13 @@ class TestStateManager: XCTestCase {

XCTAssertFalse(
stateManager.filter(
event: TrackerEvent(event: SelfDescribing(schema: "s1", payload: [:]))
event: TrackerEvent(event: SelfDescribing(schema: "s1", payload: [:]), eventId: UUID())
)
)

XCTAssertTrue(
stateManager.filter(
event: TrackerEvent(event: SelfDescribing(schema: "s2", payload: [:]))
event: TrackerEvent(event: SelfDescribing(schema: "s2", payload: [:]), eventId: UUID())
)
)
}
Expand Down

0 comments on commit 8a3d0d6

Please sign in to comment.