Skip to content

Commit

Permalink
Copy from another test
Browse files Browse the repository at this point in the history
  • Loading branch information
amitaibu committed Oct 6, 2024
1 parent 2aa73c0 commit ac3f57f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Test/FileStorage/ControllerFunctionsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import qualified Data.ByteString.Lazy as LBS
import qualified Data.Text as Text
import Data.Default (def)
import Data.Time.Clock (getCurrentTime, addUTCTime)
import Network.Wai (defaultRequest)
import Network.Wai as Wai (defaultRequest)
import Network.Wai.Parse (FileInfo(..))
import IHP.Controller.RequestContext

tests :: Spec
tests = describe "IHP.FileStorage.ControllerFunctions" $ do
let ?requestContext = undefined
describe "storeFileWithOptions" $ do
it "returns the objectPath without the baseUrl" $ do
withSystemTempDirectory "ihp-test" $ \tempDir -> do
context <- newControllerContext
context <- createControllerContext
let ?context = context

let fileInfo = FileInfo
Expand All @@ -36,17 +36,25 @@ tests = describe "IHP.FileStorage.ControllerFunctions" $ do

describe "createTemporaryDownloadUrlFromPathWithExpiredAt" $ do
it "returns baseUrl concatenated with objectPath when objectPath does not start with http:// or https://" $ do
context <- newControllerContext
context <- createControllerContext
let ?context = context
let objectPath = "static/test.txt"
temporaryDownloadUrl <- createTemporaryDownloadUrlFromPath objectPath

temporaryDownloadUrl.url `shouldBe` "http://localhost:8000/static/test.txt"

it "returns '/' concatenated with objectPath when objectPath starts with 'http://' or 'https://'" $ do
context <- newControllerContext
context <- createControllerContext
let ?context = context
let objectPath = "https://example.com/static/test.txt"
temporaryDownloadUrl <- createTemporaryDownloadUrlFromPath objectPath

temporaryDownloadUrl.url `shouldBe` "https://example.com/static/test.txt"

createControllerContext = do
let
requestBody = FormBody { params = [], files = [] }
request = Wai.defaultRequest
requestContext = RequestContext { request, respond = error "respond", requestBody, frameworkConfig = error "frameworkConfig" }
let ?requestContext = requestContext
newControllerContext

0 comments on commit ac3f57f

Please sign in to comment.