Skip to content

Commit

Permalink
Match BaseEvent entities API with Android tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
mscwilson committed Jan 29, 2024
1 parent 39b8250 commit caaf856
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Examples
Submodule Examples updated 149 files
8 changes: 4 additions & 4 deletions Sources/Snowplow/Events/EventBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,18 @@ public class Event: NSObject {
return self
}

/// Replace the context entities attached to the event with a new list of entities.
/// Adds a list of context entities to the existing ones.
@objc
public func entities(_ entities: [SelfDescribingJson]) -> Self {
self.entities = entities
self.entities.append(contentsOf: entities)
return self
}

/// Replace the context entities attached to the event with a new list of entities.
/// Adds a list of context entities to the existing ones.
@objc
@available(*, deprecated, renamed: "entities")
public func contexts(_ entities: [SelfDescribingJson]) -> Self {
self.entities = entities
self.entities.append(contentsOf: entities)
return self
}
}
Expand Down
21 changes: 21 additions & 0 deletions Tests/TestEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ class TestEvents: XCTestCase {
event.trueTimestamp = testDate
XCTAssertEqual(event.trueTimestamp, testDate)
}

func testEntities() {
let event = ScreenView(name: "screen")
let entity1 = SelfDescribingJson(schema: "schema1", andData: [String:NSObject]())
let entity2 = SelfDescribingJson(schema: "schema2", andData: [String:NSObject]())
let entity3 = SelfDescribingJson(schema: "schema3", andData: [String:NSObject]())

event.entities.append(entity1)
XCTAssertEqual(1, event.entities.count)

_ = event.entities([entity2])
XCTAssertEqual(2, event.entities.count)

_ = event.contexts([entity3])
XCTAssertEqual(3, event.entities.count)

XCTAssertEqual(3, event.contexts.count)
XCTAssertTrue(event.entities.contains(entity1))
XCTAssertTrue(event.entities.contains(entity2))
XCTAssertTrue(event.entities.contains(entity3))
}

func testApplicationInstall() {
// Prepare ApplicationInstall event
Expand Down

0 comments on commit caaf856

Please sign in to comment.