<commit_before>package im.mange.shoreditch.example

import org.json4s.native.JsonMethods._
import org.scalatest.{MustMatchers, WordSpec}

class ExampleSpec extends WordSpec with MustMatchers {
  private val shoreditch = Example.shoreditch

  "captures checks and actions" in {
    shoreditch.checks.size mustEqual 3
    shoreditch.checks must contain ("base/check/successful/check" -> SuccessfulCheck)

    shoreditch.actions.size mustEqual 3
    shoreditch.actions must contain ("base/action/successful/action" -> SuccessfulAction)
  }

  "handles missing requests" in {
    shoreditch.handle(SimpleRequest("")) mustEqual None
  }

  "handles check requests" in {
    shoreditch.handle(SimpleRequest("base/check/successful/check")) mustEqual Some("""{"failures":[]}""")
  }

  "handles check requests with failures" in {
    shoreditch.handle(SimpleRequest("base/check/failure/check")) mustEqual Some("""{"failures":["Failed"]}""")
  }

  "handles action requests" in {
    shoreditch.handle(SimpleRequest("base/action/successful/action")) mustEqual Some("""{"failures":[]}""")
  }

  "handles action requests with failures" in {
    shoreditch.handle(SimpleRequest("base/action/failure/action")) mustEqual Some("""{"failures":["Failed"]}""")
  }

  "handles metadata requests" in {
    val response = shoreditch.handle(SimpleRequest("base/metadata"))
    val expected = Some(compact(render(parse(
      """{"name":"Example System","alias":"example","version":"10001",
        |"checks":[
        |{"url":"base/check/failure/check"},
        |{"url":"base/check/successful/check"},
        |{"url":"base/check/successful/check/with/@arg"}],
        |"actions":[
        |{"url":"base/action/successful/action","in":[]},
        |{"url":"base/action/failure/action","in":[]},
        |{"url":"base/action/successful/action/with/return","in":[]}]}""".stripMargin
    ))))

//    println(response)
//    println(expected)

    response mustEqual expected
  }

  "handles check requests with args" in {
    shoreditch.handle(SimpleRequest("base/check/successful/check/with/args/arg")) mustEqual Some("""{"failures":[]}""")
  }

  "handles action requests with args" in {
    shoreditch.handle(SimpleRequest("base/action/successful/action/with/args", json = "")) mustEqual Some("""{"failures":[]}""")
  }

  //BUG: this seems to run a check, maybe the first it finds?
  "handles index requests" in {
    pending
    val response = shoreditch.handle(SimpleRequest("base"))
    response mustEqual None
  }

  //BUG: this seems to run a check, maybe the first it finds?
  "rejects checks with bogus endings to valid service" in {
    pending
    val response = shoreditch.handle(SimpleRequest("base/check/successful/check/bogus"))
    response mustEqual None
  }

  //BUG: this seems to run an action, maybe the first it finds?
  "rejects actions with bogus endings to valid service" in {
    pending
    val response = shoreditch.handle(SimpleRequest("base/action/successful/action/bogus"))
    response mustEqual None<commit_msg>give the spec some LOVE<commit_after>package im.mange.shoreditch.example

import org.json4s.native.JsonMethods._
import org.scalatest.{MustMatchers, WordSpec}

class ExampleSpec extends WordSpec with MustMatchers {
  private val shoreditch = Example.shoreditch
  private val success = Some("""{"failures":[]}""")
  private val failure = Some("""{"failures":["Failed"]}""")

  "captures checks and actions" in {
    shoreditch.checks.size mustEqual 3
    shoreditch.checks must contain ("base/check/successful/check" -> SuccessfulCheck)

    shoreditch.actions.size mustEqual 3
    shoreditch.actions must contain ("base/action/successful/action" -> SuccessfulAction)
  }

  "handles missing requests" in {
    shoreditch.handle(SimpleRequest("")) mustEqual None
  }

  "handles check requests" in {
    shoreditch.handle(SimpleRequest("base/check/successful/check")) mustEqual success
  }

  "handles check requests with failures" in {
    shoreditch.handle(SimpleRequest("base/check/failure/check")) mustEqual failure
  }

  "handles action requests" in {
    shoreditch.handle(SimpleRequest("base/action/successful/action")) mustEqual success
  }

  "handles action requests with failures" in {
    shoreditch.handle(SimpleRequest("base/action/failure/action")) mustEqual failure
  }

  "handles metadata requests" in {
    val response = shoreditch.handle(SimpleRequest("base/metadata"))
    val expected = Some(compact(render(parse(
      """{"name":"Example System","alias":"example","version":"10001",
        |"checks":[
        |{"url":"base/check/failure/check"},
        |{"url":"base/check/successful/check"},
        |{"url":"base/check/successful/check/with/@arg"}],
        |"actions":[
        |{"url":"base/action/successful/action","in":[]},
        |{"url":"base/action/failure/action","in":[]},
        |{"url":"base/action/successful/action/with/return","in":[]}]}""".stripMargin
    ))))

//    println(response)
//    println(expected)

    response mustEqual expected
  }

  "handles check requests with args" in {
    shoreditch.handle(SimpleRequest("base/check/successful/check/with/args/arg")) mustEqual success
  }

  "handles action requests with args" in {
    shoreditch.handle(SimpleRequest("base/action/successful/action/with/args", json = "")) mustEqual success
  }

  //BUG: this seems to run a check, maybe the first it finds?
  "handles index requests" in {
    pending
    shoreditch.handle(SimpleRequest("base")) mustEqual None
  }

  //BUG: this seems to run a check, maybe the first it finds?
  "rejects checks with bogus endings to valid service" in {
    pending
    shoreditch.handle(SimpleRequest("base/check/successful/check/bogus")) mustEqual None
  }

  //BUG: this seems to run an action, maybe the first it finds?
  "rejects actions with bogus endings to valid service" in {
    pending
    shoreditch.handle(SimpleRequest("base/action/successful/action/bogus")) mustEqual None
{'fraction_non_alphanumeric': 0.1457142857142857, 'fraction_numerical': 0.002689075630252101, 'mean_word_length': 4.16131830008673, 'pattern_counts': {'":': 36, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1691768', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1757, 'n_words': 402}