From ea6b1edd3d7eb7ea51526395f810dc138ea85c9f Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Wed, 26 Aug 2020 14:35:06 -0700 Subject: [PATCH] Renaming --- Development Assets/DevelopmentModels.swift | 15 ++++++++------- Metatext.xcodeproj/project.pbxproj | 12 ++++++------ Shared/MetatextApp.swift | 6 +++--- ...sService.swift => AllIdentitiesService.swift} | 4 ++-- Shared/View Models/AddIdentityViewModel.swift | 12 ++++++------ Shared/View Models/RootViewModel.swift | 16 ++++++++-------- .../View Models/AddIdentityViewModelTests.swift | 14 ++++++++------ Tests/View Models/RootViewModelTests.swift | 2 +- 8 files changed, 42 insertions(+), 39 deletions(-) rename Shared/Services/{IdentitiesService.swift => AllIdentitiesService.swift} (98%) diff --git a/Development Assets/DevelopmentModels.swift b/Development Assets/DevelopmentModels.swift index 52eaf94..5193a57 100644 --- a/Development Assets/DevelopmentModels.swift +++ b/Development Assets/DevelopmentModels.swift @@ -52,23 +52,23 @@ extension AppEnvironment { inMemoryContent: true) } -extension IdentitiesService { +extension AllIdentitiesService { static func fresh( identityDatabase: IdentityDatabase = .fresh(), keychainService: KeychainService = MockKeychainService(), - environment: AppEnvironment = .development) -> IdentitiesService { - IdentitiesService( + environment: AppEnvironment = .development) -> AllIdentitiesService { + AllIdentitiesService( identityDatabase: identityDatabase, environment: environment) } - static let development = IdentitiesService( + static let development = AllIdentitiesService( identityDatabase: .development, environment: .development) } extension IdentityService { - static let development = try! IdentitiesService.development.identityService(id: devIdentityID) + static let development = try! AllIdentitiesService.development.identityService(id: devIdentityID) } extension UserNotificationService { @@ -78,7 +78,7 @@ extension UserNotificationService { extension RootViewModel { static let development = RootViewModel( appDelegate: AppDelegate(), - identitiesService: .development, + allIdentitiesService: .development, userNotificationService: .development) } @@ -113,7 +113,8 @@ extension NotificationTypesPreferencesViewModel { } extension StatusListViewModel { - static let development = StatusListViewModel(statusListService: IdentityService.development.service(timeline: .home)) + static let development = StatusListViewModel( + statusListService: IdentityService.development.service(timeline: .home)) } // swiftlint:enable force_try diff --git a/Metatext.xcodeproj/project.pbxproj b/Metatext.xcodeproj/project.pbxproj index e9434e3..886c1d7 100644 --- a/Metatext.xcodeproj/project.pbxproj +++ b/Metatext.xcodeproj/project.pbxproj @@ -213,8 +213,8 @@ D0EC8DC624DF842700A08489 /* KeychainService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DC424DF842700A08489 /* KeychainService.swift */; }; D0EC8DC824DF8B3C00A08489 /* SecretsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DC724DF8B3C00A08489 /* SecretsService.swift */; }; D0EC8DC924DF8B3C00A08489 /* SecretsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DC724DF8B3C00A08489 /* SecretsService.swift */; }; - D0EC8DCB24DFA06700A08489 /* IdentitiesService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DCA24DFA06700A08489 /* IdentitiesService.swift */; }; - D0EC8DCC24DFA06700A08489 /* IdentitiesService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DCA24DFA06700A08489 /* IdentitiesService.swift */; }; + D0EC8DCB24DFA06700A08489 /* AllIdentitiesService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DCA24DFA06700A08489 /* AllIdentitiesService.swift */; }; + D0EC8DCC24DFA06700A08489 /* AllIdentitiesService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DCA24DFA06700A08489 /* AllIdentitiesService.swift */; }; D0EC8DCE24DFB64200A08489 /* AuthenticationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DCD24DFB64200A08489 /* AuthenticationService.swift */; }; D0EC8DCF24DFB64200A08489 /* AuthenticationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DCD24DFB64200A08489 /* AuthenticationService.swift */; }; D0EC8DD424DFE38900A08489 /* AuthenticationServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC8DD324DFE38900A08489 /* AuthenticationServiceTests.swift */; }; @@ -394,7 +394,7 @@ D0EC8DC124DF7D9C00A08489 /* IdentityService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IdentityService.swift; sourceTree = ""; }; D0EC8DC424DF842700A08489 /* KeychainService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainService.swift; sourceTree = ""; }; D0EC8DC724DF8B3C00A08489 /* SecretsService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecretsService.swift; sourceTree = ""; }; - D0EC8DCA24DFA06700A08489 /* IdentitiesService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentitiesService.swift; sourceTree = ""; }; + D0EC8DCA24DFA06700A08489 /* AllIdentitiesService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllIdentitiesService.swift; sourceTree = ""; }; D0EC8DCD24DFB64200A08489 /* AuthenticationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationService.swift; sourceTree = ""; }; D0EC8DD324DFE38900A08489 /* AuthenticationServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationServiceTests.swift; sourceTree = ""; }; D0EC8DD724E096C900A08489 /* UserNotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserNotificationService.swift; sourceTree = ""; }; @@ -533,7 +533,7 @@ isa = PBXGroup; children = ( D0EC8DCD24DFB64200A08489 /* AuthenticationService.swift */, - D0EC8DCA24DFA06700A08489 /* IdentitiesService.swift */, + D0EC8DCA24DFA06700A08489 /* AllIdentitiesService.swift */, D0EC8DC124DF7D9C00A08489 /* IdentityService.swift */, D0EC8DC424DF842700A08489 /* KeychainService.swift */, D0EC8DC724DF8B3C00A08489 /* SecretsService.swift */, @@ -1122,7 +1122,7 @@ D019E6F024DF7C2F00697C7D /* DatabaseError.swift in Sources */, D019E6D724DF728400697C7D /* MastodonEncoder.swift in Sources */, D0EC8DE524E0B44500A08489 /* UserNotificationService.swift in Sources */, - D0EC8DCB24DFA06700A08489 /* IdentitiesService.swift in Sources */, + D0EC8DCB24DFA06700A08489 /* AllIdentitiesService.swift in Sources */, D0091B7124DD68220040E8D2 /* PreferencesViewModel.swift in Sources */, D0A2453724EF346800B07068 /* StatusListViewController.swift in Sources */, D057426A24EA32AC00839EBA /* Timeline.swift in Sources */, @@ -1192,7 +1192,7 @@ D0ED1BC224CED48800B4899C /* HTTPClient.swift in Sources */, D0666A4C24C6C37700F3F04B /* Identity.swift in Sources */, D0EC8DE424E0B44400A08489 /* UserNotificationService.swift in Sources */, - D0EC8DCC24DFA06700A08489 /* IdentitiesService.swift in Sources */, + D0EC8DCC24DFA06700A08489 /* AllIdentitiesService.swift in Sources */, D0666A5524C6C3E500F3F04B /* Emoji.swift in Sources */, D019E6EE24DF7BF300697C7D /* IdentityDatabase.swift in Sources */, D0A652AE24DE3EB6002EA33F /* PreferencesEndpoint+Stubbing.swift in Sources */, diff --git a/Shared/MetatextApp.swift b/Shared/MetatextApp.swift index 5634663..aef7394 100644 --- a/Shared/MetatextApp.swift +++ b/Shared/MetatextApp.swift @@ -12,7 +12,7 @@ struct MetatextApp: App { #endif // swiftlint:enable weak_delegate - private let identitiesService: IdentitiesService = { + private let allIdentitiesService: AllIdentitiesService = { let identityDatabase: IdentityDatabase do { @@ -21,14 +21,14 @@ struct MetatextApp: App { fatalError("Failed to initialize identity database") } - return IdentitiesService(identityDatabase: identityDatabase, environment: .live) + return AllIdentitiesService(identityDatabase: identityDatabase, environment: .live) }() var body: some Scene { WindowGroup { RootView( viewModel: RootViewModel(appDelegate: appDelegate, - identitiesService: identitiesService, + allIdentitiesService: allIdentitiesService, userNotificationService: UserNotificationService())) } } diff --git a/Shared/Services/IdentitiesService.swift b/Shared/Services/AllIdentitiesService.swift similarity index 98% rename from Shared/Services/IdentitiesService.swift rename to Shared/Services/AllIdentitiesService.swift index 9e98ec0..1640d00 100644 --- a/Shared/Services/IdentitiesService.swift +++ b/Shared/Services/AllIdentitiesService.swift @@ -3,7 +3,7 @@ import Foundation import Combine -struct IdentitiesService { +struct AllIdentitiesService { let mostRecentlyUsedIdentityID: AnyPublisher private let identityDatabase: IdentityDatabase @@ -19,7 +19,7 @@ struct IdentitiesService { } } -extension IdentitiesService { +extension AllIdentitiesService { func identityService(id: UUID) throws -> IdentityService { try IdentityService(identityID: id, identityDatabase: identityDatabase, diff --git a/Shared/View Models/AddIdentityViewModel.swift b/Shared/View Models/AddIdentityViewModel.swift index b8b4f21..db23c73 100644 --- a/Shared/View Models/AddIdentityViewModel.swift +++ b/Shared/View Models/AddIdentityViewModel.swift @@ -9,12 +9,12 @@ class AddIdentityViewModel: ObservableObject { @Published private(set) var loading = false let addedIdentityID: AnyPublisher - private let identitiesService: IdentitiesService + private let allIdentitiesService: AllIdentitiesService private let addedIdentityIDInput = PassthroughSubject() private var cancellables = Set() - init(identitiesService: IdentitiesService) { - self.identitiesService = identitiesService + init(allIdentitiesService: AllIdentitiesService) { + self.allIdentitiesService = allIdentitiesService addedIdentityID = addedIdentityIDInput.eraseToAnyPublisher() } @@ -30,10 +30,10 @@ class AddIdentityViewModel: ObservableObject { return } - identitiesService.authorizeIdentity(id: identityID, instanceURL: instanceURL) + allIdentitiesService.authorizeIdentity(id: identityID, instanceURL: instanceURL) .collect() .map { _ in (identityID, instanceURL) } - .flatMap(identitiesService.createIdentity(id:instanceURL:)) + .flatMap(allIdentitiesService.createIdentity(id:instanceURL:)) .assignErrorsToAlertItem(to: \.alertItem, on: self) .receive(on: RunLoop.main) .handleEvents( @@ -60,7 +60,7 @@ class AddIdentityViewModel: ObservableObject { } // TODO: Ensure instance has not disabled public preview - identitiesService.createIdentity(id: identityID, instanceURL: instanceURL) + allIdentitiesService.createIdentity(id: identityID, instanceURL: instanceURL) .assignErrorsToAlertItem(to: \.alertItem, on: self) .sink { [weak self] in guard let self = self, case .finished = $0 else { return } diff --git a/Shared/View Models/RootViewModel.swift b/Shared/View Models/RootViewModel.swift index 229d9cd..2b47a03 100644 --- a/Shared/View Models/RootViewModel.swift +++ b/Shared/View Models/RootViewModel.swift @@ -10,18 +10,18 @@ class RootViewModel: ObservableObject { // swiftlint:disable weak_delegate private let appDelegate: AppDelegate // swiftlint:enable weak_delegate - private let identitiesService: IdentitiesService + private let allIdentitiesService: AllIdentitiesService private let userNotificationService: UserNotificationService private var cancellables = Set() init(appDelegate: AppDelegate, - identitiesService: IdentitiesService, + allIdentitiesService: AllIdentitiesService, userNotificationService: UserNotificationService) { self.appDelegate = appDelegate - self.identitiesService = identitiesService + self.allIdentitiesService = allIdentitiesService self.userNotificationService = userNotificationService - identitiesService.mostRecentlyUsedIdentityID.assign(to: &$mostRecentlyUsedIdentityID) + allIdentitiesService.mostRecentlyUsedIdentityID.assign(to: &$mostRecentlyUsedIdentityID) newIdentitySelected(id: mostRecentlyUsedIdentityID) @@ -29,7 +29,7 @@ class RootViewModel: ObservableObject { .filter { $0 } .zip(appDelegate.registerForRemoteNotifications()) .map { $1 } - .flatMap(identitiesService.updatePushSubscriptions(deviceToken:)) + .flatMap(allIdentitiesService.updatePushSubscriptions(deviceToken:)) .sink { _ in } receiveValue: { _ in } .store(in: &cancellables) } @@ -46,7 +46,7 @@ extension RootViewModel { let identityService: IdentityService do { - identityService = try identitiesService.identityService(id: id) + identityService = try allIdentitiesService.identityService(id: id) } catch { return } @@ -74,12 +74,12 @@ extension RootViewModel { } func deleteIdentity(_ identity: Identity) { - identitiesService.deleteIdentity(identity) + allIdentitiesService.deleteIdentity(identity) .sink { _ in } receiveValue: { _ in } .store(in: &cancellables) } func addIdentityViewModel() -> AddIdentityViewModel { - AddIdentityViewModel(identitiesService: identitiesService) + AddIdentityViewModel(allIdentitiesService: allIdentitiesService) } } diff --git a/Tests/View Models/AddIdentityViewModelTests.swift b/Tests/View Models/AddIdentityViewModelTests.swift index 86e4752..a2b8afa 100644 --- a/Tests/View Models/AddIdentityViewModelTests.swift +++ b/Tests/View Models/AddIdentityViewModelTests.swift @@ -8,7 +8,7 @@ import CombineExpectations class AddIdentityViewModelTests: XCTestCase { func testAddIdentity() throws { let identityDatabase = IdentityDatabase.fresh() - let sut = AddIdentityViewModel(identitiesService: .fresh(identityDatabase: identityDatabase)) + let sut = AddIdentityViewModel(allIdentitiesService: .fresh(identityDatabase: identityDatabase)) let addedIDRecorder = sut.addedIdentityID.record() sut.urlFieldText = "https://mastodon.social" @@ -19,7 +19,7 @@ class AddIdentityViewModelTests: XCTestCase { func testAddIdentityWithoutScheme() throws { let identityDatabase = IdentityDatabase.fresh() - let sut = AddIdentityViewModel(identitiesService: .fresh(identityDatabase: identityDatabase)) + let sut = AddIdentityViewModel(allIdentitiesService: .fresh(identityDatabase: identityDatabase)) let addedIDRecorder = sut.addedIdentityID.record() sut.urlFieldText = "mastodon.social" @@ -29,7 +29,7 @@ class AddIdentityViewModelTests: XCTestCase { } func testInvalidURL() throws { - let sut = AddIdentityViewModel(identitiesService: .fresh()) + let sut = AddIdentityViewModel(allIdentitiesService: .fresh()) let recorder = sut.$alertItem.record() XCTAssertNil(try wait(for: recorder.next(), timeout: 1)) @@ -46,11 +46,13 @@ class AddIdentityViewModelTests: XCTestCase { let environment = AppEnvironment( session: Session(configuration: .stubbing), webAuthSessionType: CanceledLoginMockWebAuthSession.self, - keychainServiceType: MockKeychainService.self) - let identitiesService = IdentitiesService( + keychainServiceType: MockKeychainService.self, + userDefaults: MockUserDefaults(), + inMemoryContent: true) + let allIdentitiesService = AllIdentitiesService( identityDatabase: .fresh(), environment: environment) - let sut = AddIdentityViewModel(identitiesService: identitiesService) + let sut = AddIdentityViewModel(allIdentitiesService: allIdentitiesService) let recorder = sut.$alertItem.record() XCTAssertNil(try wait(for: recorder.next(), timeout: 1)) diff --git a/Tests/View Models/RootViewModelTests.swift b/Tests/View Models/RootViewModelTests.swift index c25cde7..0ff3989 100644 --- a/Tests/View Models/RootViewModelTests.swift +++ b/Tests/View Models/RootViewModelTests.swift @@ -10,7 +10,7 @@ class RootViewModelTests: XCTestCase { func testAddIdentity() throws { let sut = RootViewModel(appDelegate: AppDelegate(), - identitiesService: IdentitiesService( + allIdentitiesService: AllIdentitiesService( identityDatabase: .fresh(), environment: .development), userNotificationService: UserNotificationService())