Skip to content

Instantly share code, notes, and snippets.

@Bradysm
Created August 9, 2020 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bradysm/a6f5bb630bd27137bc53f44fa610577d to your computer and use it in GitHub Desktop.
Save Bradysm/a6f5bb630bd27137bc53f44fa610577d to your computer and use it in GitHub Desktop.
/**
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