Skip to content

Commit

Permalink
feat: provider tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bigearsenal committed Jul 28, 2023
1 parent 2b0f6d6 commit 52ec34c
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,114 @@ import XCTest
@testable import AnalyticsManager

class EventsTest: XCTestCase {
// func testEventWithNoParams() throws {
// let event = AnalyticsEvent.backingUpCopying
// XCTAssertEqual(event.eventName, "Backing_Up_Copying")
// XCTAssertTrue(event.params == nil)
// }
//
// func testEventWithParams() throws {
// let event = AnalyticsEvent.swapSwapClick(tokenA: "USDC", tokenB: "SOL", sumA: 100, sumB: 1)
// XCTAssertEqual(event.eventName, "Swap_Swap_Click")
// XCTAssertEqual(event.params?["tokenA"] as! String, "USDC")
// XCTAssertEqual(event.params?["tokenB"] as! String, "SOL")
// XCTAssertEqual(event.params?["sumA"] as! Double, 100.0)
// XCTAssertEqual(event.params?["sumB"] as! Double, 1.0)
// }
func testKeyAppAnalytics_NormalEventsNameAndParams_ShouldReturnStandardNameAndParams() throws {
// Test case for createPhoneClickButton
let createPhoneClickButtonEvent = KeyAppAnalyticsEvent.createPhoneClickButton
XCTAssertEqual(createPhoneClickButtonEvent.name, "Create_Phone_Click_Button")
XCTAssertNil(createPhoneClickButtonEvent.params)

// Test case for restorePhoneClickButton
let restorePhoneClickButtonEvent = KeyAppAnalyticsEvent.restorePhoneClickButton
XCTAssertEqual(restorePhoneClickButtonEvent.name, "Restore_Phone_Click_Button")
XCTAssertNil(restorePhoneClickButtonEvent.params)

// Test case for restoreSmsValidation
let result = true // Replace this with the actual result you want to test
let restoreSmsValidationEvent = KeyAppAnalyticsEvent.restoreSmsValidation(result: result)
XCTAssertEqual(restoreSmsValidationEvent.name, "Restore_Sms_Validation")
XCTAssertEqual(restoreSmsValidationEvent.params?["Result"] as! Bool, result)

// Test cases for Setup events
let fromPage = "ExamplePage" // Replace this with the actual fromPage value you want to test for setupOpen
let setupOpenEvent = KeyAppAnalyticsEvent.setupOpen(fromPage: fromPage)
XCTAssertEqual(setupOpenEvent.name, "Setup_Open")
XCTAssertEqual(setupOpenEvent.params?["From_Page"] as! String, fromPage)

let path =
"ExamplePath" // Replace this with the actual path value you want to test for
// recoveryDerivableAccountsPathSelected
let recoveryDerivableAccountsPathSelectedEvent = KeyAppAnalyticsEvent
.recoveryDerivableAccountsPathSelected(path: path)
XCTAssertEqual(recoveryDerivableAccountsPathSelectedEvent.name, "Recovery_Derivable_Accounts_Path_Selected")
XCTAssertEqual(recoveryDerivableAccountsPathSelectedEvent.params?["Path"] as! String, path)

let recoveryRestoreClickEvent = KeyAppAnalyticsEvent.recoveryRestoreClick
XCTAssertEqual(recoveryRestoreClickEvent.name, "Recovery_Restore_Click")
XCTAssertNil(recoveryRestoreClickEvent.params)

let recoveryDerivableAccountsOpenEvent = KeyAppAnalyticsEvent.recoveryDerivableAccountsOpen
XCTAssertEqual(recoveryDerivableAccountsOpenEvent.name, "Recovery_Derivable_Accounts_Open")
XCTAssertNil(recoveryDerivableAccountsOpenEvent.params)

// Test cases for Main section - User Balance
let amountUsd =
100.0 // Replace this with the actual amount in USD you want to test for userAggregateBalanceBase
let currency = "USD" // Replace this with the actual currency you want to test for userAggregateBalanceBase
let userAggregateBalanceBaseEvent = KeyAppAnalyticsEvent.userAggregateBalanceBase(
amountUsd: amountUsd,
currency: currency
)
XCTAssertEqual(userAggregateBalanceBaseEvent.name, "User_Aggregate_Balance_Base")
XCTAssertEqual(userAggregateBalanceBaseEvent.params?["Amount_Usd"] as! Double, amountUsd)
XCTAssertEqual(userAggregateBalanceBaseEvent.params?["Currency"] as! String, currency)
}

func testKeyAppAnalytics_SpecialEventsNameAndParams_ShouldReturnModifiedNameAndParams() throws {
// Test cases for Swap events
let sellOnlySOLNotificationEvent = KeyAppAnalyticsEvent.sellOnlySOLNotification
XCTAssertEqual(sellOnlySOLNotificationEvent.name, "Sell_Only_SOL_Notification")
XCTAssertNil(sellOnlySOLNotificationEvent.params)

let tokenAName =
"TokenA" // Replace this with the actual token A name you want to test for swapChangingTokenAClick
let swapChangingTokenAClickEvent = KeyAppAnalyticsEvent.swapChangingTokenAClick(tokenAName: tokenAName)
XCTAssertEqual(swapChangingTokenAClickEvent.name, "Swap_Changing_Token_A_Click")
XCTAssertEqual(swapChangingTokenAClickEvent.params?["Token_A_Name"] as! String, tokenAName)

let tokenBName =
"TokenB" // Replace this with the actual token B name you want to test for swapChangingTokenBClick
let swapChangingTokenBClickEvent = KeyAppAnalyticsEvent.swapChangingTokenBClick(tokenBName: tokenBName)
XCTAssertEqual(swapChangingTokenBClickEvent.name, "Swap_Changing_Token_B_Click")
XCTAssertEqual(swapChangingTokenBClickEvent.params?["Token_B_Name"] as! String, tokenBName)

let swapErrorTokenAInsufficientAmountEvent = KeyAppAnalyticsEvent.swapErrorTokenAInsufficientAmount
XCTAssertEqual(swapErrorTokenAInsufficientAmountEvent.name, "Swap_Error_Token_A_Insufficient_Amount")
XCTAssertNil(swapErrorTokenAInsufficientAmountEvent.params)

let swapChangingValueTokenAAllEvent = KeyAppAnalyticsEvent.swapChangingValueTokenAAll(
tokenAName: tokenAName,
tokenAValue: 100.0
)
XCTAssertEqual(swapChangingValueTokenAAllEvent.name, "Swap_Changing_Value_Token_A_All")
XCTAssertEqual(swapChangingValueTokenAAllEvent.params?["Token_A_Name"] as! String, tokenAName)
XCTAssertEqual(swapChangingValueTokenAAllEvent.params?["Token_A_Value"] as! Double, 100.0)

let swapChangingValueTokenAEvent = KeyAppAnalyticsEvent.swapChangingValueTokenA(
tokenAName: tokenAName,
tokenAValue: 50.0
)
XCTAssertEqual(swapChangingValueTokenAEvent.name, "Swap_Changing_Value_Token_A")
XCTAssertEqual(swapChangingValueTokenAEvent.params?["Token_A_Name"] as! String, tokenAName)
XCTAssertEqual(swapChangingValueTokenAEvent.params?["Token_A_Value"] as! Double, 50.0)

let swapChangingValueTokenBEvent = KeyAppAnalyticsEvent.swapChangingValueTokenB(
tokenBName: tokenBName,
tokenBValue: 200.0,
transactionSimulation: true
)
XCTAssertEqual(swapChangingValueTokenBEvent.name, "Swap_Changing_Value_Token_B")
XCTAssertEqual(swapChangingValueTokenBEvent.params?["Token_B_Name"] as! String, tokenBName)
XCTAssertEqual(swapChangingValueTokenBEvent.params?["Token_B_Value"] as! Double, 200.0)
XCTAssertEqual(swapChangingValueTokenBEvent.params?["Transaction_Simulation"] as! Bool, true)

let swapSwitchTokensEvent = KeyAppAnalyticsEvent.swapSwitchTokens(
tokenAName: tokenAName,
tokenBName: tokenBName
)
XCTAssertEqual(swapSwitchTokensEvent.name, "Swap_Switch_Tokens")
XCTAssertEqual(swapSwitchTokensEvent.params?["Token_A_Name"] as! String, tokenAName)
XCTAssertEqual(swapSwitchTokensEvent.params?["Token_B_Name"] as! String, tokenBName)

// ... Test cases for User Balance and other remaining events (if applicable) ...
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import Foundation
import XCTest
@testable import AnalyticsManager

class ProvidersTests: XCTestCase {
func testKeyAppAnalytics_GiveDefaultEvents_ShouldReturnAmplitudeProviderId() {
// Test case for events with only the default provider (Amplitude)
let eventsWithDefaultProvider: [KeyAppAnalyticsEvent] = [
.createPhoneClickButton,
.restorePhoneClickButton,
]
let defaultProviderIds: Set<String> = [KeyAppAnalyticsProviderId.amplitude.rawValue]
let defaultProviderIdsResult = eventsWithDefaultProvider.flatMap(\.providerIds)
XCTAssertEqual(Set(defaultProviderIdsResult), defaultProviderIds)
}

func testKeyAppAnalytics_GiveSpecialEvents_ShouldReturnAdditionalProviderIds() {
// Test case for events with additional providers (AppsFlyer and Firebase Analytics)
let eventsWithAdditionalProviders: [KeyAppAnalyticsEvent] = [
.onboardingStartButton,
.creationPhoneScreen,
.createSmsValidation(result: true),
.createConfirmPin(result: true),
.usernameCreationScreen,
.usernameCreationButton(result: true),
.restoreSeed,
.onboardingMerged,
.login,
.buyButtonPressed(
sumCurrency: "",
sumCoin: "",
currency: "",
coin: "",
paymentMethod: "",
bankTransfer: true,
typeBankTransfer: ""
),
.sendNewConfirmButtonClick(
sendFlow: "",
token: "",
max: true,
amountToken: 0,
amountUSD: 0,
fee: true,
fiatInput: true,
signature: "",
pubKey: ""
),
.swapClickApproveButton,
]
let additionalProviderIds: Set<String> = [
KeyAppAnalyticsProviderId.amplitude.rawValue,
KeyAppAnalyticsProviderId.appsFlyer.rawValue,
KeyAppAnalyticsProviderId.firebaseAnalytics.rawValue,
]
let additionalProviderIdsResult = eventsWithAdditionalProviders.flatMap(\.providerIds)
XCTAssertEqual(Set(additionalProviderIdsResult), additionalProviderIds)
}
}

0 comments on commit 52ec34c

Please sign in to comment.