blob: a8cfae9abeb6b9ca0ce709e0b185d3da2dd9d63e (
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
|
import Data.Maybe (catMaybes)
import qualified Data.Text.IO as T
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
main :: IO ()
main = do
hspec $ do
describe "LeboncoinParser" $ 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 ["https://www.leboncoin.fr/locations/offres/ile_de_france/?th=1"]
checkAds ads
describe "OuestFranceParser" $ 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 "SeLogerParser" $ 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)
|