Last active
July 8, 2018 05:52
-
-
Save iboss-ptk/f0139c34eb7c243f2a54986071da94a8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class NotificationServiceTest : Spek({ | |
| describe(".notify") { | |
| context("when message creation fails") { | |
| // constants | |
| val messagingServiceId = "message-service-id" | |
| val errorCode = 9 | |
| val errorMessage = "error message" | |
| val restClient = mock<TwilioRestClient>() | |
| val secretRepository = mock<SecretRepository> { | |
| on { getTwilloMessagingServiceId() } doReturn messagingServiceId | |
| } | |
| val notificationService = NotificationService(restClient, secretRepository) | |
| val notificationRequest = NotificationRequest("+66", "839992233", "text") | |
| // We create a creator that returns a mocked `MessageCreator` | |
| // and now we can determine to behavior of function `create` | |
| fun creator(phoneNumber: PhoneNumber, messagingServiceId: String, text: String): MessageCreator = | |
| mock { | |
| on { create(restClient) } doReturn Message.fromJson( | |
| """ | |
| { | |
| "error_code": $errorCode, | |
| "error_message": "$errorMessage", | |
| "status": "failed" | |
| } | |
| """.trimIndent(), jacksonObjectMapper()) | |
| } | |
| // notice that I use `::creator` to refer to `creator` as a value that can be passed | |
| val result = notificationService.notify(notificationRequest, ::creator) | |
| it("returns `NotificationFailed` with error code and error message") { | |
| assertThat(result).isEqualTo(NotificationFailed(errorCode, errorMessage)) | |
| } | |
| } | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment