Fixed dataservice mock behaviour

This commit is contained in:
Eugene Zadyra
2018-06-06 11:25:33 +02:00
parent dd741c81c1
commit e97b86ba91
4 changed files with 16 additions and 13 deletions

View File

@@ -1,5 +1,4 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.parallel=true org.gradle.parallel=true
org.gradle.configureondemand=true org.gradle.configureondemand=true
org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8 org.gradle.jvmargs=-Dfile.encoding=UTF-8

View File

@@ -211,6 +211,7 @@ class Book(val userId: UserId, bot: Bot, apiService: ApiService, dataService: Da
bot.sendMessage(userId.source, lang.appointmentIsConfirmed) bot.sendMessage(userId.source, lang.appointmentIsConfirmed)
stay() stay()
} }
case _ => sys.error(s"Can not prepare reservation request using booking data $bookingData")
} }
} }

View File

@@ -75,11 +75,13 @@ class ApiService extends SessionSupport {
def getAvailableTerms(userId: Long, cityId: Long, clinicId: Option[Long], serviceId: Long, doctorId: Option[Long], def getAvailableTerms(userId: Long, cityId: Long, clinicId: Option[Long], serviceId: Long, doctorId: Option[Long],
fromDate: ZonedDateTime = ZonedDateTime.now(), toDate: Option[ZonedDateTime] = None, timeOfDay: Int = 0, fromDate: ZonedDateTime = ZonedDateTime.now(), toDate: Option[ZonedDateTime] = None, timeOfDay: Int = 0,
languageId: Long = 10, findFirstFreeTerm: Boolean = false): Either[Throwable, List[AvailableVisitsTermPresentation]] = languageId: Long = 10, findFirstFreeTerm: Boolean = false): Either[Throwable, List[AvailableVisitsTermPresentation]] =
getDefaultPayer(userId, cityId, clinicId, serviceId).flatMap { case Some(payerId) => getDefaultPayer(userId, cityId, clinicId, serviceId).flatMap {
withSession(userId) { session => case Some(payerId) =>
LuxmedApi.availableTerms(session.accessToken, session.tokenType, payerId.id, cityId, clinicId, serviceId, doctorId, withSession(userId) { session =>
fromDate, toDate, timeOfDay, languageId, findFirstFreeTerm).map(_.availableVisitsTermPresentation) LuxmedApi.availableTerms(session.accessToken, session.tokenType, payerId.id, cityId, clinicId, serviceId, doctorId,
} fromDate, toDate, timeOfDay, languageId, findFirstFreeTerm).map(_.availableVisitsTermPresentation)
}
case None => sys.error(s"Can't determine payer id by user: $userId, city: $cityId, clinic: $clinicId, service: $serviceId")
} }

View File

@@ -19,13 +19,13 @@ class AuthSpec extends AkkaTestKit {
val unauthorizedHelpActor = TestProbe() val unauthorizedHelpActor = TestProbe()
val loginActor = TestProbe() val loginActor = TestProbe()
val chatActor = TestProbe() val chatActor = TestProbe()
val unauthorizedHelpFactory: MessageSource => ActorRef = _ => unauthorizedHelpActor.ref val unauthorizedHelpFactory: ByMessageSourceActorFactory = _ => unauthorizedHelpActor.ref
val loginActorFactory: (MessageSource, ActorRef) => ActorRef = (_, _) => loginActor.ref val loginActorFactory: ByMessageSourceWithOriginatorActorFactory = (_, _) => loginActor.ref
val chatActorFactory: UserId => ActorRef = _ => chatActor.ref val chatActorFactory: UserId => ActorRef = _ => chatActor.ref
val dataService = mock(classOf[DataService]) val dataService = mock(classOf[DataService])
when(dataService.findUserIdBySource(source)).thenReturn(None)
val auth = system.actorOf(Auth.props(source, dataService, unauthorizedHelpFactory, loginActorFactory, chatActorFactory)) val auth = system.actorOf(Auth.props(source, dataService, unauthorizedHelpFactory, loginActorFactory, chatActorFactory))
when(dataService.findUserIdBySource(source)).thenReturn(None)
"send english help on /start command" in { "send english help on /start command" in {
val cmd = Command(source, Message("1", Some("/start"))) val cmd = Command(source, Message("1", Some("/start")))
@@ -75,13 +75,14 @@ class AuthSpec extends AkkaTestKit {
val unauthorizedHelpActor = TestProbe() val unauthorizedHelpActor = TestProbe()
val loginActor = TestProbe() val loginActor = TestProbe()
val chatActor = TestProbe() val chatActor = TestProbe()
val unauthorizedHelpFactory: MessageSource => ActorRef = _ => unauthorizedHelpActor.ref val unauthorizedHelpFactory: ByMessageSourceActorFactory = _ => unauthorizedHelpActor.ref
val loginActorFactory: (MessageSource, ActorRef) => ActorRef = (_, _) => loginActor.ref val loginActorFactory: ByMessageSourceWithOriginatorActorFactory = (_, _) => loginActor.ref
val chatActorFactory: UserId => ActorRef = _ => chatActor.ref val chatActorFactory: UserId => ActorRef = _ => chatActor.ref
val dataService = mock(classOf[DataService]) val dataService = mock(classOf[DataService])
when(dataService.findUserIdBySource(source)).thenReturn(Some(userId.userId))
val auth = system.actorOf(Auth.props(source, dataService, unauthorizedHelpFactory, loginActorFactory, chatActorFactory)) val auth = system.actorOf(Auth.props(source, dataService, unauthorizedHelpFactory, loginActorFactory, chatActorFactory))
when(dataService.findUserIdBySource(source)).thenReturn(Some(userId.userId))
"forward all commands to chat actor" in { "forward all commands to chat actor" in {
val cmd = Command(source, Message("1", Some("any"))) val cmd = Command(source, Message("1", Some("any")))