Skip to content

fix(EventDispatcher): change eventEndPoint to public #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Data Model/DispatchEvents/EventForDispatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation

@objcMembers public class EventForDispatch: NSObject, Codable {
static let eventEndpoint = "https://logx.optimizely.com/v1/events"
public static var eventEndpoint = "https://logx.optimizely.com/v1/events"

public let url: URL
public let body: Data
Expand Down
34 changes: 32 additions & 2 deletions Tests/OptimizelyTests-Common/EventDispatcherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,46 @@ class EventDispatcherTests: XCTestCase {
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

func testDispatcherCustom() {
func testDispatcherCustomUrl() {
let dispatcher = MockEventDispatcher()

let originalUrl = "https://logx.optimizely.com/v1/events"
let customUrl = "https://google.com"
let overrideUrl = "https://apple.com"

// default end-point

dispatcher.dispatchEvent(event: EventForDispatch(body: Data()), completionHandler: nil)

XCTAssert(dispatcher.events.count == 1)
XCTAssert(dispatcher.events.first?.url.absoluteString == originalUrl)
dispatcher.flushEvents()
XCTAssert(dispatcher.events.count == 0)

// customize end-point

EventForDispatch.eventEndpoint = customUrl
dispatcher.dispatchEvent(event: EventForDispatch(body: Data()), completionHandler: nil)

XCTAssert(dispatcher.events.count == 1)
XCTAssert(dispatcher.events.first?.url.absoluteString == customUrl)
dispatcher.flushEvents()

XCTAssert(dispatcher.events.count == 0)
// override end-point

dispatcher.dispatchEvent(event: EventForDispatch(url: URL(string: overrideUrl), body: Data()), completionHandler: nil)

XCTAssert(dispatcher.events.count == 1)
XCTAssert(dispatcher.events.first?.url.absoluteString == overrideUrl)
dispatcher.flushEvents()

// saved custom end-point

dispatcher.dispatchEvent(event: EventForDispatch(body: Data()), completionHandler: nil)

XCTAssert(dispatcher.events.count == 1)
XCTAssert(dispatcher.events.first?.url.absoluteString == customUrl)
dispatcher.flushEvents()
}

func testDispatcherMethods() {
Expand Down