Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import XCTest

final class MParticleBackendControllerDelegateTests: MParticleTestBase {

func testForwardLogInstall() {
func test_forwardLogInstall_forwardsCall_onMainQueue() {
mparticle.forwardLogInstall()
XCTAssertEqual(executor.executeOnMainAsync, true)
XCTAssertTrue(kitContainer.forwardSDKCallCalled)
Expand All @@ -25,7 +25,7 @@ final class MParticleBackendControllerDelegateTests: MParticleTestBase {
XCTAssertNil(kitContainer.forwardSDKCallUserInfoParam)
}

func testForwardLogUpdate() {
func test_forwardLogUpdate_forwardsCall_onMainQueue() {
mparticle.forwardLogUpdate()
XCTAssertEqual(executor.executeOnMainAsync, true)
XCTAssertTrue(kitContainer.forwardSDKCallCalled)
Expand Down
14 changes: 7 additions & 7 deletions UnitTests/SwiftTests/MParticle/MParticleBreadcrumbTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import XCTest

final class MParticleBreadcrumbTests: MParticleTestBase {

func testLeaveBreadcrumbCallback_withDataFilterNotSet_forwardsTransformedEvent() {
func test_leaveBreadcrumbCallback_forwardsEvent_whenDataFilterIsNil() {
mparticle.dataPlanFilter = nil
XCTAssertNil(mparticle.dataPlanFilter)

Expand All @@ -32,7 +32,7 @@ final class MParticleBreadcrumbTests: MParticleTestBase {
assertReceivedMessage("Left breadcrumb", event: event)
}

func testLeaveBreadcrumbCallback_withDataFilterSet_andDataFilterReturnNil() {
func test_leaveBreadcrumbCallback_blocksEvent_whenFilterReturnsNil() {
mparticle.leaveBreadcrumbCallback(event, execStatus: .success)

XCTAssertTrue(dataPlanFilter.transformEventCalled)
Expand All @@ -41,18 +41,18 @@ final class MParticleBreadcrumbTests: MParticleTestBase {
assertReceivedMessage("Blocked breadcrumb event from kits", event: event)
}

func testLeaveBreadcrumbCallback_execStatusFail_noLoggedMessages() {
func test_leaveBreadcrumbCallback_doesNotLog_whenExecStatusFail() {
mparticle.leaveBreadcrumbCallback(event, execStatus: .fail)

XCTAssertNil(receivedMessage)
}

func testLeaveBreadcrumb_eventNamePassed_backendControllerReceiveCorrectName() {
func test_leaveBreadcrumb_passesEventName_toBackendController() {
mparticle.leaveBreadcrumb(event.name, eventInfo: event.customAttributes)
XCTAssertEqual(backendController.eventWithNameEventNameParam, event.name)
}

func testLeaveBreadcrumb_eventNamePassed_backendControllerReturnsNilEvent_newEventCreated() {
func test_leaveBreadcrumb_createsNewEvent_whenNoExistingEventFound() {
mparticle.leaveBreadcrumb(event.name, eventInfo: event.customAttributes)
XCTAssertEqual(backendController.leaveBreadcrumbEventParam?.name, event.name)
XCTAssertEqual(backendController.leaveBreadcrumbEventParam?.type, .other)
Expand All @@ -61,7 +61,7 @@ final class MParticleBreadcrumbTests: MParticleTestBase {
XCTAssertNotNil(backendController.leaveBreadcrumbCompletionHandler)
}

func testLeaveBreadcrumb_eventNamePassed_backendControllerReturnsEvent_eventModified() {
func test_leaveBreadcrumb_updatesExistingEvent_whenEventAlreadyExists() {
backendController.eventSet?.add(event as Any)
mparticle.leaveBreadcrumb(event.name, eventInfo: event.customAttributes)
XCTAssertEqual(backendController.leaveBreadcrumbEventParam?.name, event.name)
Expand All @@ -71,7 +71,7 @@ final class MParticleBreadcrumbTests: MParticleTestBase {
XCTAssertNotNil(backendController.leaveBreadcrumbCompletionHandler)
}

func testLeaveBreadcrumb_eventNamePassed_CallbackCallsCallbackFunction() {
func test_leaveBreadcrumb_invokesCallback_andLogsMessage() {
mparticle.dataPlanFilter = nil
mparticle.leaveBreadcrumb(event.name, eventInfo: event.customAttributes)
backendController.leaveBreadcrumbCompletionHandler?(event, .success)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import XCTest
import mParticle_Apple_SDK
#endif

@available(*, deprecated, message: "Used only for testing deprecated APIs")
final class MParticleCommerceEventTests: MParticleTestBase {

func testLogCommerceEvent_assignsTimestampWhenNil() {
func test_logCommerceEvent_assignsTimestampIfMissing() {
commerceEvent.setTimestamp(nil)

mparticle.logCommerceEvent(commerceEvent)
Expand All @@ -25,7 +26,7 @@ final class MParticleCommerceEventTests: MParticleTestBase {
XCTAssertTrue(executor.executeOnMessageQueueAsync)
}

func testLogCommerceEventWithFilterReturningNil_blocksEvent() {
func test_logCommerceEvent_blocksEvent_whenFilterReturnsNil() {
dataPlanFilter.transformEventForCommerceEventParam = nil

mparticle.logCommerceEvent(commerceEvent)
Expand Down Expand Up @@ -55,7 +56,7 @@ final class MParticleCommerceEventTests: MParticleTestBase {
assertReceivedMessage("Blocked commerce event from kits", event: commerceEvent)
}

func testLogCommerceEventWithFilterReturningEvent_forwardsTransformedEvent() {
func test_logCommerceEvent_forwardsTransformedEvent_whenFilterReturnsEvent() {
dataPlanFilter.transformEventForCommerceEventReturnValue = transformedCommerceEvent

mparticle.logCommerceEvent(commerceEvent)
Expand Down Expand Up @@ -86,13 +87,13 @@ final class MParticleCommerceEventTests: MParticleTestBase {
XCTAssertTrue(kitContainer.forwardCommerceEventCallCommerceEventParam === transformedCommerceEvent)
}

func testLogCommerceEventCallbackSuccess() {
func test_logCommerceEventCallback_doesNotLogMessage_onSuccess() {
mparticle.logCommerceEventCallback(commerceEvent, execStatus: .success)

XCTAssertNil(receivedMessage)
}

func testLogCommerceEventCallbackFail() {
func test_logCommerceEventCallback_logsError_onFailure() {
mparticle.logCommerceEventCallback(commerceEvent, execStatus: .fail)

assertReceivedMessage("Failed to log commerce event", event: commerceEvent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import XCTest

final class MParticleConfigurationTests: MParticleTestBase {

func testStartWithKeyCallbackFirstRun() {
func test_start_initializesAndSetsFirstRunValues_whenFirstRun() {
XCTAssertFalse(mparticle.initialized)

mparticle.start(withKeyCallback: true, options: options, userDefaults: userDefaults)
Expand All @@ -28,7 +28,7 @@ final class MParticleConfigurationTests: MParticleTestBase {
XCTAssertTrue(userDefaults.synchronizeCalled)
}

func testStartWithKeyCallbackNotFirstRunWithIdentityRequest() {
func test_start_initializesWithoutUpdatingUserDefaults_whenNotFirstRun() {
let user = mparticle.identity.currentUser
options.identifyRequest = MPIdentityApiRequest(user: user!)

Expand All @@ -41,7 +41,7 @@ final class MParticleConfigurationTests: MParticleTestBase {
XCTAssertFalse(userDefaults.synchronizeCalled)
}

func testConfigureDefaultConfigurationExistOptionParametersAreNotSet() {
func test_configure_usesDefaultValues_whenNoSettingsExist() {
mparticle.backendController = MPBackendController_PRIVATE()
mparticle.configure(with: options)
XCTAssertEqual(mparticle.backendController.sessionTimeout, 0.0)
Expand All @@ -51,7 +51,7 @@ final class MParticleConfigurationTests: MParticleTestBase {
XCTAssertEqual(mparticle.trackNotifications, true)
}

func testConfigureWhenDefaultConfigurationExists() {
func test_configure_appliesSettings_whenConfigSettingsExist() {
let settings: NSMutableDictionary = [
"session_timeout": NSNumber(value: 2.0),
"upload_interval": NSNumber(value: 3.0),
Expand All @@ -74,7 +74,7 @@ final class MParticleConfigurationTests: MParticleTestBase {
XCTAssertEqual(mparticle.trackNotifications, false)
}

func testConfigureWithOptionsNoSettings() {
func test_configure_usesFallbackValues_whenOptionsAndSettingsAreEmpty() {
mparticle.configure(with: .init())
XCTAssertEqual(backendController.sessionTimeout, 0.0)
XCTAssertEqual(backendController.uploadInterval, 0.0)
Expand All @@ -88,7 +88,7 @@ final class MParticleConfigurationTests: MParticleTestBase {
#endif
}

func testConfigureWithOptionsWithSettingsAndOptionNotSet() {
func test_configure_appliesStoredSettings_whenOptionsNotSet() {
settingsProvider.configSettings = [
"session_timeout": 100,
"upload_interval": 50,
Expand Down Expand Up @@ -117,7 +117,7 @@ final class MParticleConfigurationTests: MParticleTestBase {
#endif
}

func testResetForSwitchingWorkspaces() {
func test_reset_clearsState_andFlushesKits() {
let expectation = XCTestExpectation()

mparticle.reset {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import XCTest

final class MParticleCustomEventTests: MParticleTestBase {

func testLogCustomEventWithNilEvent_logsError() {
func test_logCustomEvent_logsError_whenEventIsNil() {
mparticle.logCustomEvent(nil)
assertReceivedMessage("Cannot log nil event!")
}

func testLogCustomEventWithFilterReturningNil_blocksEvent() {
func test_logCustomEvent_blocksEvent_whenFilterReturnsNil() {
dataPlanFilter.transformEventReturnValue = nil

mparticle.logCustomEvent(event)
Expand Down Expand Up @@ -47,7 +47,7 @@ final class MParticleCustomEventTests: MParticleTestBase {
assertReceivedMessage("Blocked custom event from kits", event: event)
}

func testLogCustomEventWithFilterReturningEvent_forwardsTransformedEvent() {
func test_logCustomEvent_forwardsTransformedEvent_whenFilterReturnsEvent() {
dataPlanFilter.transformEventReturnValue = transformedEvent

mparticle.logCustomEvent(event)
Expand Down
14 changes: 7 additions & 7 deletions UnitTests/SwiftTests/MParticle/MParticleErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,42 @@ import XCTest

final class MParticleErrorTests: MParticleTestBase {

func testLogErrorCallbackSuccess() {
func test_logErrorCallback_logsMessage_whenSuccess() {
mparticle.logErrorCallback([:], execStatus: .success, message: "error")

assertReceivedMessage("Logged error with message: error")
}

func testLogErrorCallbackFail() {
func test_logErrorCallback_doesNotLog_whenFail() {
mparticle.logErrorCallback([:], execStatus: .fail, message: "error")

XCTAssertNil(receivedMessage)
}

func testLogExceptionCallbackSuccess() {
func test_logExceptionCallback_logsDetails_whenSuccess() {
mparticle.logExceptionCallback(exception, execStatus: .success, message: "exception", topmostContext: nil)

assertReceivedMessage("Logged exception name: exception, reason: Test, topmost context: (null)")
}

func testLogExceptionCallbackFail() {
func test_logExceptionCallback_doesNotLog_whenFail() {
mparticle.logExceptionCallback(exception, execStatus: .fail, message: "exception", topmostContext: nil)

XCTAssertNil(receivedMessage)
}

func testLogCrashCallbackSuccess() {
func test_logCrashCallback_logsMessage_whenSuccess() {
mparticle.logCrashCallback(.success, message: "Message")
assertReceivedMessage("Logged crash with message: Message")
}

func testLogNetworkPerformanceCallbackSuccess() {
func test_logNetworkPerformanceCallback_logsMessage_whenSuccess() {
mparticle.logNetworkPerformanceCallback(.success)

assertReceivedMessage("Logged network performance measurement")
}

func testLogNetworkPerformanceCallbackFail() {
func test_logNetworkPerformanceCallback_doesNotLog_whenFail() {
mparticle.logNetworkPerformanceCallback(.fail)

XCTAssertNil(receivedMessage)
Expand Down
12 changes: 6 additions & 6 deletions UnitTests/SwiftTests/MParticle/MParticleEventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ import XCTest

final class MParticleEventTests: MParticleTestBase {

func testLogEventCalledLogCustomEvent() {
func test_logEvent_callsLogCustomEvent() {
mparticle.logEvent(event)
wait(for: [listenerController.onAPICalledExpectation!], timeout: 0.1)
XCTAssertEqual(listenerController.onAPICalledApiName?.description, "logCustomEvent:")
}

func testLogEventCalledLogCommerceEvent() {
func test_logEvent_callsLogCommerceEvent() {
mparticle.logEvent(commerceEvent)
wait(for: [listenerController.onAPICalledExpectation!], timeout: 0.1)
XCTAssertEqual(listenerController.onAPICalledApiName?.description, "logCommerceEvent:")
}

func testLogEventWithFilterReturningNil_blocksEvent() {
func test_logEvent_blocksEvent_whenFilterReturnsNil() {
dataPlanFilter.transformEventForBaseEventReturnValue = nil

mparticle.logEvent(baseEvent)
Expand All @@ -53,7 +53,7 @@ final class MParticleEventTests: MParticleTestBase {
assertReceivedMessage("Blocked base event from kits", event: baseEvent)
}

func testLogBaseEventWithFilterReturningEvent_forwardsTransformedEvent() {
func test_logEvent_forwardsTransformedEvent_whenFilterReturnsEvent() {
dataPlanFilter.transformEventForBaseEventReturnValue = transformedBaseEvent

mparticle.logEvent(baseEvent)
Expand Down Expand Up @@ -84,15 +84,15 @@ final class MParticleEventTests: MParticleTestBase {
XCTAssertTrue(kitContainer.forwardSDKCallEventParam === transformedBaseEvent)
}

func testLogEventCallbackDataFilterNotSet() {
func test_logEventCallback_doesNotLogMessage_whenDataFilterIsNil() {
mparticle.dataPlanFilter = nil
XCTAssertNil(mparticle.dataPlanFilter)
mparticle.logEventCallback(event, execStatus: .success)

XCTAssertNil(receivedMessage)
}

func testLogEventCallbackDataFilterSetDataFilterReturnNil() {
func test_logEventCallback_blocksEvent_whenFilterReturnsNil() {
mparticle.logEventCallback(event, execStatus: .success)

XCTAssertTrue(dataPlanFilter.transformEventCalled)
Expand Down
4 changes: 2 additions & 2 deletions UnitTests/SwiftTests/MParticle/MParticleIdentityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import XCTest

final class MParticleIdentityTests: MParticleTestBase {

func testIdentifyNoDispatchCallbackNoErrorDefferedKitAvailable() {
func test_identifyNoDispatchCallback_clearsDeferredKit_whenNoError() {
mparticle.deferredKitConfiguration_PRIVATE = [[String: String]]()
let expectedApiResult = MPIdentityApiResult()
let expectation = XCTestExpectation()
Expand All @@ -33,7 +33,7 @@ final class MParticleIdentityTests: MParticleTestBase {
XCTAssertNil(mparticle.deferredKitConfiguration_PRIVATE)
}

func testIdentifyNoDispatchCallbackWithErrorDefferedKitAvailable() {
func test_identifyNoDispatchCallback_logsError_andClearsDeferredKit_whenErrorPresent() {
mparticle.deferredKitConfiguration_PRIVATE = [[String: String]]()
let expectedApiResult = MPIdentityApiResult()
let expectation = XCTestExpectation()
Expand Down
12 changes: 6 additions & 6 deletions UnitTests/SwiftTests/MParticle/MParticleKitBatchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import XCTest

final class MParticleKitBatchTests: MParticleTestBase {

func testLogKitBatch_withNilBatch_doesNotExecuteOrForward() {
func test_logKitBatch_doesNotExecute_whenBatchIsNil() {
mparticle.logKitBatch(nil)

assertReceivedMessage("Cannot log nil batch!")
Expand All @@ -25,7 +25,7 @@ final class MParticleKitBatchTests: MParticleTestBase {
XCTAssertFalse(persistenceController.saveCalled)
}

func testLogKitBatch_noBatchingKits_andKitsInitialized_doesNothing() {
func test_logKitBatch_doesNothing_whenNoBatchingKits_andKitsInitialized() {
kitContainer.kitsInitialized = true
kitContainer.hasKitBatchingKitsReturnValue = false

Expand All @@ -37,7 +37,7 @@ final class MParticleKitBatchTests: MParticleTestBase {
XCTAssertFalse(persistenceController.saveCalled)
}

func testLogKitBatch_kitsNotInitialized_defersWorkUntilInitialization() {
func test_logKitBatch_defersExecution_untilKitsInitialized() {
kitContainer.kitsInitialized = false
kitContainer.hasKitBatchingKitsReturnValue = true

Expand All @@ -62,7 +62,7 @@ final class MParticleKitBatchTests: MParticleTestBase {
XCTAssertNotNil(kitContainer.forwardSDKCallKitHandlerParam)
}

func testLogKitBatch_withBatchingKits_forwardsParsedBatch_andPersistsForwardRecords() {
func test_logKitBatch_forwardsParsedBatch_andPersistsRecords_whenBatchingKitsAvailable() {
kitContainer.kitsInitialized = true
kitContainer.hasKitBatchingKitsReturnValue = true

Expand All @@ -76,7 +76,7 @@ final class MParticleKitBatchTests: MParticleTestBase {
XCTAssertNotNil(kitContainer.forwardSDKCallKitHandlerParam)
}

func testLogKitBatch_invokesKitHandler_andPersistsForwardRecords() {
func test_logKitBatch_executesKitHandler_andPersistsForwardRecords() {
kitContainer.kitsInitialized = true
kitContainer.hasKitBatchingKitsReturnValue = true

Expand Down Expand Up @@ -107,7 +107,7 @@ final class MParticleKitBatchTests: MParticleTestBase {
XCTAssertTrue(persistenceController.saveForwardRecordParam === forwardRecord)
}

func testLogKitBatch_invalidJSON_stillForwardsWithNilBatch() {
func test_logKitBatch_forwardsWithNilBatch_whenJSONInvalid() {
kitContainer.kitsInitialized = true
kitContainer.hasKitBatchingKitsReturnValue = true

Expand Down
Loading
Loading