0

I am trying to write some integration tests. What I want to achieve is to setup a couple of fake URLs to emulate third party services. I want to know if it is possible to set dynamically URL path for test. For example I have this code

In a base file for the test I have this

override lazy val port = 1234

val myappTestConf = Map (
  "app.twilio.lookups" -> s"https://localhost:$port",
)

override lazy val port = 1234

implicit override lazy val app: FakeApplication =
  FakeApplication(
    additionalConfiguration = myappTestConf
  )

and then in a more specific file I have this

val getLookupPhoneUrl = s"${phoneNumber}"

implicit override lazy val app: FakeApplication =
  FakeApplication(
    additionalConfiguration = myappTestConf,
    withRoutes = {
      case ("GET", `getLookupPhoneUrl`) => Action(testLookupPhone(_))
    }
  )

The problem that I have is that this code does not compile because in the second file the phoneNumber has not been setted up, but I would like to set up dinamically, is that possible?

Thank you

agusgambina
  • 6,229
  • 14
  • 54
  • 94
  • 1
    Can you show the full test case or elaborate more about "set up dynamically" to help us better understand your intent? I still cannot see what you want to achieve. – Teliatko Mar 07 '16 at 23:31
  • @Teliatko thank you for your answer finally someone in the team solved the issue with regex I will post the answer. – agusgambina Mar 08 '16 at 21:36

1 Answers1

0

One of the members of the team solved this with regex. Here is the answer

on the test files

val GetLookupPhone = """/v1/PhoneNumbers/([0-9\.\-]+)""".r

var phone: String = _

implicit override lazy val app: FakeApplication =
  FakeApplication(
    additionalConfiguration = educatinaTestConf,
    withRoutes = {
      case ("GET", GetLookupPhone(phone)) => Action(testLookupPhone(_, phone))
    }
  )

So then the route could be accessed if the route match the regex.

agusgambina
  • 6,229
  • 14
  • 54
  • 94