2019-10-22 05:11:50 +03:00
|
|
|
module StaticHttpRequestsTests exposing (all)
|
2019-10-22 04:49:46 +03:00
|
|
|
|
2019-10-22 08:00:15 +03:00
|
|
|
import Codec
|
2019-10-22 16:46:31 +03:00
|
|
|
import Dict exposing (Dict)
|
2019-10-22 06:21:52 +03:00
|
|
|
import Expect
|
2019-10-22 04:49:46 +03:00
|
|
|
import Html
|
|
|
|
import Json.Decode as Decode
|
2019-11-03 21:07:20 +03:00
|
|
|
import Json.Decode.Exploration as Reduce
|
2019-10-22 04:49:46 +03:00
|
|
|
import Pages.ContentCache as ContentCache
|
|
|
|
import Pages.Document as Document
|
|
|
|
import Pages.ImagePath as ImagePath
|
2019-10-22 05:31:17 +03:00
|
|
|
import Pages.Internal.Platform.Cli as Main exposing (..)
|
2019-11-02 21:13:33 +03:00
|
|
|
import Pages.Internal.Secrets
|
2019-10-22 04:49:46 +03:00
|
|
|
import Pages.Manifest as Manifest
|
|
|
|
import Pages.PagePath as PagePath
|
|
|
|
import ProgramTest exposing (ProgramTest)
|
2019-11-03 00:46:52 +03:00
|
|
|
import Regex
|
2019-10-24 18:26:41 +03:00
|
|
|
import Secrets exposing (Secrets)
|
2019-10-22 05:31:17 +03:00
|
|
|
import SimulatedEffect.Cmd
|
|
|
|
import SimulatedEffect.Http
|
2019-10-22 06:21:52 +03:00
|
|
|
import SimulatedEffect.Ports
|
2019-10-24 06:45:26 +03:00
|
|
|
import StaticHttp
|
2019-11-02 23:14:09 +03:00
|
|
|
import TerminalText as Terminal
|
2019-10-22 18:31:36 +03:00
|
|
|
import Test exposing (Test, describe, only, test)
|
2019-11-02 21:13:33 +03:00
|
|
|
import Test.Http
|
2019-10-22 05:11:50 +03:00
|
|
|
|
|
|
|
|
|
|
|
all : Test
|
|
|
|
all =
|
2019-10-22 16:46:31 +03:00
|
|
|
describe "Static Http Requests"
|
|
|
|
[ test "initial requests are sent out" <|
|
2019-10-22 05:11:50 +03:00
|
|
|
\() ->
|
2019-10-24 15:52:24 +03:00
|
|
|
start
|
|
|
|
[ ( []
|
2019-10-28 17:57:21 +03:00
|
|
|
, StaticHttp.jsonRequest "https://api.github.com/repos/dillonkearns/elm-pages" (Decode.succeed ())
|
2019-10-24 15:52:24 +03:00
|
|
|
)
|
|
|
|
]
|
2019-10-22 05:56:48 +03:00
|
|
|
|> ProgramTest.simulateHttpOk
|
|
|
|
"GET"
|
|
|
|
"https://api.github.com/repos/dillonkearns/elm-pages"
|
2019-10-22 22:43:26 +03:00
|
|
|
"""{ "stargazer_count": 86 }"""
|
2019-10-22 08:00:15 +03:00
|
|
|
|> ProgramTest.expectOutgoingPortValues
|
2019-10-22 06:21:52 +03:00
|
|
|
"toJsPort"
|
2019-10-22 08:00:15 +03:00
|
|
|
(Codec.decoder Main.toJsCodec)
|
|
|
|
(Expect.equal
|
|
|
|
[ Main.Success
|
|
|
|
{ pages =
|
|
|
|
Dict.fromList
|
|
|
|
[ ( "/"
|
|
|
|
, Dict.fromList
|
2019-10-22 22:43:26 +03:00
|
|
|
[ ( "https://api.github.com/repos/dillonkearns/elm-pages"
|
|
|
|
, """{ "stargazer_count": 86 }"""
|
|
|
|
)
|
2019-10-22 08:00:15 +03:00
|
|
|
]
|
|
|
|
)
|
|
|
|
]
|
2019-10-22 09:02:31 +03:00
|
|
|
, manifest = manifest
|
2019-10-22 08:00:15 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2019-11-01 23:29:09 +03:00
|
|
|
, test "andThen" <|
|
|
|
|
\() ->
|
|
|
|
start
|
|
|
|
[ ( [ "elm-pages" ]
|
2019-11-02 02:46:12 +03:00
|
|
|
, StaticHttp.jsonRequest "https://api.github.com/repos/dillonkearns/elm-pages" (Decode.succeed ())
|
2019-11-01 23:29:09 +03:00
|
|
|
|> StaticHttp.andThen
|
|
|
|
(\continueUrl ->
|
|
|
|
StaticHttp.jsonRequest "NEXT-REQUEST" (Decode.succeed ())
|
|
|
|
)
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|> ProgramTest.simulateHttpOk
|
|
|
|
"GET"
|
|
|
|
"https://api.github.com/repos/dillonkearns/elm-pages"
|
|
|
|
"""null"""
|
|
|
|
|> ProgramTest.simulateHttpOk
|
|
|
|
"GET"
|
|
|
|
"NEXT-REQUEST"
|
|
|
|
"""null"""
|
|
|
|
|> ProgramTest.expectOutgoingPortValues
|
|
|
|
"toJsPort"
|
|
|
|
(Codec.decoder Main.toJsCodec)
|
|
|
|
(Expect.equal
|
|
|
|
[ Main.Success
|
|
|
|
{ pages =
|
|
|
|
Dict.fromList
|
|
|
|
[ ( "/elm-pages"
|
|
|
|
, Dict.fromList
|
|
|
|
[ ( "https://api.github.com/repos/dillonkearns/elm-pages"
|
|
|
|
, """null"""
|
|
|
|
)
|
|
|
|
, ( "NEXT-REQUEST"
|
|
|
|
, """null"""
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
, manifest = manifest
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2019-10-22 18:42:17 +03:00
|
|
|
, test "port is sent out once all requests are finished" <|
|
|
|
|
\() ->
|
|
|
|
start
|
2019-10-24 15:52:24 +03:00
|
|
|
[ ( [ "elm-pages" ]
|
2019-10-28 17:57:21 +03:00
|
|
|
, StaticHttp.jsonRequest "https://api.github.com/repos/dillonkearns/elm-pages" (Decode.succeed ())
|
2019-10-24 15:52:24 +03:00
|
|
|
)
|
|
|
|
, ( [ "elm-pages-starter" ]
|
2019-10-28 17:57:21 +03:00
|
|
|
, StaticHttp.jsonRequest "https://api.github.com/repos/dillonkearns/elm-pages-starter" (Decode.succeed ())
|
2019-10-24 15:52:24 +03:00
|
|
|
)
|
2019-10-22 18:42:17 +03:00
|
|
|
]
|
|
|
|
|> ProgramTest.simulateHttpOk
|
|
|
|
"GET"
|
|
|
|
"https://api.github.com/repos/dillonkearns/elm-pages"
|
2019-10-22 22:43:26 +03:00
|
|
|
"""{ "stargazer_count": 86 }"""
|
2019-10-22 18:42:17 +03:00
|
|
|
|> ProgramTest.simulateHttpOk
|
|
|
|
"GET"
|
|
|
|
"https://api.github.com/repos/dillonkearns/elm-pages-starter"
|
2019-10-22 22:43:26 +03:00
|
|
|
"""{ "stargazer_count": 22 }"""
|
2019-10-22 18:42:17 +03:00
|
|
|
|> ProgramTest.expectOutgoingPortValues
|
|
|
|
"toJsPort"
|
|
|
|
(Codec.decoder Main.toJsCodec)
|
|
|
|
(Expect.equal
|
|
|
|
[ Main.Success
|
|
|
|
{ pages =
|
|
|
|
Dict.fromList
|
|
|
|
[ ( "/elm-pages"
|
|
|
|
, Dict.fromList
|
2019-10-22 22:43:26 +03:00
|
|
|
[ ( "https://api.github.com/repos/dillonkearns/elm-pages"
|
|
|
|
, """{ "stargazer_count": 86 }"""
|
|
|
|
)
|
2019-10-22 18:42:17 +03:00
|
|
|
]
|
|
|
|
)
|
|
|
|
, ( "/elm-pages-starter"
|
|
|
|
, Dict.fromList
|
2019-10-22 22:43:26 +03:00
|
|
|
[ ( "https://api.github.com/repos/dillonkearns/elm-pages-starter"
|
|
|
|
, """{ "stargazer_count": 22 }"""
|
|
|
|
)
|
2019-10-22 18:42:17 +03:00
|
|
|
]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
, manifest = manifest
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2019-11-05 00:05:12 +03:00
|
|
|
, test "reduced JSON is sent out" <|
|
|
|
|
\() ->
|
|
|
|
start
|
|
|
|
[ ( []
|
|
|
|
, StaticHttp.reducedJsonRequest "https://api.github.com/repos/dillonkearns/elm-pages" (Reduce.field "stargazer_count" Reduce.int)
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|> ProgramTest.simulateHttpOk
|
|
|
|
"GET"
|
|
|
|
"https://api.github.com/repos/dillonkearns/elm-pages"
|
|
|
|
"""{ "stargazer_count": 86, "unused_field": 123 }"""
|
|
|
|
|> ProgramTest.expectOutgoingPortValues
|
|
|
|
"toJsPort"
|
|
|
|
(Codec.decoder Main.toJsCodec)
|
|
|
|
(Expect.equal
|
|
|
|
[ Main.Success
|
|
|
|
{ pages =
|
|
|
|
Dict.fromList
|
|
|
|
[ ( "/"
|
|
|
|
, Dict.fromList
|
|
|
|
[ ( "https://api.github.com/repos/dillonkearns/elm-pages"
|
|
|
|
, """{"stargazer_count":86}"""
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
, manifest = manifest
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2019-10-28 18:04:34 +03:00
|
|
|
, test "the port sends out even if there are no http requests" <|
|
|
|
|
\() ->
|
|
|
|
start
|
|
|
|
[ ( []
|
|
|
|
, StaticHttp.succeed ()
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|> ProgramTest.expectOutgoingPortValues
|
|
|
|
"toJsPort"
|
|
|
|
(Codec.decoder Main.toJsCodec)
|
|
|
|
(Expect.equal
|
|
|
|
[ Main.Success
|
|
|
|
{ pages =
|
|
|
|
Dict.fromList
|
|
|
|
[ ( "/"
|
|
|
|
, Dict.fromList []
|
|
|
|
)
|
|
|
|
]
|
|
|
|
, manifest = manifest
|
2019-10-30 07:45:23 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
|
|
|
, test "the port sends out when there are duplicate http requests for the same page" <|
|
|
|
|
\() ->
|
|
|
|
start
|
|
|
|
[ ( []
|
|
|
|
, StaticHttp.map2 (\_ _ -> ())
|
|
|
|
(StaticHttp.jsonRequest "http://example.com" (Decode.succeed ()))
|
|
|
|
(StaticHttp.jsonRequest "http://example.com" (Decode.succeed ()))
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|> ProgramTest.simulateHttpOk
|
|
|
|
"GET"
|
|
|
|
"http://example.com"
|
|
|
|
"""null"""
|
|
|
|
|> ProgramTest.expectOutgoingPortValues
|
|
|
|
"toJsPort"
|
|
|
|
(Codec.decoder Main.toJsCodec)
|
|
|
|
(Expect.equal
|
|
|
|
[ Main.Success
|
|
|
|
{ pages =
|
|
|
|
Dict.fromList
|
|
|
|
[ ( "/"
|
|
|
|
, Dict.fromList [ ( "http://example.com", "null" ) ]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
, manifest = manifest
|
2019-10-28 18:04:34 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2019-10-24 15:52:24 +03:00
|
|
|
, test "an error is sent out for decoder failures" <|
|
|
|
|
\() ->
|
|
|
|
start
|
2019-10-28 17:57:21 +03:00
|
|
|
[ ( [ "elm-pages" ]
|
|
|
|
, StaticHttp.jsonRequest "https://api.github.com/repos/dillonkearns/elm-pages" (Decode.fail "The user should get this message from the CLI.")
|
|
|
|
)
|
2019-10-24 15:52:24 +03:00
|
|
|
]
|
|
|
|
|> ProgramTest.simulateHttpOk
|
|
|
|
"GET"
|
|
|
|
"https://api.github.com/repos/dillonkearns/elm-pages"
|
|
|
|
"""{ "stargazer_count": 86 }"""
|
|
|
|
|> ProgramTest.expectOutgoingPortValues
|
|
|
|
"toJsPort"
|
|
|
|
(Codec.decoder Main.toJsCodec)
|
|
|
|
(Expect.equal
|
2019-10-24 16:11:56 +03:00
|
|
|
[ Errors
|
2019-10-30 08:33:47 +03:00
|
|
|
"""\u{001B}[36m-- FAILED STATIC HTTP ERROR ----------------------------------------------------- elm-pages\u{001B}[0m
|
|
|
|
|
|
|
|
/elm-pages
|
2019-10-27 02:50:09 +03:00
|
|
|
|
|
|
|
Problem with the given value:
|
|
|
|
|
2019-11-02 21:13:33 +03:00
|
|
|
{
|
|
|
|
"stargazer_count": 86
|
|
|
|
}
|
|
|
|
|
|
|
|
The user should get this message from the CLI."""
|
|
|
|
]
|
|
|
|
)
|
2019-11-03 00:17:32 +03:00
|
|
|
, test "an error is sent for missing secrets from continuation requests" <|
|
|
|
|
\() ->
|
|
|
|
start
|
|
|
|
[ ( [ "elm-pages" ]
|
|
|
|
, StaticHttp.jsonRequestWithSecrets
|
|
|
|
(\secrets ->
|
|
|
|
secrets
|
|
|
|
|> Secrets.get "API_KEY"
|
|
|
|
|> Result.map
|
|
|
|
(\apiKey ->
|
|
|
|
"https://api.github.com/repos/dillonkearns/elm-pages?apiKey=" ++ apiKey
|
|
|
|
)
|
|
|
|
)
|
|
|
|
Decode.string
|
|
|
|
|> StaticHttp.andThen
|
|
|
|
(\url ->
|
|
|
|
StaticHttp.jsonRequestWithSecrets
|
|
|
|
(\secrets ->
|
|
|
|
secrets
|
|
|
|
|> Secrets.get "MISSING"
|
|
|
|
|> Result.map
|
|
|
|
(\missingSecret ->
|
|
|
|
url ++ "?apiKey=" ++ missingSecret
|
|
|
|
)
|
|
|
|
)
|
|
|
|
(Decode.succeed ())
|
|
|
|
)
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|> ProgramTest.simulateHttpOk
|
|
|
|
"GET"
|
|
|
|
"https://api.github.com/repos/dillonkearns/elm-pages?apiKey=ABCD1234"
|
|
|
|
""" "continuation-url" """
|
|
|
|
|> ProgramTest.expectOutgoingPortValues
|
|
|
|
"toJsPort"
|
|
|
|
(Codec.decoder Main.toJsCodec)
|
2019-11-03 00:46:52 +03:00
|
|
|
(expectErrorsPort
|
|
|
|
"""-- MISSING SECRET ----------------------------------------------------- elm-pages
|
|
|
|
|
|
|
|
I expected to find this Secret in your environment variables but didn't find a match:
|
|
|
|
|
|
|
|
Secrets.get "MISSING"
|
|
|
|
^^^^^^^
|
|
|
|
|
|
|
|
So maybe MISSING should be API_KEY"""
|
2019-11-03 00:17:32 +03:00
|
|
|
)
|
2019-11-02 21:13:33 +03:00
|
|
|
, test "an error is sent for HTTP errors" <|
|
|
|
|
\() ->
|
|
|
|
start
|
|
|
|
[ ( []
|
|
|
|
, StaticHttp.jsonRequest "https://api.github.com/repos/dillonkearns/elm-pages" (Decode.succeed ())
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|> ProgramTest.simulateHttpResponse
|
|
|
|
"GET"
|
|
|
|
"https://api.github.com/repos/dillonkearns/elm-pages"
|
|
|
|
(Test.Http.httpResponse
|
|
|
|
{ statusCode = 404
|
|
|
|
, headers = []
|
|
|
|
, body = ""
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|> ProgramTest.expectOutgoingPortValues
|
|
|
|
"toJsPort"
|
|
|
|
(Codec.decoder Main.toJsCodec)
|
|
|
|
(Expect.equal
|
2019-11-02 23:14:09 +03:00
|
|
|
[ Errors <|
|
|
|
|
Terminal.toString
|
|
|
|
[ Terminal.cyan <| Terminal.text "-- FAILED STATIC HTTP ERROR ----------------------------------------------------- elm-pages"
|
|
|
|
, Terminal.text "\n\nI got an error making an HTTP request to this URL: "
|
|
|
|
, Terminal.yellow <| Terminal.text "https://api.github.com/repos/dillonkearns/elm-pages"
|
|
|
|
, Terminal.text "\n\nBad status: 404"
|
|
|
|
]
|
2019-10-24 15:52:24 +03:00
|
|
|
]
|
|
|
|
)
|
2019-10-24 18:26:41 +03:00
|
|
|
, test "uses real secrets to perform request and masked secrets to store and lookup response" <|
|
|
|
|
\() ->
|
|
|
|
start
|
|
|
|
[ ( []
|
2019-10-28 17:57:21 +03:00
|
|
|
, StaticHttp.jsonRequestWithSecrets
|
|
|
|
(\secrets ->
|
2019-10-24 18:26:41 +03:00
|
|
|
secrets
|
|
|
|
|> Secrets.get "API_KEY"
|
|
|
|
|> Result.map
|
|
|
|
(\apiKey ->
|
|
|
|
"https://api.github.com/repos/dillonkearns/elm-pages?apiKey=" ++ apiKey
|
|
|
|
)
|
2019-10-28 17:57:21 +03:00
|
|
|
)
|
|
|
|
(Decode.succeed ())
|
2019-10-24 18:26:41 +03:00
|
|
|
)
|
|
|
|
]
|
|
|
|
|> ProgramTest.simulateHttpOk
|
|
|
|
"GET"
|
|
|
|
"https://api.github.com/repos/dillonkearns/elm-pages?apiKey=ABCD1234"
|
|
|
|
"""{ "stargazer_count": 86 }"""
|
|
|
|
|> ProgramTest.expectOutgoingPortValues
|
|
|
|
"toJsPort"
|
|
|
|
(Codec.decoder Main.toJsCodec)
|
|
|
|
(Expect.equal
|
|
|
|
[ Main.Success
|
|
|
|
{ pages =
|
|
|
|
Dict.fromList
|
|
|
|
[ ( "/"
|
|
|
|
, Dict.fromList
|
|
|
|
[ ( "https://api.github.com/repos/dillonkearns/elm-pages?apiKey=<API_KEY>"
|
|
|
|
, """{ "stargazer_count": 86 }"""
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
, manifest = manifest
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2019-10-22 05:11:50 +03:00
|
|
|
]
|
2019-10-22 04:49:46 +03:00
|
|
|
|
|
|
|
|
2019-10-28 17:57:21 +03:00
|
|
|
start : List ( List String, StaticHttp.Request a ) -> ProgramTest Main.Model Main.Msg (Main.Effect PathKey)
|
2019-10-22 16:46:31 +03:00
|
|
|
start pages =
|
2019-10-22 04:49:46 +03:00
|
|
|
let
|
|
|
|
document =
|
2019-10-22 05:56:48 +03:00
|
|
|
Document.fromList
|
|
|
|
[ Document.parser
|
|
|
|
{ extension = "md"
|
|
|
|
, metadata = Decode.succeed ()
|
|
|
|
, body = \_ -> Ok ()
|
|
|
|
}
|
|
|
|
]
|
2019-10-22 04:49:46 +03:00
|
|
|
|
|
|
|
content =
|
2019-10-22 16:46:31 +03:00
|
|
|
pages
|
|
|
|
|> List.map
|
|
|
|
(\( path, _ ) ->
|
|
|
|
( path, { extension = "md", frontMatter = "null", body = Just "" } )
|
|
|
|
)
|
2019-10-22 04:49:46 +03:00
|
|
|
|
|
|
|
contentCache =
|
|
|
|
ContentCache.init document content
|
|
|
|
|
|
|
|
siteMetadata =
|
|
|
|
contentCache
|
|
|
|
|> Result.map
|
|
|
|
(\cache -> cache |> ContentCache.extractMetadata PathKey)
|
2019-10-29 22:37:28 +03:00
|
|
|
|> Result.mapError (List.map Tuple.second)
|
2019-10-22 04:49:46 +03:00
|
|
|
|
|
|
|
config =
|
|
|
|
{ toJsPort = toJsPort
|
|
|
|
, manifest = manifest
|
|
|
|
, view =
|
|
|
|
\allFrontmatter page ->
|
2019-10-22 16:46:31 +03:00
|
|
|
let
|
2019-10-24 15:52:24 +03:00
|
|
|
thing =
|
2019-10-22 16:46:31 +03:00
|
|
|
pages
|
|
|
|
|> Dict.fromList
|
|
|
|
|> Dict.get
|
|
|
|
(page.path
|
|
|
|
|> PagePath.toString
|
|
|
|
|> String.dropLeft 1
|
|
|
|
|> String.split "/"
|
|
|
|
|> List.filter (\pathPart -> pathPart /= "")
|
|
|
|
)
|
|
|
|
in
|
2019-10-24 15:52:24 +03:00
|
|
|
case thing of
|
2019-10-28 17:57:21 +03:00
|
|
|
Just request ->
|
|
|
|
request
|
2019-10-24 15:52:24 +03:00
|
|
|
|> StaticHttp.map
|
|
|
|
(\staticData -> { view = \model viewForPage -> { title = "Title", body = Html.text "" }, head = [] })
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
Debug.todo "Couldn't find page"
|
2019-10-22 04:49:46 +03:00
|
|
|
}
|
|
|
|
in
|
|
|
|
ProgramTest.createDocument
|
|
|
|
{ init = Main.init identity contentCache siteMetadata config identity
|
|
|
|
, update = Main.update siteMetadata config
|
2019-10-25 17:00:04 +03:00
|
|
|
, view = \_ -> { title = "", body = [] }
|
2019-10-22 04:49:46 +03:00
|
|
|
}
|
2019-10-22 05:31:17 +03:00
|
|
|
|> ProgramTest.withSimulatedEffects simulateEffects
|
2019-10-24 18:26:41 +03:00
|
|
|
|> ProgramTest.start (flags """{"secrets":
|
|
|
|
{"API_KEY": "ABCD1234"}
|
|
|
|
}""")
|
|
|
|
|
|
|
|
|
|
|
|
flags : String -> Decode.Value
|
|
|
|
flags jsonString =
|
|
|
|
case Decode.decodeString Decode.value jsonString of
|
|
|
|
Ok value ->
|
|
|
|
value
|
|
|
|
|
|
|
|
Err _ ->
|
|
|
|
Debug.todo "Invalid JSON value."
|
2019-10-22 04:49:46 +03:00
|
|
|
|
|
|
|
|
2019-10-22 09:02:31 +03:00
|
|
|
simulateEffects : Main.Effect PathKey -> ProgramTest.SimulatedEffect Main.Msg
|
2019-10-22 05:31:17 +03:00
|
|
|
simulateEffects effect =
|
|
|
|
case effect of
|
|
|
|
NoEffect ->
|
|
|
|
SimulatedEffect.Cmd.none
|
|
|
|
|
|
|
|
SendJsData value ->
|
2019-10-22 08:00:15 +03:00
|
|
|
SimulatedEffect.Ports.send "toJsPort" (value |> Codec.encoder Main.toJsCodec)
|
2019-10-22 05:31:17 +03:00
|
|
|
|
|
|
|
-- toJsPort value |> Cmd.map never
|
|
|
|
Batch list ->
|
|
|
|
list
|
|
|
|
|> List.map simulateEffects
|
|
|
|
|> SimulatedEffect.Cmd.batch
|
|
|
|
|
2019-11-02 21:13:33 +03:00
|
|
|
FetchHttp secureUrl ->
|
|
|
|
let
|
|
|
|
{ masked, unmasked } =
|
|
|
|
Pages.Internal.Secrets.unwrap secureUrl
|
|
|
|
in
|
2019-10-22 05:31:17 +03:00
|
|
|
SimulatedEffect.Http.get
|
2019-11-02 21:13:33 +03:00
|
|
|
{ url = unmasked
|
2019-10-22 05:31:17 +03:00
|
|
|
, expect =
|
|
|
|
SimulatedEffect.Http.expectString
|
|
|
|
(\response ->
|
2019-10-24 17:06:50 +03:00
|
|
|
GotStaticHttpResponse
|
2019-11-02 21:13:33 +03:00
|
|
|
{ url = masked
|
2019-10-22 05:31:17 +03:00
|
|
|
, response = response
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-03 00:46:52 +03:00
|
|
|
expectErrorsPort expectedPlainString actualPorts =
|
|
|
|
case actualPorts of
|
|
|
|
[ Errors actualRichTerminalString ] ->
|
|
|
|
let
|
|
|
|
actualPlainString =
|
|
|
|
actualRichTerminalString
|
|
|
|
|> Regex.replace
|
|
|
|
(Regex.fromString "\u{001B}\\[[0-9;]+m"
|
|
|
|
|> Maybe.withDefault Regex.never
|
|
|
|
)
|
|
|
|
(\_ -> "")
|
|
|
|
in
|
|
|
|
actualPlainString |> Expect.equal expectedPlainString
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
Expect.fail "Expected single error port"
|
|
|
|
|
|
|
|
|
2019-10-22 04:49:46 +03:00
|
|
|
toJsPort foo =
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
|
|
|
type PathKey
|
|
|
|
= PathKey
|
|
|
|
|
|
|
|
|
|
|
|
manifest : Manifest.Config PathKey
|
|
|
|
manifest =
|
|
|
|
{ backgroundColor = Nothing
|
|
|
|
, categories = []
|
|
|
|
, displayMode = Manifest.Standalone
|
|
|
|
, orientation = Manifest.Portrait
|
|
|
|
, description = "elm-pages - A statically typed site generator."
|
|
|
|
, iarcRatingId = Nothing
|
|
|
|
, name = "elm-pages docs"
|
|
|
|
, themeColor = Nothing
|
2019-10-22 09:02:31 +03:00
|
|
|
, startUrl = PagePath.external ""
|
2019-10-22 04:49:46 +03:00
|
|
|
, shortName = Just "elm-pages"
|
2019-10-22 09:02:31 +03:00
|
|
|
, sourceIcon = ImagePath.external ""
|
2019-10-22 04:49:46 +03:00
|
|
|
}
|