Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jotaemepereira committed May 23, 2024
1 parent 85aa59a commit 189df3c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class DataBrokerProtectionStatsPixelsUserDefaults: DataBrokerProtectionSta

private let userDefaults: UserDefaults

init(userDefaults: UserDefaults = .dbp) {
init(userDefaults: UserDefaults = .standard) {
self.userDefaults = userDefaults
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import Foundation

final class DataBrokerProtectionStatsPixelsTests: XCTestCase {

private let handler = MockDataBrokerProtectionPixelsHandler()

override func tearDown() {
handler.clear()
}

func testNumberOfNewMatchesIsCalculatedCorrectly() {
let historyEvents: [HistoryEvent] = [
.init(brokerId: 1, profileQueryId: 1, type: .matchesFound(count: 2)),
Expand All @@ -35,7 +41,7 @@ final class DataBrokerProtectionStatsPixelsTests: XCTestCase {
scanJobData: .mockWith(historyEvents: historyEvents),
optOutJobData: [.mock(with: .mockWithoutRemovedDate)])
let sut = DataBrokerProtectionStatsPixels(database: MockDatabase(),
handler: MockDataBrokerProtectionPixelsHandler(),
handler: handler,
repository: MockDataBrokerProtectionStatsPixelsRepository())

let result = sut.calculateNumberOfNewMatchesFound([brokerProfileQueryData])
Expand All @@ -60,7 +66,7 @@ final class DataBrokerProtectionStatsPixelsTests: XCTestCase {
scanJobData: .mockWith(historyEvents: historyEvents),
optOutJobData: [.mock(with: .mockWithoutRemovedDate)])
let sut = DataBrokerProtectionStatsPixels(database: MockDatabase(),
handler: MockDataBrokerProtectionPixelsHandler(),
handler: handler,
repository: MockDataBrokerProtectionStatsPixelsRepository())

let result = sut.calculateNumberOfNewMatchesFound([brokerProfileQueryData])
Expand All @@ -81,7 +87,7 @@ final class DataBrokerProtectionStatsPixelsTests: XCTestCase {
scanJobData: .mockWith(historyEvents: historyEventsForScan),
optOutJobData: [.mock(with: .mockWithoutRemovedDate, historyEvents: historyEventsForOptOut)])
let sut = DataBrokerProtectionStatsPixels(database: MockDatabase(),
handler: MockDataBrokerProtectionPixelsHandler(),
handler: handler,
repository: MockDataBrokerProtectionStatsPixelsRepository())

let result = sut.calculateDurationOfFirstOptOut([brokerProfileQueryData])
Expand All @@ -102,7 +108,7 @@ final class DataBrokerProtectionStatsPixelsTests: XCTestCase {
scanJobData: .mockWith(historyEvents: historyEventsForScan),
optOutJobData: [.mock(with: .mockWithoutRemovedDate, historyEvents: historyEventsForOptOut)])
let sut = DataBrokerProtectionStatsPixels(database: MockDatabase(),
handler: MockDataBrokerProtectionPixelsHandler(),
handler: handler,
repository: MockDataBrokerProtectionStatsPixelsRepository())

let result = sut.calculateDurationOfFirstOptOut([brokerProfileQueryData])
Expand All @@ -127,7 +133,7 @@ final class DataBrokerProtectionStatsPixelsTests: XCTestCase {
scanJobData: .mockWith(historyEvents: historyEventsForScan),
optOutJobData: [.mock(with: .mockWithoutRemovedDate, historyEvents: historyEventsForOptOut)])
let sut = DataBrokerProtectionStatsPixels(database: MockDatabase(),
handler: MockDataBrokerProtectionPixelsHandler(),
handler: handler,
repository: MockDataBrokerProtectionStatsPixelsRepository())

let result = sut.calculateDurationOfFirstOptOut([brokerProfileQueryData])
Expand Down Expand Up @@ -180,7 +186,7 @@ final class DataBrokerProtectionStatsPixelsTests: XCTestCase {
.mock(with: .mockWithRemovedDate, historyEvents: historyEventForOptOutWithSubmittedRequest),
])
let sut = DataBrokerProtectionStatsPixels(database: MockDatabase(),
handler: MockDataBrokerProtectionPixelsHandler(),
handler: handler,
repository: MockDataBrokerProtectionStatsPixelsRepository())

let result = sut.calculateByBroker(broker, data: [brokerProfileQueryData])
Expand Down Expand Up @@ -218,7 +224,7 @@ final class DataBrokerProtectionStatsPixelsTests: XCTestCase {
.mock(with: .mockWithoutRemovedDate, historyEvents: [HistoryEvent]())
])
let sut = DataBrokerProtectionStatsPixels(database: MockDatabase(),
handler: MockDataBrokerProtectionPixelsHandler(),
handler: handler,
repository: MockDataBrokerProtectionStatsPixelsRepository())

let result = sut.calculateByBroker(broker, data: [brokerProfileQueryData])
Expand All @@ -231,7 +237,7 @@ final class DataBrokerProtectionStatsPixelsTests: XCTestCase {
func testWhenDateOfFirstScanIsNil_thenWeDoNotFireAnyPixel() {
let repository = MockDataBrokerProtectionStatsPixelsRepository()
let sut = DataBrokerProtectionStatsPixels(database: MockDatabase(),
handler: MockDataBrokerProtectionPixelsHandler(),
handler: handler,
repository: repository)

sut.tryToFireStatsPixels()
Expand All @@ -251,7 +257,7 @@ final class DataBrokerProtectionStatsPixelsTests: XCTestCase {
]
let repository = MockDataBrokerProtectionStatsPixelsRepository()
let sut = DataBrokerProtectionStatsPixels(database: database,
handler: MockDataBrokerProtectionPixelsHandler(),
handler: handler,
repository: repository)

sut.tryToFireStatsPixels()
Expand All @@ -271,7 +277,7 @@ final class DataBrokerProtectionStatsPixelsTests: XCTestCase {
let repository = MockDataBrokerProtectionStatsPixelsRepository()
repository.latestStatsWeeklyPixelDate = Date().yesterday!
let sut = DataBrokerProtectionStatsPixels(database: database,
handler: MockDataBrokerProtectionPixelsHandler(),
handler: handler,
repository: repository)

sut.tryToFireStatsPixels()
Expand All @@ -292,7 +298,7 @@ final class DataBrokerProtectionStatsPixelsTests: XCTestCase {
let repository = MockDataBrokerProtectionStatsPixelsRepository()
repository.latestStatsWeeklyPixelDate = eightDaysAgo
let sut = DataBrokerProtectionStatsPixels(database: database,
handler: MockDataBrokerProtectionPixelsHandler(),
handler: handler,
repository: repository)

sut.tryToFireStatsPixels()
Expand All @@ -312,7 +318,7 @@ final class DataBrokerProtectionStatsPixelsTests: XCTestCase {
]
let repository = MockDataBrokerProtectionStatsPixelsRepository()
let sut = DataBrokerProtectionStatsPixels(database: database,
handler: MockDataBrokerProtectionPixelsHandler(),
handler: handler,
repository: repository)

sut.tryToFireStatsPixels()
Expand All @@ -333,7 +339,7 @@ final class DataBrokerProtectionStatsPixelsTests: XCTestCase {
let repository = MockDataBrokerProtectionStatsPixelsRepository()
repository.latestStatsMonthlyPixelDate = twentyDaysAgo
let sut = DataBrokerProtectionStatsPixels(database: database,
handler: MockDataBrokerProtectionPixelsHandler(),
handler: handler,
repository: repository)

sut.tryToFireStatsPixels()
Expand All @@ -354,7 +360,7 @@ final class DataBrokerProtectionStatsPixelsTests: XCTestCase {
let repository = MockDataBrokerProtectionStatsPixelsRepository()
repository.latestStatsMonthlyPixelDate = thirtyDaysAgo
let sut = DataBrokerProtectionStatsPixels(database: database,
handler: MockDataBrokerProtectionPixelsHandler(),
handler: handler,
repository: repository)

sut.tryToFireStatsPixels()
Expand Down

0 comments on commit 189df3c

Please sign in to comment.