tooty/tests/MastodonTest/HttpTest.elm
Nicolas Perriault 2b74533960 Fix #64: Handle paginations. (#131)
* Extract link header values.
* Expose response link header to a new type.
* Add tests for Mastodon.http.extractLinks.
* WiP
* Wrap decoded content and links into a new Response type.
* Update MastodonMsg handlers so they handle responses.
* Remove debug statements.
* Add edge case to tests.
* Add missing TODO comment.
* Simplifies Mastodon.Http signatures
* Paginate the user timeline.
* I lost my mind. May revert.
* Updated Http API to be more explicit.
* Fuck namespaces.
* Cosmetics.
* I'm burnt out, lost 10 pounds, but it works.
* Fix qs param for local tl was appended to link url.
* Fix my own mediocrity.
* Fix oauth endpoints.
* Fix Link header case handling with Firefox.
* Add test case for link header name case handling.
2017-05-05 17:26:49 +02:00

63 lines
2.6 KiB
Elm

module MastodonTest.HttpTest exposing (..)
import Dict
import Test exposing (..)
import Expect
import Mastodon.Http exposing (..)
all : Test
all =
describe "Mastodon.Http"
[ describe "extractLinks"
[ test "should handle absence of link header" <|
\() ->
extractLinks (Dict.fromList [])
|> Expect.equal { prev = Nothing, next = Nothing }
, test "should parse a link header" <|
\() ->
let
headers =
Dict.fromList
[ ( "link", "<nextLinkUrl>; rel=\"next\", <prevLinkUrl>; rel=\"prev\"" )
]
in
extractLinks headers
|> Expect.equal { prev = Just "prevLinkUrl", next = Just "nextLinkUrl" }
, test "should handle link header name case appropriately" <|
\() ->
let
headers =
Dict.fromList
[ ( "Link", "<nextLinkUrl>; rel=\"next\", <prevLinkUrl>; rel=\"prev\"" )
]
in
extractLinks headers
|> Expect.equal { prev = Just "prevLinkUrl", next = Just "nextLinkUrl" }
, test "should extract a single prev link" <|
\() ->
let
headers =
Dict.fromList [ ( "link", "<prevLinkUrl>; rel=\"prev\"" ) ]
in
extractLinks headers
|> Expect.equal { prev = Just "prevLinkUrl", next = Nothing }
, test "should extract a single next link" <|
\() ->
let
headers =
Dict.fromList [ ( "link", "<nextLinkUrl>; rel=\"next\"" ) ]
in
extractLinks headers
|> Expect.equal { prev = Nothing, next = Just "nextLinkUrl" }
, test "should only extract prev and next links" <|
\() ->
let
headers =
Dict.fromList [ ( "link", "<nextLinkUrl>; rel=\"next\", <blurp>; rel=\"blop\"" ) ]
in
extractLinks headers
|> Expect.equal { prev = Nothing, next = Just "nextLinkUrl" }
]
]