11//
22// OccurrenceLogicTests.swift
3- //
3+ //
44//
55// Created by Yusuf Tör on 17/06/2022.
66//
77// swiftlint:disable all
88
99// ONLY TEST THIS MANUALLY, DON'T PUSH TO SERVER AS IT TAKES A LONG TIME:
1010/*
11- import XCTest
11+ import Testing
1212@testable import SuperwallKit
1313
1414@available(iOS 14.0, *)
15- class OccurrenceLogicTests: XCTestCase {
15+ class OccurrenceLogicTests {
1616 var coreDataManager: CoreDataManager!
1717 var coreDataStack: CoreDataStackMock!
1818 let eventName = "SuperwallEvent"
1919
20- override func setUp() {
21- super.setUp()
20+ init() {
2221 coreDataStack = CoreDataStackMock()
2322 coreDataManager = CoreDataManager(coreDataStack: coreDataStack)
2423 }
2524
26- override func tearDown() {
27- super.tearDown()
25+ deinit {
2826 coreDataStack.deleteAllEntities(named: "PlacementData")
2927 coreDataManager = nil
3028 coreDataStack = nil
3129 }
3230
33- func test_getCountsFromThousandsOfStoredEvents_notPreemptive () {
31+ @Test func getCountsFromThousandsOfStoredEvents_notPreemptive () {
3432 let fourMinsAgo: TimeInterval = -240
3533 let sessionDate = Date().advanced(by: fourMinsAgo)
3634 let appSession = AppSession(id: "abc", startAt: sessionDate)
@@ -44,24 +42,20 @@ class OccurrenceLogicTests: XCTestCase {
4442 arrayOfNames.append(randomString)
4543 }
4644
47- let expectation = expectation(description: "Saved Event")
48- expectation.expectedFulfillmentCount = arrayOfNames.count
4945/*
5046 let twoMinsAgo: TimeInterval = -120
5147 let firstEventDate = Date().advanced(by: twoMinsAgo)
5248 let firstPlacementData: PlacementData = .stub()
5349 .setting(\.name, to: eventName)
5450 .setting(\.createdAt, to: firstEventDate)
5551 coreDataManager.savePlacementData(firstPlacementData) { _ in
56- expectation.fulfill()
5752 }*/
5853 var percentage: Double = 1 / 2
5954 var total = 0
6055 for name in arrayOfNames {
6156 let count = Int(1000000 * percentage)
6257 total += count
6358 coreDataStack.batchInsertPlacementData(eventName: name, count: count) {
64- expectation.fulfill()
6559 }
6660 percentage = percentage / 2
6761 }
@@ -73,46 +67,31 @@ class OccurrenceLogicTests: XCTestCase {
7367 .setting(\.name, to: eventName)
7468 .setting(\.createdAt, to: lastEventDate)
7569 coreDataManager.savePlacementData(lastPlacementData) { _ in
76- expectation.fulfill()
7770 }*/
7871
79- waitForExpectations(timeout: 80.0) { error in
80- XCTAssertNil(error)
81- }
8272 print("************")
8373 var count: [String: Any] = [:]
84- let options = XCTMeasureOptions()
85- options.iterationCount = 1
86- measure(options: options) {
87- var eventOccurrences: [String: [String: Any]] = [:]
88- let eventNames = storage.coreDataManager.getAllEventNames()
89-
90- for eventName in eventNames {
91- eventOccurrences[eventName] = OccurrenceLogic.getEventOccurrences(
92- of: eventName,
93- isPreemptive: false,
94- storage: storage,
95- appSessionManager: appSessionManager
96- )
97- }
98- /*
99- count = OccurrenceLogic.getEventOccurrences(
100- of: arrayOfNames[0],
74+ var eventOccurrences: [String: [String: Any]] = [:]
75+ let eventNames = storage.coreDataManager.getAllEventNames()
76+
77+ for eventName in eventNames {
78+ eventOccurrences[eventName] = OccurrenceLogic.getEventOccurrences(
79+ of: eventName,
10180 isPreemptive: false,
10281 storage: storage,
10382 appSessionManager: appSessionManager
104- )*/
83+ )
10584 }
10685
10786 print("************")
108- XCTAssertEqual (count["$count_since_install"] as? Int, 11000)
109- XCTAssertEqual (count["$count_30d"] as? Int, 11000)
110- XCTAssertEqual (count["$count_7d"] as? Int, 11000)
111- XCTAssertEqual (count["$count_24h"] as? Int, 11000)
112- XCTAssertEqual (count["$count_session"] as? Int, 11000)
113- XCTAssertEqual (count["$count_today"] as? Int, 11000)
114- // XCTAssertEqual (count["$first_occurred_at"] as? String, firstPlacementData.createdAt.isoString)
115- // XCTAssertEqual (count["$last_occurred_at"] as? String, lastPlacementData.createdAt.isoString)
87+ #expect (count["$count_since_install"] as? Int == 11000)
88+ #expect (count["$count_30d"] as? Int == 11000)
89+ #expect (count["$count_7d"] as? Int == 11000)
90+ #expect (count["$count_24h"] as? Int == 11000)
91+ #expect (count["$count_session"] as? Int == 11000)
92+ #expect (count["$count_today"] as? Int == 11000)
93+ // #expect (count["$first_occurred_at"] as? String == firstPlacementData.createdAt.isoString)
94+ // #expect (count["$last_occurred_at"] as? String == lastPlacementData.createdAt.isoString)
11695 }
11796}
11897
@@ -123,7 +102,6 @@ class OccurrenceLogicTests: XCTestCase {
123102 Total:
124103 5M = 1.96s (avg. of ten: 1.9246s)
125104
126-
127105
128106
129107 Just firstOccurred:
0 commit comments