Skip to content

Commit

Permalink
Add event check on array
Browse files Browse the repository at this point in the history
  • Loading branch information
lmarceau committed Jan 21, 2025
1 parent 094c60b commit 9b51cc6
Showing 1 changed file with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class UnifiedAdsCallbackTelemetryTests: XCTestCase {
XCTAssertEqual(logger.savedMessage, "The unified ads telemetry call failed: \(tile.clickURL)")
}

func testLegacyImpressionTelemetry() {
func testLegacyImpressionTelemetry() throws {
let subject = createSubject()
subject.sendImpressionTelemetry(tile: tile, position: 1)

Expand All @@ -58,9 +58,26 @@ class UnifiedAdsCallbackTelemetryTests: XCTestCase {
}
XCTAssertEqual(asAnyHashable(savedPing), asAnyHashable(GleanMetrics.Pings.shared.topsitesImpression))
XCTAssertEqual(gleanWrapper.savedEvents?.count, 2)

// Ensuring we call the right metrics type
let firstSavedMetric = try XCTUnwrap(
gleanWrapper.savedEvents?[0] as? EventMetricType<GleanMetrics.TopSites.ContileImpressionExtra>
)
let expectedFirstMetricType = type(of: GleanMetrics.TopSites.contileImpression)
let firstResultMetricType = type(of: firstSavedMetric)
let debugMessage = TelemetryDebugMessage(expectedMetric: expectedFirstMetricType,
resultMetric: firstResultMetricType)
XCTAssert(firstResultMetricType == expectedFirstMetricType, debugMessage.text)

let secondSavedMetric = try XCTUnwrap(gleanWrapper.savedEvents?[1] as? StringMetricType)
let expectedSecondMetricType = type(of: GleanMetrics.TopSites.contileAdvertiser)
let secondResultMetricType = type(of: secondSavedMetric)
let secondDebugMessage = TelemetryDebugMessage(expectedMetric: expectedSecondMetricType,
resultMetric: secondResultMetricType)
XCTAssert(secondResultMetricType == expectedSecondMetricType, secondDebugMessage.text)
}

func testLegacyClickTelemetry() {
func testLegacyClickTelemetry() throws {
let subject = createSubject()
subject.sendClickTelemetry(tile: tile, position: 1)

Expand All @@ -75,6 +92,23 @@ class UnifiedAdsCallbackTelemetryTests: XCTestCase {
}
XCTAssertEqual(asAnyHashable(savedPing), asAnyHashable(GleanMetrics.Pings.shared.topsitesImpression))
XCTAssertEqual(gleanWrapper.savedEvents?.count, 2)

// Ensuring we call the right metrics type
let firstSavedMetric = try XCTUnwrap(
gleanWrapper.savedEvents?[0] as? EventMetricType<GleanMetrics.TopSites.ContileClickExtra>
)
let expectedFirstMetricType = type(of: GleanMetrics.TopSites.contileClick)
let firstResultMetricType = type(of: firstSavedMetric)
let debugMessage = TelemetryDebugMessage(expectedMetric: expectedFirstMetricType,
resultMetric: firstResultMetricType)
XCTAssert(firstResultMetricType == expectedFirstMetricType, debugMessage.text)

let secondSavedMetric = try XCTUnwrap(gleanWrapper.savedEvents?[1] as? StringMetricType)
let expectedSecondMetricType = type(of: GleanMetrics.TopSites.contileAdvertiser)
let secondResultMetricType = type(of: secondSavedMetric)
let secondDebugMessage = TelemetryDebugMessage(expectedMetric: expectedSecondMetricType,
resultMetric: secondResultMetricType)
XCTAssert(secondResultMetricType == expectedSecondMetricType, secondDebugMessage.text)
}

// MARK: - Helper functions
Expand Down

0 comments on commit 9b51cc6

Please sign in to comment.