Skip to content

Commit

Permalink
Add test for Handler, and correct failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathonherbert committed May 10, 2024
1 parent 206f47a commit f235d4f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/Handler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class Handler
APIGatewayProxyResponseEvent
]
with Logging with QueryJson {
implicit val ec: scala.concurrent.ExecutionContext =
private implicit val ec: scala.concurrent.ExecutionContext =
scala.concurrent.ExecutionContext.global
val cql = new Cql()
private val cql = new Cql()

def handleRequest(
event: APIGatewayProxyRequestEvent,
Expand Down
27 changes: 27 additions & 0 deletions src/test/scala/HandlerTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cql

import org.scalatest.matchers._
import org.scalatest.funspec.AnyFunSpec
import cql.lang.BaseTest
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent

class HandlerTest extends AnyFunSpec with should.Matchers {
val handler = new Handler()

def assertIO(input: String, status: Int, output: String) =
val request = new APIGatewayProxyRequestEvent().withBody(input)

val response = handler.handleRequest(request, null)

response.getBody.contains(output) shouldBe true

describe("a program") {
it("should give a 200 for a valid query") {
assertIO("+section:commentisfree", 200, "section=commentisfree")
}

it("should give a 400 for an invalid query") {
assertIO("this AND", 200, "There must be a query following 'AND', e.g. this AND that.")
}
}
}
4 changes: 2 additions & 2 deletions src/test/scala/lang/ScannerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ class ScannerTest extends BaseTest {
assert(tokens === expectedTokens)
}

it("should yield a colon token when a query meta value is incomplete") {
it("should yield a query field value token when a query meta value is incomplete") {
val scanner = new Scanner("""example +tag:""")
val tokens = scanner.scanTokens
val expectedTokens = List(
unquotedStringToken("example"),
Token(TokenType.QUERY_FIELD_KEY, "+tag", Some("tag"), 8, 11),
Token(TokenType.COLON, ":", None, 12, 12),
Token(TokenType.QUERY_VALUE, ":", None, 12, 12),
eofToken(13)
)
assert(tokens === expectedTokens)
Expand Down

0 comments on commit f235d4f

Please sign in to comment.