Wire through new Secrets API.

This commit is contained in:
Dillon Kearns 2019-11-11 12:40:38 -08:00
parent 2963598592
commit 45d5ce8e89
8 changed files with 278 additions and 148 deletions

View File

@ -10,7 +10,8 @@ import Head
import Head.Seo as Seo
import Html exposing (Html)
import Html.Attributes as Attr
import Json.Decode as Decode exposing (Decoder)
import Json.Decode as JD exposing (Decoder)
import Json.Decode.Exploration as Decode
import Pages exposing (images, pages)
import Pages.Directory as Directory exposing (Directory)
import Pages.Document
@ -67,7 +68,7 @@ markdownDocument : ( String, Pages.Document.DocumentHandler Metadata () )
markdownDocument =
Pages.Document.parser
{ extension = "md"
, metadata = Decode.succeed ()
, metadata = JD.succeed ()
, body = \_ -> Ok ()
}
@ -116,30 +117,31 @@ companyView company =
]
airtableRequest : StaticHttp.Request (List Company)
airtableRequest =
StaticHttp.jsonRequestWithSecrets
(\secrets ->
secrets
|> Secrets.get "AIRTABLE_API_KEY"
|> Result.map
(\airtableApiKey ->
"https://api.airtable.com/v0/appNsAv2iE9mFm56N/Table%201?view=Approved&api_key=" ++ airtableApiKey
)
)
(Decode.field "records"
(Decode.list
(Decode.field "fields"
(Decode.map3 Company
(Decode.field "Company Name" Decode.string)
(Decode.field "Company Logo" (Decode.index 0 (Decode.field "url" Decode.string)))
(Decode.field "Significant lines of Elm code (in thousands)"
(Decode.index 0 Decode.string)
)
)
)
)
)
--airtableRequest : StaticHttp.Request (List Company)
--airtableRequest =
-- StaticHttp.getWithSecrets
-- (\secrets ->
-- secrets
-- |> Secrets.get "AIRTABLE_API_KEY"
-- |> Result.map
-- (\airtableApiKey ->
-- "https://api.airtable.com/v0/appNsAv2iE9mFm56N/Table%201?view=Approved&api_key=" ++ airtableApiKey
-- )
-- )
-- (Decode.field "records"
-- (Decode.list
-- (Decode.field "fields"
-- (Decode.map3 Company
-- (Decode.field "Company Name" Decode.string)
-- (Decode.field "Company Logo" (Decode.index 0 (Decode.field "url" Decode.string)))
-- (Decode.field "Significant lines of Elm code (in thousands)"
-- (Decode.index 0 Decode.string)
-- )
-- )
-- )
-- )
-- )
view :
@ -156,17 +158,19 @@ view :
view siteMetadata page =
case page.frontmatter of
() ->
StaticHttp.map3
(\elmCompanies forks starCount ->
-- StaticHttp.map3
-- (\elmCompanies forks starCount ->
StaticHttp.map
(\starCount ->
{ view =
\model viewForPage ->
{ title = "Landing Page"
, body =
(header starCount
:: [ forks
|> List.map (\forkName -> Element.row [] [ Element.text forkName ])
|> Element.column [ Element.spacing 15, Element.centerX, Element.padding 20 ]
]
([ header starCount ]
-- :: [ forks
-- |> List.map (\forkName -> Element.row [] [ Element.text forkName ])
-- |> Element.column [ Element.spacing 15, Element.centerX, Element.padding 20 ]
-- ]
-- (elmCompanies
-- |> List.map companyView
-- )
@ -177,19 +181,25 @@ view siteMetadata page =
, head = head page.frontmatter
}
)
airtableRequest
(StaticHttp.jsonRequest "https://api.github.com/repos/dillonkearns/elm-pages"
(Decode.field "forks_url" Decode.string)
|> StaticHttp.andThen
(\forksUrl ->
StaticHttp.jsonRequest forksUrl (Decode.list (Decode.field "full_name" Decode.string))
)
)
(StaticHttp.jsonRequest "https://api.github.com/repos/dillonkearns/elm-pages"
-- airtableRequest
-- (StaticHttp.get "https://api.github.com/repos/dillonkearns/elm-pages"
-- (Decode.field "forks_url" Decode.string)
-- |> StaticHttp.andThen
-- (\forksUrl ->
-- StaticHttp.jsonRequest forksUrl (Decode.list (Decode.field "full_name" Decode.string))
-- )
-- )
(StaticHttp.reducedGet "https://api.github.com/repos/dillonkearns/elm-pages"
(Decode.field "stargazers_count" Decode.int)
)
-- (StaticHttp.get "https://api.github.com/repos/dillonkearns/elm-pages"
-- (JD.field "stargazers_count" JD.int)
-- )
layout body =
body
|> Element.layout

View File

@ -29,11 +29,13 @@ import Mark
import Pages.ContentCache as ContentCache exposing (ContentCache)
import Pages.Document
import Pages.ImagePath as ImagePath
import Pages.Internal.Secrets exposing (RequestDetails)
import Pages.Internal.Secrets as StaticHttpRequest exposing (RequestDetails)
import Pages.Manifest as Manifest
import Pages.PagePath as PagePath exposing (PagePath)
import Pages.StaticHttpRequest as StaticHttpRequest
import Secrets exposing (Secrets)
import Secrets2
import SecretsDict exposing (SecretsDict)
import Set exposing (Set)
import StaticHttp
import TerminalText as Terminal
@ -100,7 +102,7 @@ successCodec =
type Effect pathKey
= NoEffect
| SendJsData (ToJsPayload pathKey)
| FetchHttp Pages.Internal.Secrets.Url
| FetchHttp { masked : StaticHttpRequest.RequestDetails, unmasked : StaticHttpRequest.RequestDetails }
| Batch (List (Effect pathKey))
@ -121,14 +123,14 @@ type alias Flags =
type alias Model =
{ staticResponses : StaticResponses
, secrets : Secrets
, secrets : SecretsDict
, errors : List Error
, allRawResponses : Dict String (Maybe String)
}
type Error
= MissingSecret BuildError
= MissingSecrets (List BuildError)
| MetadataDecodeError BuildError
| InternalError BuildError
| FailedStaticHttpRequestError BuildError
@ -235,10 +237,23 @@ perform cliMsgConstructor toJsPort effect =
|> List.map (perform cliMsgConstructor toJsPort)
|> Cmd.batch
FetchHttp secureUrl ->
Pages.Internal.Secrets.get secureUrl
-- TODO send info needed for hash here (RequestDetails)
(GotStaticHttpResponse >> cliMsgConstructor)
FetchHttp { unmasked, masked } ->
Http.request
{ method = unmasked.method
, url = unmasked.url
, headers = []
, body = Http.emptyBody
, expect =
Http.expectString
(\response ->
(GotStaticHttpResponse >> cliMsgConstructor)
{ request = masked
, response = response
}
)
, timeout = Nothing
, tracker = Nothing
}
init :
@ -264,7 +279,7 @@ init :
-> Decode.Value
-> ( model, Effect pathKey )
init toModel contentCache siteMetadata config cliMsgConstructor flags =
case Decode.decodeValue (Decode.field "secrets" Pages.Internal.Secrets.decoder) flags of
case Decode.decodeValue (Decode.field "secrets" SecretsDict.decoder) flags of
Ok secrets ->
case contentCache of
Ok _ ->
@ -373,7 +388,7 @@ init toModel contentCache siteMetadata config cliMsgConstructor flags =
Err error ->
updateAndSendPortIfDone
(Model Dict.empty
Pages.Internal.Secrets.empty
SecretsDict.masked
[ InternalError <| { message = [ Terminal.text <| "Failed to parse flags: " ++ Decode.errorToString error ] }
]
Dict.empty
@ -504,7 +519,11 @@ dictCompact dict =
|> Dict.Extra.filterMap (\key value -> value)
performStaticHttpRequests : Dict String (Maybe String) -> Secrets -> List ( String, StaticHttp.Request a ) -> Result (List Error) (List Pages.Internal.Secrets.Url)
--performStaticHttpRequests : Dict String (Maybe String) -> SecretsDict -> List ( String, StaticHttp.Request a ) -> Result (List Error) (List Pages.Internal.Secrets.Url)
performStaticHttpRequests : Dict String (Maybe String) -> SecretsDict -> List ( String, StaticHttp.Request a ) -> Result (List Error) (List { unmasked : StaticHttpRequest.RequestDetails, masked : StaticHttpRequest.RequestDetails })
performStaticHttpRequests allRawResponses secrets staticRequests =
staticRequests
|> List.map
@ -521,8 +540,12 @@ performStaticHttpRequests allRawResponses secrets staticRequests =
-- |> Set.toList
|> List.map
(\urlBuilder ->
urlBuilder secrets
|> Result.mapError MissingSecret
Secrets2.lookup secrets urlBuilder
|> Result.mapError MissingSecrets
|> Result.map
(\unmasked ->
{ unmasked = unmasked, masked = unmasked }
)
)
|> combineMultipleErrors
@ -596,24 +619,15 @@ staticResponsesUpdate newEntry model =
NotFetched request rawResponses ->
let
realUrls =
-- TODO @@@@@@@ this needs to be hashed
StaticHttpRequest.resolveUrls request
(updatedAllResponses |> dictCompact)
|> Tuple.second
|> List.map
(\urlBuilder ->
Pages.Internal.Secrets.useFakeSecrets3
urlBuilder
|> hashUrl
)
|> List.map Secrets2.maskedLookup
|> List.map hashUrl
includesUrl =
-- TODO hash
List.member
(hashUrl newEntry.request
|> Debug.log "check member"
)
(realUrls |> Debug.log "real urls")
List.member (hashUrl newEntry.request)
realUrls
in
if includesUrl then
let
@ -635,7 +649,7 @@ staticResponsesUpdate newEntry model =
return
sendStaticResponsesIfDone : Secrets -> Dict String (Maybe String) -> List Error -> StaticResponses -> Manifest.Config pathKey -> Effect pathKey
sendStaticResponsesIfDone : SecretsDict -> Dict String (Maybe String) -> List Error -> StaticResponses -> Manifest.Config pathKey -> Effect pathKey
sendStaticResponsesIfDone secrets allRawResponses errors staticResponses manifest =
let
pendingRequests =
@ -678,7 +692,12 @@ sendStaticResponsesIfDone secrets allRawResponses errors staticResponses manifes
(rawResponses |> Dict.map (\key value -> value |> Result.withDefault ""))
fetchedAllKnownUrls =
(knownUrlsToFetch |> List.map Pages.Internal.Secrets.useFakeSecrets |> Set.fromList |> Set.size)
(knownUrlsToFetch
|> List.map Secrets2.maskedLookup
|> List.map hashUrl
|> Set.fromList
|> Set.size
)
== (rawResponses |> Dict.keys |> List.length)
in
if hasPermanentHttpError || hasPermanentError || (allUrlsKnown && fetchedAllKnownUrls) then
@ -735,9 +754,15 @@ sendStaticResponsesIfDone secrets allRawResponses errors staticResponses manifes
of
Ok urlsToPerform ->
let
maskedToUnmasked : Dict String { masked : RequestDetails, unmasked : RequestDetails }
maskedToUnmasked =
urlsToPerform
|> List.map (\secureUrl -> ( Pages.Internal.Secrets.masked secureUrl, secureUrl ))
-- |> List.map (\secureUrl -> ( Pages.Internal.Secrets.masked secureUrl, secureUrl ))
|> List.map
(\secureUrl ->
-- ( hashUrl secureUrl, { unmasked = secureUrl, masked = secureUrl } )
( hashUrl secureUrl.masked, secureUrl )
)
|> Dict.fromList
alreadyPerformed =
@ -787,9 +812,10 @@ errorsToString errors =
errorToString : Error -> String
errorToString error =
case error of
MissingSecret buildError ->
banner "Missing Secret" ++ buildError.message |> Terminal.toString
MissingSecrets buildErrors ->
""
-- banner "Missing Secret" -- ++ buildError.message |> Terminal.toString
MetadataDecodeError buildError ->
banner "Metadata Decode Error" ++ buildError.message |> Terminal.toString

View File

@ -4,11 +4,12 @@ import BuildError exposing (BuildError)
import Dict exposing (Dict)
import Pages.Internal.Secrets exposing (UrlWithSecrets)
import Secrets exposing (Secrets)
import Secrets2
import TerminalText as Terminal
type Request value
= Request ( List UrlWithSecrets, Dict String String -> Result Error ( Dict String String, Request value ) )
= Request ( List (Secrets2.Value { url : String, method : String }), Dict String String -> Result Error ( Dict String String, Request value ) )
| Done value
@ -42,7 +43,11 @@ type Error
| DecoderError String
urls : Request value -> List UrlWithSecrets
type alias RequestDetails =
{ url : String, method : String }
urls : Request value -> List (Secrets2.Value RequestDetails)
urls request =
case request of
Request ( urlList, lookupFn ) ->
@ -97,7 +102,7 @@ resolve request rawResponses =
Ok value
resolveUrls : Request value -> Dict String String -> ( Bool, List Pages.Internal.Secrets.UrlWithSecrets )
resolveUrls : Request value -> Dict String String -> ( Bool, List (Secrets2.Value RequestDetails) )
resolveUrls request rawResponses =
case request of
Request ( urlList, lookupFn ) ->

View File

@ -1,11 +1,36 @@
module Secrets2 exposing (Value, map, succeed, with)
module Secrets2 exposing (Value, append, lookup, map, maskedLookup, succeed, with)
import BuildError exposing (BuildError)
import Dict exposing (Dict)
import Json.Decode.Exploration as Decode
import SecretsDict exposing (SecretsDict)
type Value value
= Value (Dict String String -> Result (List String) value)
= Value (SecretsDict -> Result (List String) value)
lookup : SecretsDict -> Value a -> Result (List BuildError) a
lookup secrets (Value lookupSecrets) =
lookupSecrets secrets
-- TODO
|> Result.mapError (\_ -> [])
maskedLookup : Value value -> value
maskedLookup (Value lookupSecrets) =
case lookupSecrets SecretsDict.masked of
Ok value ->
value
Err error ->
-- crash
maskedLookup (Value lookupSecrets)
type SecretsLookup
= Masked
| Unmasked (Dict String String)
succeed : value -> Value value
@ -13,6 +38,34 @@ succeed value =
Value (\_ -> Ok value)
append : Value (List value) -> Value (List value) -> Value (List value)
append (Value lookupSecrets1) (Value lookupSecrets2) =
Value
(\secrets ->
let
secrets1 : Result (List String) (List value)
secrets1 =
lookupSecrets1 secrets
secrets2 : Result (List String) (List value)
secrets2 =
lookupSecrets2 secrets
in
case ( secrets1, secrets2 ) of
( Ok value1, Ok value2 ) ->
Ok (value1 ++ value2)
( Ok value1, Err errors2 ) ->
Err errors2
( Err errors1, Ok value2 ) ->
Err errors1
( Err errors1, Err errors2 ) ->
Err (errors1 ++ errors2)
)
map : (valueA -> valueB) -> Value valueA -> Value valueB
map mapFunction (Value lookupSecrets) =
Value
@ -28,7 +81,7 @@ with newSecret (Value lookupSecrets) =
\secrets ->
case lookupSecrets secrets of
Ok value ->
case Dict.get newSecret secrets of
case SecretsDict.get newSecret secrets of
Just newValue ->
value newValue |> Ok
@ -36,7 +89,7 @@ with newSecret (Value lookupSecrets) =
Err [ newSecret ]
Err error ->
case Dict.get newSecret secrets of
case SecretsDict.get newSecret secrets of
Just newValue ->
Err error

35
src/SecretsDict.elm Normal file
View File

@ -0,0 +1,35 @@
module SecretsDict exposing (SecretsDict, decoder, get, masked, unmasked)
import Dict exposing (Dict)
import Json.Decode as Decode exposing (Decoder)
decoder : Decoder SecretsDict
decoder =
Decode.dict Decode.string
|> Decode.map Unmasked
unmasked : Dict String String -> SecretsDict
unmasked dict =
Unmasked dict
masked : SecretsDict
masked =
Masked
get : String -> SecretsDict -> Maybe String
get secretName secretsDict =
case Masked of
Masked ->
Just secretName
Unmasked dict ->
dict |> Dict.get secretName
type SecretsDict
= Masked
| Unmasked (Dict String String)

View File

@ -23,13 +23,11 @@ module StaticHttp exposing
import BuildError exposing (BuildError)
import Dict exposing (Dict)
import Dict.Extra
import Head
import Html exposing (Html)
import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Exploration
import Pages.Internal.Secrets
import Pages.StaticHttpRequest exposing (Request(..))
import Secrets exposing (Secrets)
import Secrets2
{-| TODO
@ -176,7 +174,7 @@ lookup requestInfo rawResponses =
Ok ( rawResponses, value )
addUrls : List Pages.Internal.Secrets.UrlWithSecrets -> Pages.StaticHttpRequest.Request value -> Pages.StaticHttpRequest.Request value
addUrls : List (Secrets2.Value { url : String, method : String }) -> Pages.StaticHttpRequest.Request value -> Pages.StaticHttpRequest.Request value
addUrls urlsToAdd requestInfo =
case requestInfo of
Request ( initialUrls, function ) ->
@ -190,7 +188,7 @@ addUrls urlsToAdd requestInfo =
-- Request ( urlsToAdd, \_ -> value |> Done |> Ok )
lookupUrls : Pages.StaticHttpRequest.Request value -> List Pages.Internal.Secrets.UrlWithSecrets
lookupUrls : Pages.StaticHttpRequest.Request value -> List (Secrets2.Value { url : String, method : String })
lookupUrls requestInfo =
case requestInfo of
Request ( urls, lookupFn ) ->
@ -234,13 +232,15 @@ succeed value =
{-| TODO
-}
getWithSecrets : (Secrets -> Result BuildError String) -> Decoder a -> Request a
getWithSecrets :
Secrets2.Value String
-> Decoder a
-> Request a
getWithSecrets url decoder =
jsonRequestWithSecrets
(\secrets ->
url secrets
|> Result.map
(\okUrl -> { url = okUrl, method = "GET" })
(url
|> Secrets2.map
(\okUrl -> { url = okUrl, method = "GET" })
)
decoder
@ -259,7 +259,7 @@ get url decoder =
jsonRequest : { url : String, method : String } -> Decoder a -> Request a
jsonRequest url decoder =
Request
( [ Pages.Internal.Secrets.urlWithoutSecrets url ]
( [ Secrets2.succeed url ]
, \rawResponseDict ->
rawResponseDict
|> Dict.get (url |> Pages.Internal.Secrets.hashRequest)
@ -308,7 +308,7 @@ reducedPost url decoder =
-}
reducedJsonRequest : { url : String, method : String } -> Json.Decode.Exploration.Decoder a -> Request a
reducedJsonRequest requestInfo decoder =
request (\secrets -> Ok requestInfo) decoder
request (Secrets2.succeed requestInfo) decoder
type Expect a
@ -322,26 +322,22 @@ type Expect a
{-| TODO
-}
request :
(Secrets
->
Result BuildError
{ method : String
Secrets2.Value
{ method : String
-- , headers : List Header
, url : String
-- , headers : List Header
, url : String
-- , body : Body
}
)
-- , body : Body
}
-> Json.Decode.Exploration.Decoder a
-> Request a
request urlWithSecrets decoder =
Request
( [ Pages.Internal.Secrets.stringToUrl urlWithSecrets
]
( [ urlWithSecrets ]
, \rawResponseDict ->
rawResponseDict
|> Dict.get (Pages.Internal.Secrets.useFakeSecrets2 urlWithSecrets |> Pages.Internal.Secrets.hashRequest)
|> Dict.get (Secrets2.maskedLookup urlWithSecrets |> Pages.Internal.Secrets.hashRequest)
|> (\maybeResponse ->
case maybeResponse of
Just rawResponse ->
@ -352,7 +348,7 @@ request urlWithSecrets decoder =
)
Nothing ->
Pages.Internal.Secrets.useFakeSecrets2 urlWithSecrets
Secrets2.maskedLookup urlWithSecrets
|> Pages.Internal.Secrets.requestToString
|> Pages.StaticHttpRequest.MissingHttpResponse
|> Err
@ -388,7 +384,7 @@ request urlWithSecrets decoder =
(\finalRequest ->
( strippedResponses
|> Dict.insert
(Pages.Internal.Secrets.useFakeSecrets2 urlWithSecrets |> Pages.Internal.Secrets.hashRequest)
(Secrets2.maskedLookup urlWithSecrets |> Pages.Internal.Secrets.hashRequest)
reduced
, finalRequest
)
@ -399,14 +395,23 @@ request urlWithSecrets decoder =
{-| TODO
-}
jsonRequestWithSecrets : (Secrets -> Result BuildError { url : String, method : String }) -> Decoder a -> Request a
jsonRequestWithSecrets :
Secrets2.Value
{ method : String
-- , headers : List Header
, url : String
-- , body : Body
}
-> Decoder a
-> Request a
jsonRequestWithSecrets urlWithSecrets decoder =
Request
( [ Pages.Internal.Secrets.stringToUrl urlWithSecrets
]
( [ urlWithSecrets ]
, \rawResponseDict ->
rawResponseDict
|> Dict.get (Pages.Internal.Secrets.useFakeSecrets2 urlWithSecrets |> Pages.Internal.Secrets.hashRequest)
|> Dict.get (Secrets2.maskedLookup urlWithSecrets |> Pages.Internal.Secrets.hashRequest)
|> (\maybeResponse ->
case maybeResponse of
Just rawResponse ->
@ -415,7 +420,7 @@ jsonRequestWithSecrets urlWithSecrets decoder =
Nothing ->
-- Err <| "Couldn't find response for url `" ++ Pages.Internal.Secrets.useFakeSecrets urlWithSecrets ++ "`"
Pages.Internal.Secrets.useFakeSecrets2 urlWithSecrets
Secrets2.maskedLookup urlWithSecrets
|> Pages.Internal.Secrets.requestToString
|> Pages.StaticHttpRequest.MissingHttpResponse
|> Err

View File

@ -16,6 +16,7 @@ import Pages.PagePath as PagePath
import ProgramTest exposing (ProgramTest)
import Regex
import Secrets exposing (Secrets)
import Secrets2
import SimulatedEffect.Cmd
import SimulatedEffect.Http as Http
import SimulatedEffect.Ports
@ -367,25 +368,21 @@ The user should get this message from the CLI."""
start
[ ( [ "elm-pages" ]
, StaticHttp.getWithSecrets
(\secrets ->
secrets
|> Secrets.get "API_KEY"
|> Result.map
(\apiKey ->
"https://api.github.com/repos/dillonkearns/elm-pages?apiKey=" ++ apiKey
)
(Secrets2.succeed
(\apiKey ->
"https://api.github.com/repos/dillonkearns/elm-pages?apiKey=" ++ apiKey
)
|> Secrets2.with "API_KEY"
)
Decode.string
|> StaticHttp.andThen
(\url ->
StaticHttp.getWithSecrets
(\secrets ->
secrets
|> Secrets.get "MISSING"
|> Result.map
(\missingSecret ->
url ++ "?apiKey=" ++ missingSecret
)
(Secrets2.succeed
(\missingSecret ->
url ++ "?apiKey=" ++ missingSecret
)
|> Secrets2.with "MISSING"
)
(Decode.succeed ())
)
@ -442,13 +439,11 @@ So maybe MISSING should be API_KEY"""
start
[ ( []
, StaticHttp.getWithSecrets
(\secrets ->
secrets
|> Secrets.get "API_KEY"
|> Result.map
(\apiKey ->
"https://api.github.com/repos/dillonkearns/elm-pages?apiKey=" ++ apiKey
)
(Secrets2.succeed
(\apiKey ->
"https://api.github.com/repos/dillonkearns/elm-pages?apiKey=" ++ apiKey
)
|> Secrets2.with "API_KEY"
)
(Decode.succeed ())
)
@ -570,11 +565,7 @@ simulateEffects effect =
|> List.map simulateEffects
|> SimulatedEffect.Cmd.batch
FetchHttp secureUrl ->
let
{ masked, unmasked } =
Pages.Internal.Secrets.unwrap secureUrl
in
FetchHttp { unmasked, masked } ->
Http.request
{ method = unmasked.method
, url = unmasked.url
@ -584,7 +575,7 @@ simulateEffects effect =
Http.expectString
(\response ->
GotStaticHttpResponse
{ request = { url = masked, method = unmasked.method }
{ request = masked
, response = response
}
)

View File

@ -5,6 +5,7 @@ import Expect
import Json.Decode as Decode
import Pages.Internal.Secrets
import Pages.StaticHttpRequest as StaticHttpRequest
import Secrets2
import StaticHttp
import Test exposing (Test, describe, only, test)
@ -27,8 +28,8 @@ all =
, ( "[GET]NEXT", "null" )
]
)
|> Tuple.mapSecond (List.map Pages.Internal.Secrets.useFakeSecrets)
|> Expect.equal ( True, [ "first", "NEXT" ] )
|> Tuple.mapSecond (List.map Secrets2.maskedLookup)
|> Expect.equal ( True, [ get "first", get "NEXT" ] )
)
, test "andThen staring with done" <|
\() ->
@ -43,8 +44,8 @@ all =
[ ( "[GET]NEXT", "null" )
]
)
|> Tuple.mapSecond (List.map Pages.Internal.Secrets.useFakeSecrets)
|> Expect.equal ( True, [ "NEXT" ] )
|> Tuple.mapSecond (List.map Secrets2.maskedLookup)
|> Expect.equal ( True, [ get "NEXT" ] )
)
, test "map" <|
\() ->
@ -62,8 +63,8 @@ all =
, ( "[GET]NEXT", "null" )
]
)
|> Tuple.mapSecond (List.map Pages.Internal.Secrets.useFakeSecrets)
|> Expect.equal ( True, [ "first", "NEXT" ] )
|> Tuple.mapSecond (List.map Secrets2.maskedLookup)
|> Expect.equal ( True, [ get "first", get "NEXT" ] )
)
, test "andThen chain with 1 response available and 1 pending" <|
\() ->
@ -78,8 +79,8 @@ all =
[ ( "[GET]first", "null" )
]
)
|> Tuple.mapSecond (List.map Pages.Internal.Secrets.useFakeSecrets)
|> Expect.equal ( False, [ "first", "NEXT" ] )
|> Tuple.mapSecond (List.map Secrets2.maskedLookup)
|> Expect.equal ( False, [ get "first", get "NEXT" ] )
)
, test "andThen chain with 1 response available and 2 pending" <|
\() ->
@ -96,7 +97,11 @@ all =
|> (\request ->
StaticHttpRequest.resolveUrls request
(Dict.fromList [ ( "[GET]first", "1" ) ])
|> Tuple.mapSecond (List.map Pages.Internal.Secrets.useFakeSecrets)
|> Expect.equal ( False, [ "first", "NEXT" ] )
|> Tuple.mapSecond (List.map Secrets2.maskedLookup)
|> Expect.equal ( False, [ get "first", get "NEXT" ] )
)
]
get url =
{ url = url, method = "GET" }