summaryrefslogtreecommitdiff
path: root/cask/test/src/test/cask/FailureTests.scala
blob: 65018ce90470b1a90e47157d49eab17e7cf046b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package test.cask

import cask.model.Request
import utest._

object FailureTests extends TestSuite {
  class myDecorator extends cask.RawDecorator {
    def wrapFunction(ctx: Request, delegate: Delegate) = {
      delegate(Map("extra" -> 31337))
    }
  }

  val tests = Tests{
    'mismatchedDecorators - {
      utest.compileError("""
        object Decorated extends cask.MainRoutes{
          @myDecorator
          @cask.websocket("/hello/:world")
          def hello(world: String)(extra: Int) = ???
          initialize()
        }
      """).check(
          """
          def hello(world: String)(extra: Int) = ???
              ^
          """,
        "required: cask.router.Decorator[_, cask.endpoints.WebsocketResult, _]"
      )
      utest.compileError("""
        object Decorated extends cask.MainRoutes{
          @cask.get("/hello/:world")
          @myDecorator()
          def hello(world: String)(extra: Int)= world
          initialize()
        }
      """).msg ==>
        "Last annotation applied to a function must be an instance of Endpoint, not test.cask.FailureTests.myDecorator"

      utest.compileError("""
        object Decorated extends cask.MainRoutes{
          @cask.get("/hello/:world")
          @cask.get("/hello/:world")
          def hello(world: String)(extra: Int)= world
          initialize()
        }
      """).msg ==>
        "You can only apply one Endpoint annotation to a function, not 2 in cask.endpoints.get, cask.endpoints.get"
    }
  }
}