2020-08-25 16:08:02 +03:00
|
|
|
module Parser.QueryTest where
|
|
|
|
|
|
|
|
import Test.Tasty.Hspec
|
|
|
|
|
|
|
|
import Data.Either (isLeft)
|
2020-09-17 16:41:59 +03:00
|
|
|
import qualified Path.Posix as PPosix
|
2020-08-25 16:08:02 +03:00
|
|
|
|
|
|
|
import Parser.Common (runWaspParser)
|
|
|
|
import Parser.Query (query)
|
|
|
|
import qualified Wasp.Query
|
|
|
|
import qualified Wasp.JsImport
|
|
|
|
|
|
|
|
spec_parseQuery :: Spec
|
|
|
|
spec_parseQuery =
|
|
|
|
describe "Parsing query declaration" $ do
|
|
|
|
let parseQuery = runWaspParser query
|
|
|
|
|
|
|
|
it "When given a valid query declaration, returns correct AST" $ do
|
|
|
|
let testQueryName = "myQuery"
|
|
|
|
testQueryJsFunctionName = "myJsQuery"
|
2020-09-17 16:41:59 +03:00
|
|
|
testQueryJsFunctionFrom = [PPosix.relfile|some/path|]
|
2020-08-25 16:08:02 +03:00
|
|
|
let testQuery = Wasp.Query.Query
|
|
|
|
{ Wasp.Query._name = testQueryName
|
|
|
|
, Wasp.Query._jsFunction = Wasp.JsImport.JsImport
|
2020-08-25 16:55:37 +03:00
|
|
|
{ Wasp.JsImport._defaultImport = Nothing
|
|
|
|
, Wasp.JsImport._namedImports = [ testQueryJsFunctionName ]
|
|
|
|
, Wasp.JsImport._from = testQueryJsFunctionFrom
|
2020-08-25 16:08:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
parseQuery ( "query " ++ testQueryName ++ " {\n" ++
|
|
|
|
" fn: import { " ++ testQueryJsFunctionName ++ " } from \"@ext/some/path\"\n" ++
|
|
|
|
"}"
|
|
|
|
) `shouldBe` Right testQuery
|
|
|
|
it "When given query wasp declaration without 'fn' property, should return Left" $ do
|
|
|
|
isLeft (parseQuery "query myQuery { }") `shouldBe` True
|