Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
- Merge SessionVerificationControllerProxyMock into MockSessionVerificationControllerProxy.
- Merge ClientProxyMock into MockClientProxy.
- Simplify naming.
  • Loading branch information
pixlwave committed Jan 6, 2023
1 parent e875bfd commit 0e3d798
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 248 deletions.
14 changes: 3 additions & 11 deletions ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -206,7 +206,6 @@
69BCBB4FB2DC3D61A28D3FD8 /* TimelineStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DC2C9E0E15C79BBDA80F0A2 /* TimelineStyle.swift */; };
6A0E7551E0D1793245F34CDD /* ClientError.swift in Sources */ = {isa = PBXBuildFile; fileRef = D09A267106B9585D3D0CFC0D /* ClientError.swift */; };
6AC1DC1EAD9F7568360DA1BA /* ServerSelectionModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = A30A1758E2B73EF38E7C42F8 /* ServerSelectionModels.swift */; };
6AE7082703DB19F74A83F677 /* SessionVerificationControllerProxyMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDC0DCEE729FCBE315C7445C /* SessionVerificationControllerProxyMock.swift */; };
6B15FF984906AAFCF9DC4F58 /* OnboardingUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C88046D6A070D9827181C4D /* OnboardingUITests.swift */; };
6C67774E8387D44426718BD9 /* FilePreviewCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADB3A7BCE745626EC61EF3C3 /* FilePreviewCoordinator.swift */; };
6C9F6C7F2B35288C4230EF3F /* FilePreviewModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55EA4B03F92F31EAA83B3F7B /* FilePreviewModels.swift */; };
Expand Down Expand Up @@ -374,7 +373,6 @@
BD782053BE4C3D2F0BDE5699 /* ServiceLocator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F95CADD0A5DBD76B990FCB /* ServiceLocator.swift */; };
BEEEB659A0BA510D7BE6345C /* RoomMemberProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D1790942BE4FE0D8273191B /* RoomMemberProxy.swift */; };
BFB534E338A3D949944FB2F5 /* NotificationServiceProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B490675B8E31423AF116BDA /* NotificationServiceProxy.swift */; };
C07B25B7F552657C158DA85B /* ClientProxyMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5461F0B817787C9694D9620A /* ClientProxyMock.swift */; };
C1910A16BDF131FECA77BE22 /* EmojiPickerScreenCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEA38B9851CFCC4D67F5587D /* EmojiPickerScreenCoordinator.swift */; };
C3522917C0C367C403429EEC /* CoordinatorProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = B251F5B4511D1CA0BA8361FE /* CoordinatorProtocol.swift */; };
C35CF4DAB1467FE1BBDC204B /* MessageTimelineItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEAF1C75771D9DC75877F4B4 /* MessageTimelineItem.swift */; };
Expand Down Expand Up @@ -712,7 +710,6 @@
541542F5AC323709D8563458 /* AnalyticsPrompt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsPrompt.swift; sourceTree = "<group>"; };
542D4F49FABA056DEEEB3400 /* RustTracing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RustTracing.swift; sourceTree = "<group>"; };
5445FCE0CE15E634FDC1A2E2 /* AnalyticsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsService.swift; sourceTree = "<group>"; };
5461F0B817787C9694D9620A /* ClientProxyMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientProxyMock.swift; sourceTree = "<group>"; };
55BC11560C8A2598964FFA4C /* bs */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = bs; path = bs.lproj/Localizable.strings; sourceTree = "<group>"; };
55D7187F6B0C0A651AC3DFFA /* in */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = in; path = in.lproj/Localizable.strings; sourceTree = "<group>"; };
55EA4B03F92F31EAA83B3F7B /* FilePreviewModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilePreviewModels.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -799,7 +796,7 @@
8D6094DEAAEB388E1AE118C6 /* MockRoomTimelineProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockRoomTimelineProvider.swift; sourceTree = "<group>"; };
8D8169443E5AC5FF71BFB3DB /* cs */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = cs; path = cs.lproj/Localizable.strings; sourceTree = "<group>"; };
8DC2C9E0E15C79BBDA80F0A2 /* TimelineStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineStyle.swift; sourceTree = "<group>"; };
8E088F2A1B9EC529D3221931 /* UITests.xctestplan */ = {isa = PBXFileReference; path = UITests.xctestplan; sourceTree = "<group>"; };
8E088F2A1B9EC529D3221931 /* UITests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = UITests.xctestplan; sourceTree = "<group>"; };
8ED2D2F6A137A95EA50413BE /* UserNotificationControllerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserNotificationControllerProtocol.swift; sourceTree = "<group>"; };
8F7D42E66E939B709C1EC390 /* MockRoomSummaryProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockRoomSummaryProvider.swift; sourceTree = "<group>"; };
8FC26871038FB0E4AAE22605 /* apple_emojis_data.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = apple_emojis_data.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1011,10 +1008,9 @@
EBE5502760CF6CA2D7201883 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = ja; path = ja.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
ED044D00F2176681CC02CD54 /* HomeScreenRoomCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeScreenRoomCell.swift; sourceTree = "<group>"; };
ED1D792EB82506A19A72C8DE /* RoomTimelineItemProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomTimelineItemProtocol.swift; sourceTree = "<group>"; };
ED482057AE39D5C6D9C5F3D8 /* message.caf */ = {isa = PBXFileReference; path = message.caf; sourceTree = "<group>"; };
ED482057AE39D5C6D9C5F3D8 /* message.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = message.caf; sourceTree = "<group>"; };
EDAA4472821985BF868CC21C /* ServerSelectionViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerSelectionViewModelTests.swift; sourceTree = "<group>"; };
EDB6E40BAD4504D899FAAC9A /* TemplateViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateViewModel.swift; sourceTree = "<group>"; };
EDC0DCEE729FCBE315C7445C /* SessionVerificationControllerProxyMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionVerificationControllerProxyMock.swift; sourceTree = "<group>"; };
EE8BCD14EFED23459A43FDFF /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = "<group>"; };
EEAF1C75771D9DC75877F4B4 /* MessageTimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageTimelineItem.swift; sourceTree = "<group>"; };
EEE384418EB1FEDFA62C9CD0 /* RoomTimelineViewFactoryProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomTimelineViewFactoryProtocol.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1521,7 +1517,6 @@
53280D2292E6C9C7821773FD /* UserSession */ = {
isa = PBXGroup;
children = (
EDC0DCEE729FCBE315C7445C /* SessionVerificationControllerProxyMock.swift */,
F36C0A6D59717193F49EA986 /* UserSessionTests.swift */,
);
path = UserSession;
Expand Down Expand Up @@ -1839,7 +1834,6 @@
7DBC911559934065993A5FF4 /* NotificationManager */ = {
isa = PBXGroup;
children = (
5461F0B817787C9694D9620A /* ClientProxyMock.swift */,
0376C429FAB1687C3D905F3E /* MockCoder.swift */,
30ED584467DB380E3CEFB1DB /* NotificationManagerTests.swift */,
DC0AEA686E425F86F6BA0404 /* UNNotification+Creator.swift */,
Expand Down Expand Up @@ -2869,7 +2863,6 @@
0F9E38A75337D0146652ACAB /* BackgroundTaskTests.swift in Sources */,
7F61F9ACD5EC9E845EF3EFBF /* BugReportServiceTests.swift in Sources */,
C7CFDB4929DDD9A3B5BA085D /* BugReportViewModelTests.swift in Sources */,
C07B25B7F552657C158DA85B /* ClientProxyMock.swift in Sources */,
9C45CE85325CD591DADBC4CA /* ElementXTests.swift in Sources */,
501304F26B52DF7024011B6C /* EmojiMartJSONLoaderTests.swift in Sources */,
25618589E0DE0F1E95FC7B5C /* EmojiProviderTests.swift in Sources */,
Expand All @@ -2894,7 +2887,6 @@
46562110EE202E580A5FFD9C /* RoomScreenViewModelTests.swift in Sources */,
EA31DD9043B91ECB8E45A9A6 /* ScreenshotDetectorTests.swift in Sources */,
93875ADD456142D20823ED24 /* ServerSelectionViewModelTests.swift in Sources */,
6AE7082703DB19F74A83F677 /* SessionVerificationControllerProxyMock.swift in Sources */,
86675910612A12409262DFBD /* SessionVerificationStateMachineTests.swift in Sources */,
755727E0B756430DFFEC4732 /* SessionVerificationViewModelTests.swift in Sources */,
206F0DBAB6AF042CA1FF2C0D /* SettingsViewModelTests.swift in Sources */,
Expand Down
36 changes: 32 additions & 4 deletions ElementX/Sources/Services/Client/MockClientProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,31 @@ class MockClientProxy: ClientProxyProtocol {
throw ClientProxyError.failedLoadingMedia
}

var sessionVerificationControllerProxyResult: Result<SessionVerificationControllerProxyProtocol, ClientProxyError>?
func sessionVerificationControllerProxy() async -> Result<SessionVerificationControllerProxyProtocol, ClientProxyError> {
.failure(.failedRetrievingSessionVerificationController)
if let sessionVerificationControllerProxyResult {
return sessionVerificationControllerProxyResult
} else {
return .failure(.failedRetrievingSessionVerificationController)
}
}

func logout() async {
// no-op
}


var setPusherCalled = false
var setPusherErrorToThrow: Error?
var setPusherPushkey: String?
var setPusherKind: PusherKind?
var setPusherAppId: String?
var setPusherAppDisplayName: String?
var setPusherDeviceDisplayName: String?
var setPusherProfileTag: String?
var setPusherLang: String?
var setPusherUrl: String?
var setPusherFormat: PushFormat?
var setPusherDefaultPayload: [AnyHashable: Any]?
// swiftlint:disable:next function_parameter_count
func setPusher(pushkey: String,
kind: PusherKind?,
Expand All @@ -98,6 +115,17 @@ class MockClientProxy: ClientProxyProtocol {
url: String?,
format: PushFormat?,
defaultPayload: [AnyHashable: Any]?) async throws {
// no-op
if let setPusherErrorToThrow { throw setPusherErrorToThrow }
setPusherCalled = true
setPusherPushkey = pushkey
setPusherKind = kind
setPusherAppId = appId
setPusherAppDisplayName = appDisplayName
setPusherDeviceDisplayName = deviceDisplayName
setPusherProfileTag = profileTag
setPusherLang = lang
setPusherUrl = url
setPusherFormat = format
setPusherDefaultPayload = defaultPayload
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ struct MockSessionVerificationControllerProxy: SessionVerificationControllerProx
var callbacks = PassthroughSubject<SessionVerificationControllerProxyCallback, Never>()

var isVerified = false
var requestDelay: Duration = .seconds(2)

func requestVerification() async -> Result<Void, SessionVerificationControllerProxyError> {
Task.detached {
try await Task.sleep(nanoseconds: 2_000_000_000)
try await Task.sleep(for: requestDelay)
callbacks.send(.receivedVerificationData(Self.emojis))
}

Expand All @@ -34,7 +35,7 @@ struct MockSessionVerificationControllerProxy: SessionVerificationControllerProx

func approveVerification() async -> Result<Void, SessionVerificationControllerProxyError> {
Task.detached {
try await Task.sleep(nanoseconds: 2_000_000_000)
try await Task.sleep(for: requestDelay)
callbacks.send(.finished)
}

Expand All @@ -43,7 +44,7 @@ struct MockSessionVerificationControllerProxy: SessionVerificationControllerProx

func declineVerification() async -> Result<Void, SessionVerificationControllerProxyError> {
Task.detached {
try await Task.sleep(nanoseconds: 2_000_000_000)
try await Task.sleep(for: requestDelay)
callbacks.send(.cancelled)
}

Expand All @@ -52,7 +53,7 @@ struct MockSessionVerificationControllerProxy: SessionVerificationControllerProx

func cancelVerification() async -> Result<Void, SessionVerificationControllerProxyError> {
Task.detached {
try await Task.sleep(nanoseconds: 2_000_000_000)
try await Task.sleep(for: requestDelay)
callbacks.send(.cancelled)
}

Expand Down
122 changes: 0 additions & 122 deletions UnitTests/Sources/NotificationManager/ClientProxyMock.swift

This file was deleted.

Loading

0 comments on commit 0e3d798

Please sign in to comment.