barber icon indicating copy to clipboard operation
barber copied to clipboard

Add validation & tests for only supporting specific types in DocumentData

Open adrw opened this issue 5 years ago • 0 comments

Especially once field stemming is supported, we want to explicitly indicate which types are supported and which aren't.

  @Disabled @Test
  fun `Fails on a non supported DocumentData unit`() {
    data class StrangeUnitDocumentData(
      val strange: Unit
    ) : DocumentData

    val strangeUnitEN_US = DocumentTemplate(
      fields = mapOf(
        "sms_body" to "That's {{ strange }}"
      ),
      source = StrangeUnitDocumentData::class,
      targets = setOf(TransactionalSmsDocument::class),
      locale = Locale.EN_US
    )

    val exception = assertFailsWith<BarberException> {
      BarbershopBuilder()
        .installDocument<TransactionalEmailDocument>()
        .installDocument<TransactionalSmsDocument>()
        .installDocumentTemplate<StrangeUnitDocumentData>(strangeUnitEN_US)
        .build()
    }
    assertEquals(
      """
        |Problems
        |1) ...
        |
      """.trimMargin(),
      exception.toString())
  }

adrw avatar Jul 30 '19 18:07 adrw