From 4bd9e47d7f97ffe5423c0f3606f4ce3477fd26f4 Mon Sep 17 00:00:00 2001 From: Maurice Carrier Date: Thu, 5 Sep 2024 13:56:34 -0400 Subject: [PATCH] Revert "Restore playback tracker plus unit tests" This reverts commit 85468a70a9aa9b1b3158d6510e9a6805cad67595. --- Palace.xcodeproj/project.pbxproj | 19 +- .../Tracker/AudiobookTimeTracker.swift | 4 +- .../UI/TPPBookCellDelegate+Extensions.swift | 11 +- PalaceTests/AudiobookTrackerTests.swift | 206 ------------------ 4 files changed, 13 insertions(+), 227 deletions(-) delete mode 100644 PalaceTests/AudiobookTrackerTests.swift diff --git a/Palace.xcodeproj/project.pbxproj b/Palace.xcodeproj/project.pbxproj index 438f9f9eb..08df0c85a 100644 --- a/Palace.xcodeproj/project.pbxproj +++ b/Palace.xcodeproj/project.pbxproj @@ -1075,7 +1075,6 @@ E544C4F02A395E8C00B2DC9D /* MyBooksSimplifiedBearerToken.swift in Sources */ = {isa = PBXBuildFile; fileRef = E544C4EE2A395E8C00B2DC9D /* MyBooksSimplifiedBearerToken.swift */; }; E544C4F72A3C1E4A00B2DC9D /* Dictionary+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E544C4F62A3C1E4A00B2DC9D /* Dictionary+Extensions.swift */; }; E544C4F82A3C1E4A00B2DC9D /* Dictionary+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E544C4F62A3C1E4A00B2DC9D /* Dictionary+Extensions.swift */; }; - E544E7142C8A14D400802EB9 /* AudiobookTrackerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E544E7132C8A14D400802EB9 /* AudiobookTrackerTests.swift */; }; E549954828EE1AAA00EA0D9B /* TransifexManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = E549954728EE1AAA00EA0D9B /* TransifexManager.swift */; }; E549955228EE1ADB00EA0D9B /* TXNativeExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E549955128EE1ADB00EA0D9B /* TXNativeExtensions.swift */; }; E54DD4D5275C7C940013C200 /* View+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E54DD4D4275C7C940013C200 /* View+Extensions.swift */; }; @@ -1993,7 +1992,6 @@ E544C4EB2A395DDE00B2DC9D /* MyBooksDownloadInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyBooksDownloadInfo.swift; sourceTree = ""; }; E544C4EE2A395E8C00B2DC9D /* MyBooksSimplifiedBearerToken.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyBooksSimplifiedBearerToken.swift; sourceTree = ""; }; E544C4F62A3C1E4A00B2DC9D /* Dictionary+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Dictionary+Extensions.swift"; sourceTree = ""; }; - E544E7132C8A14D400802EB9 /* AudiobookTrackerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudiobookTrackerTests.swift; sourceTree = ""; }; E549954728EE1AAA00EA0D9B /* TransifexManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransifexManager.swift; sourceTree = ""; }; E549955128EE1ADB00EA0D9B /* TXNativeExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TXNativeExtensions.swift; sourceTree = ""; }; E54DD4C6275C60E70013C200 /* UIViewControllerWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewControllerWrapper.swift; sourceTree = ""; }; @@ -3412,7 +3410,6 @@ E5F8A57C28A48B8300A229AE /* BookPreviewTests.swift */, E534510429FA238500D88BC6 /* AudiobookmarkTests.swift */, E5024A8E2A0EB9D6006BF653 /* AudiobookBookmarkBusinessLogicTests.swift */, - E544E7132C8A14D400802EB9 /* AudiobookTrackerTests.swift */, ); path = PalaceTests; sourceTree = ""; @@ -4354,7 +4351,6 @@ 730D17C02552124B004CAC83 /* TPPMyBooksDownloadsCenterMock.swift in Sources */, 735F41A3243E381D00046182 /* String+NYPLAdditionsTests.swift in Sources */, 17BE24E725FABCDE00AE707F /* TPPUserAccountProviderMock.swift in Sources */, - E544E7142C8A14D400802EB9 /* AudiobookTrackerTests.swift in Sources */, E5037FE729A3FF84002DA132 /* ButtonStateTests.swift in Sources */, 7311FD2B25CBD086004447CB /* TPPSignInOutBusinessLogicUIDelegateMock.swift in Sources */, 173F0823241AAA4E00A64658 /* TPPBookStateTests.swift in Sources */, @@ -5909,9 +5905,11 @@ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES_ERROR; CODE_SIGN_ENTITLEMENTS = Palace/PalaceDebug.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; - CODE_SIGN_STYLE = Automatic; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; + CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 286; - DEVELOPMENT_TEAM = 88CBA74T8K; + DEVELOPMENT_TEAM = ""; + "DEVELOPMENT_TEAM[sdk=iphoneos*]" = 88CBA74T8K; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -5938,7 +5936,8 @@ ); MARKETING_VERSION = 1.1.0; PRODUCT_BUNDLE_IDENTIFIER = org.thepalaceproject.palace; - PROVISIONING_PROFILE_SPECIFIER = ""; + PROVISIONING_PROFILE_SPECIFIER = "Ad Hoc 2"; + "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "Ad Hoc 2"; RUN_CLANG_STATIC_ANALYZER = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG SIMPLYE FEATURE_DRM_CONNECTOR FEATURE_CRASH_REPORTING LCP FEATURE_OVERDRIVE"; SWIFT_OBJC_BRIDGING_HEADER = "Palace/AppInfrastructure/Palace-Bridging-Header.h"; @@ -6154,11 +6153,13 @@ CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_IDENTITY = "Apple Development"; - CODE_SIGN_STYLE = Automatic; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; + CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = dwarf; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = 88CBA74T8K; + DEVELOPMENT_TEAM = ""; + "DEVELOPMENT_TEAM[sdk=iphoneos*]" = 88CBA74T8K; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; diff --git a/Palace/Audiobooks/Tracker/AudiobookTimeTracker.swift b/Palace/Audiobooks/Tracker/AudiobookTimeTracker.swift index 12eb1ecea..d60eaab4d 100644 --- a/Palace/Audiobooks/Tracker/AudiobookTimeTracker.swift +++ b/Palace/Audiobooks/Tracker/AudiobookTimeTracker.swift @@ -65,17 +65,15 @@ class AudiobookTimeTracker: NSObject, AudiobookPlaybackTrackerDelegate { func receiveValue(_ value: Date) { duration += tick let minute = minuteFormatter.string(from: value) - if minute != currentMinute { saveCurrentDuration(date: value) currentMinute = minute - duration = 0 } } private func saveCurrentDuration(date: Date = Date()) { if duration > 0 { - timeEntryId = ULID(timestamp: date) + timeEntryId = ULID(timestamp: date) // timeEntryId value updates once every minute dataManager.save(time: timeEntry) duration = 0 } diff --git a/Palace/Book/UI/TPPBookCellDelegate+Extensions.swift b/Palace/Book/UI/TPPBookCellDelegate+Extensions.swift index 77982e339..acc0c2ccf 100644 --- a/Palace/Book/UI/TPPBookCellDelegate+Extensions.swift +++ b/Palace/Book/UI/TPPBookCellDelegate+Extensions.swift @@ -75,19 +75,12 @@ extension TPPBookCellDelegate { return } - var timeTracker: AudiobookTimeTracker? - if let libraryId = AccountsManager.shared.currentAccount?.uuid, let timeTrackingURL = book.timeTrackingURL { - timeTracker = AudiobookTimeTracker(libraryId: libraryId, bookId: book.identifier, timeTrackingUrl: timeTrackingURL) - } - let metadata = AudiobookMetadata(title: book.title, authors: [book.authors ?? ""]) let audiobookManager = DefaultAudiobookManager( metadata: metadata, audiobook: audiobook, - networkService: DefaultAudiobookNetworkService(tracks: audiobook.tableOfContents.allTracks), - playbackTrackerDelegate: timeTracker - ) - + networkService: DefaultAudiobookNetworkService(tracks: audiobook.tableOfContents.allTracks)) + self.audiobookBookmarkBusinessLogic = AudiobookBookmarkBusinessLogic(book: book) audiobookManager.bookmarkDelegate = self.audiobookBookmarkBusinessLogic diff --git a/PalaceTests/AudiobookTrackerTests.swift b/PalaceTests/AudiobookTrackerTests.swift deleted file mode 100644 index 4518b8274..000000000 --- a/PalaceTests/AudiobookTrackerTests.swift +++ /dev/null @@ -1,206 +0,0 @@ -// -// AudiobookTrackerTests.swift -// PalaceTests -// -// Created by Maurice Carrier on 9/5/24. -// Copyright © 2024 The Palace Project. All rights reserved. -// - -import XCTest -import Combine -@testable import Palace - -class MockDataManager: DataManager { - - var savedTimeEntries: [TimeEntry] = [] - - func save(time: TimeEntry) { - savedTimeEntries.append(time) - } - - func removeSynchronizedEntries(ids: [String]) { - savedTimeEntries.removeAll { ids.contains($0.id) } - } - - func saveStore() { - } - - func loadStore() { - } - - func cleanUpUrls() { - } - - func syncValues() { - } -} - -class AudiobookTimeTrackerTests: XCTestCase { - - var sut: AudiobookTimeTracker! - var mockDataManager: MockDataManager! - var currentDate: Date! - - override func setUp() { - super.setUp() - mockDataManager = MockDataManager() - currentDate = Date() - sut = AudiobookTimeTracker( - libraryId: "library123", - bookId: "book123", - timeTrackingUrl: URL(string: "https://example.com")!, - dataManager: mockDataManager - ) - } - - override func tearDown() { - sut = nil - mockDataManager = nil - currentDate = nil - super.tearDown() - } - - func testPlaybackStarted_savesCorrectAggregateTime() { - let expectation = self.expectation(description: "Aggregate time saved") - - for i in 0..<90 { - let simulatedDate = Calendar.current.date(byAdding: .second, value: i, to: currentDate)! - sut.receiveValue(simulatedDate) - } - - sut = nil - - DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { - let totalTimeSaved = self.mockDataManager.savedTimeEntries.reduce(0) { $0 + $1.duration } - XCTAssertEqual(totalTimeSaved, 90, "Total time saved should be 90 seconds") - expectation.fulfill() - } - - wait(for: [expectation], timeout: 3.0) - } - - func testTimeEntries_areLimitedTo60Seconds() { - let expectation = self.expectation(description: "Limit time entry duration to 60 seconds") - - for i in 0..<70 { - let simulatedDate = Calendar.current.date(byAdding: .second, value: i, to: currentDate)! - sut.receiveValue(simulatedDate) - } - - sut = nil - - DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { - XCTAssertGreaterThanOrEqual(self.mockDataManager.savedTimeEntries.count, 2, "There should be at least 2 entries since the playback spanned 2 minutes.") - - XCTAssertLessThanOrEqual(self.mockDataManager.savedTimeEntries.first!.duration, 60, "First entry should be less than or equal to 60 seconds") - XCTAssertLessThanOrEqual(self.mockDataManager.savedTimeEntries.last!.duration, 60, "Last entry should be less than or equal to 60 seconds") - - let total = self.mockDataManager.savedTimeEntries.reduce(0) { $0 + $1.duration } - - XCTAssertEqual(total, 70, "Total should equal 70 seconds") - - expectation.fulfill() - } - - wait(for: [expectation], timeout: 5.0) - } - - - - func testTimeEntries_areInUTC() { - // Arrange - let expectation = self.expectation(description: "Time entries should be in UTC") - - // Simulate 60 seconds of playback - for i in 0..<60 { - let simulatedDate = Calendar.current.date(byAdding: .second, value: i, to: currentDate)! - sut.receiveValue(simulatedDate) - } - - // Assert that the time entry is recorded in UTC - DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { - let firstEntry = self.mockDataManager.savedTimeEntries.first - XCTAssertNotNil(firstEntry, "Time entry should exist") - XCTAssertTrue(firstEntry?.duringMinute.hasSuffix("Z") ?? false, "Time entry should be in UTC format") - expectation.fulfill() - } - - wait(for: [expectation], timeout: 3.0) - } - - func testPlaybackStopped_stopsTimer() { - // Arrange - sut.playbackStarted() - let expectation = self.expectation(description: "Timer stopped") - - // Act - DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { - self.sut.playbackStopped() - let previousDuration = self.sut.timeEntry.duration - - // After another second, ensure duration has not increased - DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { - XCTAssertEqual(self.sut.timeEntry.duration, previousDuration) - expectation.fulfill() - } - } - - // Assert - wait(for: [expectation], timeout: 10.0) - } - - func testSaveCurrentDuration_savesTimeEntryCorrectly() { - sut.playbackStarted() - let expectation = self.expectation(description: "Saved Time entry Correctly") - - for i in 0..<59 { - let simulatedDate = Calendar.current.date(byAdding: .second, value: i, to: currentDate)! - sut.receiveValue(simulatedDate) - } - - sut = nil - - DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { - - XCTAssertLessThanOrEqual(self.mockDataManager.savedTimeEntries.count, 2, "There should be less than or equal to 2 entries.") - let total = self.mockDataManager.savedTimeEntries.reduce(0) { $0 + $1.duration } - - XCTAssertEqual(total, 60, "Total should be less than or equal to 60") - - XCTAssertEqual(self.mockDataManager.savedTimeEntries.first?.bookId, "book123") - XCTAssertEqual(self.mockDataManager.savedTimeEntries.first?.libraryId, "library123") - expectation.fulfill() - } - - wait(for: [expectation], timeout: 3.0) - } - - func testNoPlayback_savesNoTimeEntry() { - sut.playbackStarted() - sut.playbackStopped() - - XCTAssertEqual(mockDataManager.savedTimeEntries.count, 0, "No time entries should be saved without playback") - } - - func testExactMinuteOfPlayback_savesCorrectTimeEntry() { - sut.playbackStarted() - let expectation = self.expectation(description: "Saved Time entry Correctly") - - for i in 0..<59 { - let simulatedDate = Calendar.current.date(byAdding: .second, value: i, to: currentDate)! - sut.receiveValue(simulatedDate) - } - - sut = nil - - DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { - let total = self.mockDataManager.savedTimeEntries.reduce(0) { $0 + $1.duration } - - XCTAssertLessThanOrEqual(self.mockDataManager.savedTimeEntries.count, 2, "There should be less than or equal to 2 entries.") - XCTAssertEqual(total, 60, "Time entry should be for 60 seconds") - expectation.fulfill() - } - - wait(for: [expectation], timeout: 3.0) - } -}