aboutsummaryrefslogtreecommitdiff
path: root/src/test/haskell/ParserSpec.hs
blob: 64b2b33e5853f61ddfbc83f6ab7867865e53e2a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
module ParserSpec (spec) where

import           Data.Maybe             (catMaybes)
import qualified Data.Text.IO           as T
import qualified Network.Wreq.Session   as Session
import           Test.Hspec

import qualified Ads
import qualified FetchAd
import           Model.Ad               (Ad (..))
import qualified Parser.LeboncoinParser as LeboncoinParser
-- import qualified Parser.OuestFranceParser as OuestFranceParser
-- import qualified Parser.SeLogerParser     as SeLogerParser

spec :: Spec
spec = do
  describe "Parser" $ do
    session <- runIO Session.newSession
    describe "LeBonCoin" $ do

      it "should parse no results from empty string" $ do
        LeboncoinParser.parse "" `shouldBe` []

      it "should parse ads from local page" $ do
        ads <- T.readFile "src/test/resources/leboncoin.html"
        LeboncoinParser.parse ads `shouldBe` Ads.leboncoin

      it "should parse ads from remote page" $ do
        ads <- FetchAd.leboncoin
          session
          ["https://www.leboncoin.fr/annonces/offres/ile_de_france/"]
        checkAds ads

    -- describe "OuestFrance" $ do
    --
    --   it "should parse no results from empty string" $ do
    --     OuestFranceParser.parse "" `shouldBe` []
    --
    --   it "should parse ads from page" $ do
    --     rawOuestFranceAds <- T.readFile "src/test/resources/ouestFrance.html"
    --     OuestFranceParser.parse rawOuestFranceAds `shouldBe` Ads.ouestFrance
    --
    --   it "should parse ads from remote page" $ do
    --     ads <- FetchAd.ouestFrance ["https://www.ouestfrance-immo.com/louer/appartement/rennes-35-35000/"]
    --     checkAds ads
    --
    -- describe "SeLoger" $ do
    --
    --   it "should parse no results from empty string" $ do
    --     SeLogerParser.parse "" `shouldBe` []
    --
    --   it "should parse ads from page" $ do
    --     ads <- T.readFile "src/test/resources/seLoger.html"
    --     SeLogerParser.parse ads `shouldBe` Ads.seLoger
    --
    --   it "should parse ads from remote page" $ do
    --     ads <- FetchAd.seLoger ["https://www.seloger.com/list.htm?tri=initial&idtypebien=2,1&idtt=2,5&naturebien=1,2,4&ci=690123"]
    --     checkAds ads

checkAds :: [Ad] -> IO ()
checkAds ads = do
  length ads `shouldSatisfy` (\n -> n > 10)
  (length . catMaybes . map price $ ads) `shouldSatisfy` (\n -> n > 10)