Created
August 9, 2020 15:32
-
-
Save Bradysm/a6f5bb630bd27137bc53f44fa610577d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Service for mocking a message sending service | |
Conforms to MessageSendable protocol | |
*/ | |
struct MockedMessageService: MessageSendable { | |
/** | |
Mocked version of send message | |
*/ | |
func sendMessage(username: String, message: String, completion: @escaping (Result<String, Error>) -> Void) { | |
// check for cases that will cause failure and mock them | |
if username.isEmpty { | |
completion(.failure(MessageError.emptyUsername)) | |
} | |
if message.isEmpty { | |
completion(.failure(MessageError.emptyMessage)) | |
} | |
// mock successfully sending message | |
completion(.success("Successfully sent message")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment