/
ScraperSpec.hs
224 lines (211 loc) · 9.01 KB
/
ScraperSpec.hs
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
module SBIsecCoJp.ScraperSpec (spec) where
import qualified Control.Monad as M
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.IO as TL
import Test.Hspec
import qualified BrokerBackend as BB
import ModelDef (TickerSymbol (..))
import qualified SBIsecCoJp.Scraper as S
import qualified ScraperBackend as SB
--
-- マーケット情報ページ
--
test01MarketPage = "01k.sbisec.co.jp_bsite_market_indexDetail.do.utf8.html"
test01MarketPage' = Just S.MarketInfoPage
{ S.miCaption = "国内指標"
, S.miPrice = Just 23631.88
, S.miMonth = 1
, S.miDay = 26
, S.miHour = 15
, S.miMinute = 15
, S.miDifference = Just (-37.61)
, S.miDiffPercent = Just (-0.16)
, S.miOpen = Just 23757.34
, S.miHigh = Just 23797.96
, S.miLow = Just 23592.28
}
--
-- ログインページ
--
test01LoginPage = "01k.sbisec.co.jp_bsite_visitor_top.do.utf8.html"
test01LoginPage' = SB.FormTag
{ SB.formAction = "https://k.sbisec.co.jp/bsite/visitor/loginUserCheck.do"
, SB.formMethod = Just "POST"
, SB.formInputTag =
[ SB.InputTag (Just "text") (Just "username") (Just "")
, SB.InputTag (Just "password") (Just "password") (Just "")
, SB.InputTag (Just "submit") (Just "login") (Just " ログイン ")
, SB.InputTag (Just "button") (Just "cancel") (Just "キャンセル")
]
}
--
-- トップページ
--
test01TopPage = "01k.sbisec.co.jp_bsite_member_menu.do.utf8.html"
test01TopPage' = S.TopPage
[ ("ログアウト","/bsite/member/logout.do")
, ("取引/株価照会","/bsite/price/search.do")
, ("注文照会","/bsite/member/stock/orderList.do")
, ("注文取消/訂正","/bsite/member/stock/orderList.do?cayen.comboOff=1")
, ("口座管理","/bsite/member/acc/menu.do")
, ("保有証券一覧","/bsite/member/acc/holdStockList.do")
, ("買付余力","/bsite/member/acc/purchaseMarginList.do")
, ("信用建玉一覧","/bsite/member/acc/positionList.do")
, ("信用建余力","/bsite/member/acc/positionMargin.do")
, ("出金/振替指示","/bsite/member/banking/withdrawMenu.do")
, ("ATMカード","/bsite/member/acc/atmwithdrawMax.do")
, ("重要なお知らせ","javascript:openJmsg('/bsite/member/jmsg/JMsgRedirect.do?categoryId=03')")
, ("当社からのお知らせ","javascript:openETrade('/bsite/member/jmsg/JMsgRedirect.do?categoryId=02')")
, ("登録銘柄","/bsite/member/portfolio/registeredStockList.do")
, ("銘柄登録","/bsite/member/portfolio/stockSearch.do")
, ("銘柄一括登録/編集","/bsite/member/portfolio/lumpStockEntry.do")
, ("銘柄削除","/bsite/member/portfolio/registeredStockDelete.do")
, ("リスト作成/変更","/bsite/member/portfolio/listEdit.do")
, ("マーケット情報","/bsite/market/menu.do")
, ("ランキング","/bsite/market/rankingListM.do")
, ("海外指標","/bsite/market/foreignIndexDetail.do")
, ("外国為替","/bsite/market/forexDetail.do")
, ("市況コメント","/bsite/market/marketInfoList.do")
, ("ニュース","/bsite/market/newsList.do")
, ("取引パスワード/注文確認省略設定","/bsite/member/setting/omissionSetting.do")
, ("手数料","/bsite/info/productGroupList.do?service_info_id=commission")
, ("取扱商品","/bsite/info/productGroupList.do?service_info_id=goodsList")
, ("新着情報/キャンペーン","/bsite/info/campaignInfoList.do")
, ("お問い合わせ","/bsite/info/inquiryList.do")
, ("ログイン履歴","/bsite/member/loginHistory.do")
, ("!ポリシー/免責事項","/bsite/info/policyList.do")
, ("システムメンテナンス","/bsite/info/systemInfoDetail.do?sortation_id=maintenance")
, ("ログアウト","/bsite/member/logout.do")
, ("金融商品取引法に係る表示","/bsite/info/policyDetail.do?list=title&policy_info_id=salesLaw&text_no=1")
]
--
-- 口座管理ページ
--
test01AccMenuPage = "01k.sbisec.co.jp_bsite_member_acc_menu.do.utf8.html"
test01AccMenuPage' = S.AccMenuPage
[ ("トップ","/bsite/member/menu.do")
, ("ログアウト","/bsite/member/logout.do")
, ("取引/株価照会","/bsite/price/search.do")
, ("登録銘柄","/bsite/member/portfolio/registeredStockList.do")
, ("口座管理","/bsite/member/acc/menu.do")
, ("マーケット情報","/bsite/market/menu.do")
, ("保有証券一覧","/bsite/member/acc/holdStockList.do")
, ("買付余力","/bsite/member/acc/purchaseMarginList.do")
, ("信用建玉一覧","/bsite/member/acc/positionList.do")
, ("信用建余力","/bsite/member/acc/positionMargin.do")
, ("出金/振替指示","/bsite/member/banking/withdrawMenu.do")
, ("ATMカード","/bsite/member/acc/atmMenu.do")
, ("トップ","/bsite/member/menu.do")
, ("ログアウト","/bsite/member/logout.do")
, ("金融商品取引法に係る表示","/bsite/info/policyDetail.do?list=title&policy_info_id=salesLaw&text_no=1")
]
--
-- 買付余力ページ
--
test01AccPurchaseMarginListPage = "01k.sbisec.co.jp_bsite_member_acc_purchaseMarginList.do.utf8.html"
test01AccPurchaseMarginListPage' = S.PurchaseMarginListPage
[ ("詳細","/bsite/member/acc/purchaseMarginDetail.do?no=3&account_type=1")
, ("詳細","/bsite/member/acc/purchaseMarginDetail.do?no=4&account_type=1")
]
--
-- 買付余力詳細ページ
--
test01AccPurchaseMarginDetailPage = "01k.sbisec.co.jp_bsite_member_acc_purchaseMarginDetail.do.utf8.html"
test01AccPurchaseMarginDetailPage' = Just S.PurchaseMarginDetailPage
{ pmdUserid = "Z12-1234567"
, pmdDay = "2018/01/26"
, pmdMoneyToSpare = 123456
, pmdCashBalance = 321654
}
--
-- 保有証券一覧ページ
--
test01AccHoldStockListPage = "01k.sbisec.co.jp_bsite_member_acc_holdStockList.do.utf8.html"
test01AccHoldStockListPage' = Just S.HoldStockListPage
{ S.hslUserid = "Z12-1234567"
, S.hslNthPages = "1~2件(2件中)"
, S.hslEvaluation = 123456.0
, S.hslProfit = 1500.0
, S.hslLinks = S.HoldStockDetailLink
[ ("ヨロシサン製薬","/bsite/member/acc/holdStockDetail.do?company_code=1111&new_old_id=+&hitokutei_kbn=0&st_right_id=+&")
, ("オムラ・インダストリ","/bsite/member/acc/holdStockDetail.do?company_code=2222&new_old_id=+&hitokutei_kbn=0&st_right_id=+&")
]
}
--
-- 保有証券詳細ページ
--
test01AccHoldStockDetailPage = "01k.sbisec.co.jp_bsite_member_acc_holdStockDetail.do.utf8.html"
test01AccHoldStockDetailPage' = Just S.HoldStockDetailPage
{ S.hsdUserid = "Z12-1234567"
, hsdTicker = TSTYO 1111
, hsdCaption = "ヨロシサン製薬"
, hsdDiff = -1
, hsdCount = 100
, hsdPurchasePrice = 100
, hsdPrice = 120
}
test02AccHoldStockDetailPage = "02k.sbisec.co.jp_bsite_member_acc_holdStockDetail.do.utf8.html"
test02AccHoldStockDetailPage' = Just S.HoldStockDetailPage
{ S.hsdUserid = "Z12-1234567"
, hsdTicker = TSTYO 2222
, hsdCaption = "オムラ・インダストリ"
, hsdDiff = 100
, hsdCount = 100
, hsdPurchasePrice = 1000
, hsdPrice = 1035
}
--
-- Hspecテスト
--
spec :: Spec
spec = do
--
describe "market information page" $
it "test 01" $ do
html <- TL.readFile ("test/SBIsecCoJp/" ++ test01MarketPage)
S.marketInfoPage html `shouldBe` test01MarketPage'
--
describe "formLogin page" $
it "test 01" $ do
html <- TL.readFile ("test/SBIsecCoJp/" ++ test01LoginPage)
case S.formLoginPage html of
Left l -> TL.putStrLn l
Right r -> r `shouldBe` test01LoginPage'
--
describe "top page" $
it "test 01" $ do
html <- TL.readFile ("test/SBIsecCoJp/" ++ test01TopPage)
S.topPage html `shouldBe` test01TopPage'
--
describe "acc/menu page" $
it "test 01" $ do
html <- TL.readFile ("test/SBIsecCoJp/" ++ test01AccMenuPage)
S.accMenuPage html `shouldBe` test01AccMenuPage'
--
describe "acc/purchaseMarginList page" $
it "test 01" $ do
html <- TL.readFile ("test/SBIsecCoJp/" ++ test01AccPurchaseMarginListPage)
S.purchaseMarginListPage html `shouldBe` test01AccPurchaseMarginListPage'
--
describe "acc/purchaseMarginDetail page" $
it "test 01" $ do
html <- TL.readFile ("test/SBIsecCoJp/" ++ test01AccPurchaseMarginDetailPage)
S.purchaseMarginDetailPage html `shouldBe` test01AccPurchaseMarginDetailPage'
--
describe "acc/holdStockList page" $
it "test 01" $ do
html <- TL.readFile ("test/SBIsecCoJp/" ++ test01AccHoldStockListPage)
S.holdStockListPage html `shouldBe` test01AccHoldStockListPage'
--
describe "acc/holdStockDetail page" $ do
it "test 01" $ do
html <- TL.readFile ("test/SBIsecCoJp/" ++ test01AccHoldStockDetailPage)
S.holdStockDetailPage html `shouldBe` test01AccHoldStockDetailPage'
it "test 02" $ do
html <- TL.readFile ("test/SBIsecCoJp/" ++ test02AccHoldStockDetailPage)
S.holdStockDetailPage html `shouldBe` test02AccHoldStockDetailPage'
-- print $ S.holdStockDetailPage html
-- M.mapM_ (TL.putStrLn . TL.fromStrict {-. T.unwords-}) $ S.holdStockDetailPage html