Created
July 8, 2018 06:13
-
-
Save iboss-ptk/e60e16845d4eb8d8c03340ed2bfae7e7 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") | |
| // Assign a lambda to val directly | |
| val creator: MessageCreatorFactory = { _, _, _ -> | |
| mock { | |
| on { create(restClient) } doReturn Message.fromJson( | |
| """ | |
| { | |
| "error_code": $errorCode, | |
| "error_message": "$errorMessage", | |
| "status": "failed" | |
| } | |
| """.trimIndent(), jacksonObjectMapper()) | |
| } | |
| } | |
| // `::` is not needed anymore | |
| 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