Skip to content

Instantly share code, notes, and snippets.

@shubhamsgit
Last active July 18, 2023 15:08
Show Gist options
  • Select an option

  • Save shubhamsgit/9156c961c13d7623bd1d89c1f2281460 to your computer and use it in GitHub Desktop.

Select an option

Save shubhamsgit/9156c961c13d7623bd1d89c1f2281460 to your computer and use it in GitHub Desktop.
Sample Test for Appointment Repository
@Test
fun createTimeSlotWithQuery_success_returnsTimeSlot() {
val startDate = "2023-07-15T10:00:00Z"
val endDate = "2023-07-15T11:00:00Z"
val appointmentBlockGet = appointmentBlockGet
enqueueMockResponse("mocked_responses/AppointmentRepository/TimeSlotCreate-success.json")
val result: TimeSlot = appointmentRepository.createTimeSlot(startDate, endDate, appointmentBlockGet).toBlocking().first()
assertEquals(result.endDate, endDate)
}
fun enqueueMockResponse(fileName: String) {
avaClass.classLoader?.let {
val inputStream = it.getResourceAsStream(fileName)
val source = inputStream.source().buffer()
val mockResponse = MockResponse()
mockResponse.setBody(source.readString(Charsets.UTF_8))
mockResponse.setResponseCode(200)
mockWebServer.enqueue(mockResponse)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment