2019-04-19 16:22:14 +03:00
|
|
|
module Parser.ParserTest where
|
|
|
|
|
2020-09-23 15:34:24 +03:00
|
|
|
import Data.Either
|
2020-09-25 15:36:31 +03:00
|
|
|
import qualified Path.Posix as PPosix
|
2020-09-23 15:34:24 +03:00
|
|
|
import Test.Tasty.Hspec
|
2019-04-19 16:22:14 +03:00
|
|
|
|
2020-09-25 15:36:31 +03:00
|
|
|
import NpmDependency as ND
|
2020-09-23 15:34:24 +03:00
|
|
|
import Parser
|
2020-09-25 15:36:31 +03:00
|
|
|
import qualified StrongPath as SP
|
2020-09-23 15:34:24 +03:00
|
|
|
import Wasp
|
2020-10-21 17:37:20 +03:00
|
|
|
import qualified Wasp.Entity
|
2020-10-08 17:17:47 +03:00
|
|
|
import qualified Wasp.Auth
|
2020-08-25 16:08:02 +03:00
|
|
|
import qualified Wasp.JsImport
|
2020-09-25 15:36:31 +03:00
|
|
|
import qualified Wasp.NpmDependencies
|
2020-09-23 15:34:24 +03:00
|
|
|
import qualified Wasp.Page
|
|
|
|
import qualified Wasp.Query
|
2020-09-25 15:36:31 +03:00
|
|
|
import qualified Wasp.Route as R
|
2020-09-23 15:34:24 +03:00
|
|
|
|
2019-04-19 16:22:14 +03:00
|
|
|
spec_parseWasp :: Spec
|
2019-07-02 21:47:16 +03:00
|
|
|
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
|
2020-08-25 13:06:46 +03:00
|
|
|
it "When given a valid wasp source, should return correct Wasp" $ \wasp -> do
|
2019-04-19 16:22:14 +03:00
|
|
|
parseWasp wasp
|
|
|
|
`shouldBe`
|
2019-05-05 18:54:51 +03:00
|
|
|
Right (fromWaspElems
|
|
|
|
[ WaspElementApp $ App
|
|
|
|
{ appName = "test_app"
|
|
|
|
, appTitle = "Hello World!"
|
2021-02-04 13:42:01 +03:00
|
|
|
, appHead = Nothing
|
2019-05-05 18:54:51 +03:00
|
|
|
}
|
2020-10-08 17:17:47 +03:00
|
|
|
, WaspElementAuth $ Wasp.Auth.Auth
|
|
|
|
{ Wasp.Auth._userEntity = "User"
|
|
|
|
, Wasp.Auth._methods = [Wasp.Auth.EmailAndPassword]
|
2021-02-01 18:32:07 +03:00
|
|
|
, Wasp.Auth._onAuthFailedRedirectTo = "/test"
|
2020-10-08 17:17:47 +03:00
|
|
|
}
|
2020-07-31 15:26:10 +03:00
|
|
|
, WaspElementRoute $ R.Route
|
|
|
|
{ R._urlPath = "/"
|
|
|
|
, R._targetPage = "Landing"
|
|
|
|
}
|
2020-08-04 14:02:34 +03:00
|
|
|
, WaspElementPage $ Wasp.Page.Page
|
|
|
|
{ Wasp.Page._name = "Landing"
|
|
|
|
, Wasp.Page._component = Wasp.JsImport.JsImport
|
|
|
|
{ Wasp.JsImport._defaultImport = Just "Landing"
|
|
|
|
, Wasp.JsImport._namedImports = []
|
2020-09-23 15:34:24 +03:00
|
|
|
, Wasp.JsImport._from = SP.fromPathRelFileP [PPosix.relfile|pages/Landing|]
|
2020-08-04 14:02:34 +03:00
|
|
|
}
|
2021-02-01 18:32:07 +03:00
|
|
|
, Wasp.Page._authRequired = Just False
|
2019-05-31 20:35:50 +03:00
|
|
|
}
|
2020-07-31 15:26:10 +03:00
|
|
|
, WaspElementRoute $ R.Route
|
|
|
|
{ R._urlPath = "/test"
|
|
|
|
, R._targetPage = "TestPage"
|
|
|
|
}
|
2020-08-04 14:02:34 +03:00
|
|
|
, WaspElementPage $ Wasp.Page.Page
|
|
|
|
{ Wasp.Page._name = "TestPage"
|
|
|
|
, Wasp.Page._component = Wasp.JsImport.JsImport
|
|
|
|
{ Wasp.JsImport._defaultImport = Just "Test"
|
|
|
|
, Wasp.JsImport._namedImports = []
|
2020-09-23 15:34:24 +03:00
|
|
|
, Wasp.JsImport._from = SP.fromPathRelFileP [PPosix.relfile|pages/Test|]
|
2020-08-04 14:02:34 +03:00
|
|
|
}
|
2021-02-01 18:32:07 +03:00
|
|
|
, Wasp.Page._authRequired = Nothing
|
2019-05-05 18:54:51 +03:00
|
|
|
}
|
2020-10-21 17:37:20 +03:00
|
|
|
, WaspElementEntity $ Wasp.Entity.Entity
|
|
|
|
{ Wasp.Entity._name = "Task"
|
|
|
|
, Wasp.Entity._pslModelSchema = "\
|
2020-09-04 15:21:47 +03:00
|
|
|
\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" ]
|
2020-09-23 15:34:24 +03:00
|
|
|
, Wasp.JsImport._from = SP.fromPathRelFileP [PPosix.relfile|some/path|]
|
2020-08-25 16:08:02 +03:00
|
|
|
}
|
2020-09-30 22:16:41 +03:00
|
|
|
, Wasp.Query._entities = Nothing
|
2020-08-25 16:08:02 +03:00
|
|
|
}
|
2020-09-25 15:36:31 +03:00
|
|
|
, WaspElementNpmDependencies $ Wasp.NpmDependencies.NpmDependencies
|
|
|
|
{ Wasp.NpmDependencies._dependencies =
|
|
|
|
[ ND.NpmDependency
|
|
|
|
{ ND._name = "lodash"
|
|
|
|
, ND._version = "^4.17.15"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2019-05-05 18:54:51 +03:00
|
|
|
]
|
2020-09-23 15:34:24 +03:00
|
|
|
`setJsImports` [ JsImport (Just "something") [] (SP.fromPathRelFileP [PPosix.relfile|some/file|]) ]
|
2019-05-05 18:54:51 +03:00
|
|
|
)
|