Skip to content

Commit

Permalink
Start fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amitaibu committed Oct 6, 2024
1 parent 73c2074 commit 6702d3e
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions Test/FileStorage/ControllerFunctionsSpec.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ImplicitParams #-}

module Test.FileStorage.ControllerFunctionsSpec (spec) where
module Test.FileStorage.ControllerFunctionsSpec where

import Test.Hspec
import IHP.Prelude
Expand All @@ -15,11 +12,12 @@ import qualified Data.ByteString.Lazy as LBS
import qualified Data.Text as Text
import Data.Default (def)
import Data.Time.Clock (getCurrentTime, addUTCTime)
import IHP.Controller.RequestContext (RequestContext (..))
import Network.Wai (defaultRequest)
import Network.Wai.Parse (FileInfo(..))

spec :: Spec
spec = describe "IHP.FileStorage.ControllerFunctions" $ do
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
Expand All @@ -28,26 +26,25 @@ spec = describe "IHP.FileStorage.ControllerFunctions" $ do

let fileInfo = FileInfo
{ fileName = "test.txt"
, contentType = "text/plain"
, fileContentType = "text/plain"
, fileContent = "Hello, world!"
}
let options = def { objectName = Just "test.txt" }

result <- storeFileWithOptions fileInfo options
result <- storeFile fileInfo "Test.FileStorage.ControllerFunctionsSpec"

result `shouldBe` "static/test.txt"
result.url `shouldBe` "Test.FileStorage.ControllerFunctionsSpec/test.txt"

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

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

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

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

0 comments on commit 6702d3e

Please sign in to comment.