wasp/waspc/test/Parser/ParserTest.hs

93 lines
4.3 KiB
Haskell
Raw Normal View History

2019-04-19 16:22:14 +03:00
module Parser.ParserTest where
import Data.Either
import qualified Path.Posix as PPosix
import Test.Tasty.Hspec
2019-04-19 16:22:14 +03:00
import NpmDependency as ND
import Parser
import qualified StrongPath as SP
import Wasp
2020-10-21 17:37:20 +03:00
import qualified Wasp.Entity
import qualified Wasp.Auth
2020-08-25 16:08:02 +03:00
import qualified Wasp.JsImport
import qualified Wasp.NpmDependencies
import qualified Wasp.Page
import qualified Wasp.Query
import qualified Wasp.Route as R
2019-04-19 16:22:14 +03:00
spec_parseWasp :: Spec
spec_parseWasp =
2019-04-19 16:22:14 +03:00
describe "Parsing wasp" $ do
it "When given wasp without app, should return Left" $ do
isLeft (parseWasp "hoho") `shouldBe` True
before (readFile "test/Parser/valid.wasp") $ do
it "When given a valid wasp source, should return correct Wasp" $ \wasp -> do
2019-04-19 16:22:14 +03:00
parseWasp wasp
`shouldBe`
Right (fromWaspElems
[ WaspElementApp $ App
{ appName = "test_app"
, appTitle = "Hello World!"
2021-02-04 13:42:01 +03:00
, appHead = Nothing
}
, WaspElementAuth $ Wasp.Auth.Auth
{ Wasp.Auth._userEntity = "User"
, Wasp.Auth._methods = [Wasp.Auth.EmailAndPassword]
, Wasp.Auth._onAuthFailedRedirectTo = "/test"
}
, WaspElementRoute $ R.Route
{ R._urlPath = "/"
, R._targetPage = "Landing"
}
, WaspElementPage $ Wasp.Page.Page
{ Wasp.Page._name = "Landing"
, Wasp.Page._component = Wasp.JsImport.JsImport
{ Wasp.JsImport._defaultImport = Just "Landing"
, Wasp.JsImport._namedImports = []
, Wasp.JsImport._from = SP.fromPathRelFileP [PPosix.relfile|pages/Landing|]
}
, Wasp.Page._authRequired = Just False
2019-05-31 20:35:50 +03:00
}
, WaspElementRoute $ R.Route
{ R._urlPath = "/test"
, R._targetPage = "TestPage"
}
, WaspElementPage $ Wasp.Page.Page
{ Wasp.Page._name = "TestPage"
, Wasp.Page._component = Wasp.JsImport.JsImport
{ Wasp.JsImport._defaultImport = Just "Test"
, Wasp.JsImport._namedImports = []
, Wasp.JsImport._from = SP.fromPathRelFileP [PPosix.relfile|pages/Test|]
}
, Wasp.Page._authRequired = Nothing
}
2020-10-21 17:37:20 +03:00
, WaspElementEntity $ Wasp.Entity.Entity
{ Wasp.Entity._name = "Task"
, Wasp.Entity._pslModelSchema = "\
\id Int @id @default(autoincrement())\n\
\ description String\n\
\ isDone Boolean @default(false)"
}
2020-08-25 16:08:02 +03:00
, WaspElementQuery $ Wasp.Query.Query
{ Wasp.Query._name = "myQuery"
, Wasp.Query._jsFunction = Wasp.JsImport.JsImport
2020-08-25 16:55:37 +03:00
{ Wasp.JsImport._defaultImport = Nothing
, Wasp.JsImport._namedImports = [ "myJsQuery" ]
, Wasp.JsImport._from = SP.fromPathRelFileP [PPosix.relfile|some/path|]
2020-08-25 16:08:02 +03:00
}
, Wasp.Query._entities = Nothing
2020-08-25 16:08:02 +03:00
}
, WaspElementNpmDependencies $ Wasp.NpmDependencies.NpmDependencies
{ Wasp.NpmDependencies._dependencies =
[ ND.NpmDependency
{ ND._name = "lodash"
, ND._version = "^4.17.15"
}
]
}
]
`setJsImports` [ JsImport (Just "something") [] (SP.fromPathRelFileP [PPosix.relfile|some/file|]) ]
)